Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-18-2011, 02:49 PM   PM User | #1
DataTalk
Regular Coder

 
Join Date: Nov 2010
Location: Oregon
Posts: 219
Thanks: 19
Thanked 10 Times in 10 Posts
DataTalk is an unknown quantity at this point
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..
DataTalk is offline   Reply With Quote
Old 01-18-2011, 05:32 PM   PM User | #2
DataTalk
Regular Coder

 
Join Date: Nov 2010
Location: Oregon
Posts: 219
Thanks: 19
Thanked 10 Times in 10 Posts
DataTalk is an unknown quantity at this point
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..
DataTalk is offline   Reply With Quote
Old 01-18-2011, 05:36 PM   PM User | #3
Fumigator
UE Antagonizer


 
Fumigator's Avatar
 
Join Date: Dec 2005
Location: Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
Posts: 7,686
Thanks: 42
Thanked 637 Times in 625 Posts
Fumigator is a glorious beacon of lightFumigator is a glorious beacon of lightFumigator is a glorious beacon of lightFumigator is a glorious beacon of lightFumigator is a glorious beacon of light
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.
__________________
Fumigator is offline   Reply With Quote
Old 01-18-2011, 06:11 PM   PM User | #4
DataTalk
Regular Coder

 
Join Date: Nov 2010
Location: Oregon
Posts: 219
Thanks: 19
Thanked 10 Times in 10 Posts
DataTalk is an unknown quantity at this point
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..
DataTalk is offline   Reply With Quote
Old 01-18-2011, 08:18 PM   PM User | #5
DataTalk
Regular Coder

 
Join Date: Nov 2010
Location: Oregon
Posts: 219
Thanks: 19
Thanked 10 Times in 10 Posts
DataTalk is an unknown quantity at this point
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..
DataTalk is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 11:58 PM.


Advertisement
Log in to turn off these ads.