Help with mysql and php form variables!

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
narotosensei
Forum Newbie
Posts: 3
Joined: Tue Dec 07, 2010 9:55 pm
Contact:

Help with mysql and php form variables!

Post by narotosensei »

I can't figure this thing out! I'm still kinda new to php. I'm making a family tree website. I'm trying to hand build the CMS but, alas, I'm having trouble. I know there must be something so simple that I'm missing. I have a MYSQL database with 9 different tables. Instead of building 9 different insert record pages, I decided to use a switch statement to determine which table to edit. So the basics of it, I have a page with links and a URL variable. Each link sends a different value to the next page. The new page then determines from the URL variable which form and table to build. I have no problem with this part. Its my processor page. After inputting the data in the form and submitting, I keep getting SQL errors!
Here's a snippet from the processor page.

Code: Select all

<?php require_once('../Connections/conn_gilliam.php'); 
mysql_select_db($database_conn_gilliam, $conn_gilliam);
?>
<?php switch ($_GET['tbl']) {
					case "1";
	$query_rs_insert_gen = "INSERT INTO tbl_gen (dob, desc, dod, fname, img, lname, rootID) VALUES ('".$_POST['dob']."', '".$_POST['desc']."', '".$_POST['dod']."', '".$_POST['fname']."', '".$_POST['img']."', '".$_POST['lname']."', '".$_POST['pk']."');";
	$rs_insert_gen = mysql_query($query_rs_insert_gen) or die(mysql_error());
						break;
THE ERROR I KEEP GETTING "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'desc, dod, fname, img, lname, rootID) VALUES ('', 'asdf' '', '', '', '', 'sdf')' at line 1"

I know that all my values from the form are getting there because I can echo them.
I'm positive all my fields name match up.
What am I missing?
devilinc
Forum Newbie
Posts: 16
Joined: Fri Nov 12, 2010 1:07 am

Re: Help with mysql and php form variables!

Post by devilinc »

CHANGE BELOW LINE:::

Code: Select all

$query_rs_insert_gen = "INSERT INTO tbl_gen (dob, desc, dod, fname, img, lname, rootID) VALUES ('".$_POST['dob']."', '".$_POST['desc']."', '".$_POST['dod']."', '".$_POST['fname']."', '".$_POST['img']."', '".$_POST['lname']."', '".$_POST['pk']."');";
TO:::

Code: Select all

$query_rs_insert_gen = "INSERT INTO tbl_gen (dob, desc, dod, fname, img, lname, rootID) VALUES ('$_POST[dob]', \"$_POST[desc]\", '$_POST[dod], \"$_POST[fname]\", \"$_POST[img]\", \"$_POST[lname]\", \"$_POST[pk]\")";
try to echo this statement also in your php file and execute it in your database....hope this works....its those quotes problem....

P.S. WHY DONT YOU STORE THE FORM FIELDS INTO VARIABLES INSTEAD OF USING THE POST? DONT YOU NEED THEM AGAIN?
narotosensei
Forum Newbie
Posts: 3
Joined: Tue Dec 07, 2010 9:55 pm
Contact:

Re: Help with mysql and php form variables!

Post by narotosensei »

I tried your code out, and I'm still getting the same error... Any more ideas?
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: Help with mysql and php form variables!

Post by AbraCadaver »

narotosensei wrote:I tried your code out, and I'm still getting the same error... Any more ideas?
http://dev.mysql.com/doc/refman/5.1/en/ ... words.html
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
narotosensei
Forum Newbie
Posts: 3
Joined: Tue Dec 07, 2010 9:55 pm
Contact:

Re: Help with mysql and php form variables!

Post by narotosensei »

Eureka! Thanks that post saved me a bunch of trouble :D
Post Reply