Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder
    Join Date
    Nov 2010
    Location
    Oregon
    Posts
    243
    Thanks
    23
    Thanked 10 Times in 10 Posts

    Stored Procedure INSERT INTO parameters

    I am looking for the proper parameters for INSERT INTO using stored procedure

    Here is the result I am getting from this stored procedure...

    Inserts the $POST[] function Into the employees table:
    $_POST[FirstName]
    $_POST[LastName]


    This should "execute" the $POST[] function and insert the correct data:
    Mike
    Richards


    Question is:
    Why is this inserting the $POST[] function instead of executing it ?...
    I have tried '$_POST[FirstName]' and '" .$_POST['FirstName']. '"
    Does not seem to be the correct parameters when using stored procedure
    Code:
    <?php
    // create new stored procedure
    $insert = "(FirstName, LastName) VALUES ( '\$_POST[FirstName]', '\$_POST[LastName]')";
    
    $sql = ("CREATE PROCEDURE sp_employees() INSERT INTO `employees` $insert ");
      mysql_select_db('$c_database');
        $res = mysql_query( $sql, $connection )
          or die('Could not create sp_employees: ' . mysql_error()); 
    
    header("Location: ./sp_manager.php") ;
    mysql_close($connection);
    }
    ?>
    Code to call the procedure
    Code:
    <?php
    if($_POST['Submit']) { mysql_query("CALL sp_employees ()");
    header("Location: ./employees.php");
    }
    ?>
    Last edited by DataTalk; 01-18-2011 at 05:12 PM.

  • #2
    Regular Coder
    Join Date
    Nov 2010
    Location
    Oregon
    Posts
    243
    Thanks
    23
    Thanked 10 Times in 10 Posts
    I see where @FirstName has been used in place of $_POST[FirstName] for INSERT INTO with stored procedures

    INSERT INTO employees (FirstName, LastName) VALUES (@FirstName, @LastName)

    But this does not post the field <input type='text' name='FirstName'>
    Just inserts a blank record in employees, because of @ instead of $_POST?

    How do I correct this?
    Last edited by DataTalk; 01-18-2011 at 05:40 PM.

  • #3
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    Hmm... It looks like you need to deepen your understanding of how stored procedures work. You need to use IN parameters to pass values to the stored procedure when you call it, as in the example found in this link:

    http://dev.mysql.com/tech-resources/...rocedures.html

    Also in that link is a PDF that gives a good understanding of how to code and use stored procedures.

  • #4
    Regular Coder
    Join Date
    Nov 2010
    Location
    Oregon
    Posts
    243
    Thanks
    23
    Thanked 10 Times in 10 Posts
    I pretty much figured out the logic with using SELECT..and other stufff

    Its the INSERT INTO , and UPDATE that I am trying to master..

    Thanks for posting that pdf.. I lost that link, I have been looking for it..
    Last edited by DataTalk; 01-18-2011 at 06:18 PM.

  • #5
    Regular Coder
    Join Date
    Nov 2010
    Location
    Oregon
    Posts
    243
    Thanks
    23
    Thanked 10 Times in 10 Posts
    The pdf didn't really explain how to pass the value from
    a form field in a page.php

    I will read up some more on this..

    Thanks!
    Last edited by DataTalk; 01-18-2011 at 11:20 PM.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •