Page 1 of 1

Help with mysql and php form variables!

Posted: Tue Dec 07, 2010 10:11 pm
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?

Re: Help with mysql and php form variables!

Posted: Tue Dec 07, 2010 10:57 pm
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?

Re: Help with mysql and php form variables!

Posted: Wed Dec 08, 2010 1:17 pm
by narotosensei
I tried your code out, and I'm still getting the same error... Any more ideas?

Re: Help with mysql and php form variables!

Posted: Wed Dec 08, 2010 2:12 pm
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

Re: Help with mysql and php form variables!

Posted: Wed Dec 08, 2010 2:24 pm
by narotosensei
Eureka! Thanks that post saved me a bunch of trouble :D