...

View Full Version : Variable out a dropdown menu item



SuperMode55
01-17-2012, 12:23 AM
Hello, I'm making a dropdown menu with about 5 choices from these choices I have 5 tables so if the user chooses "choice1" I want to insert data into table "choice1" so I made
a variable out of each option like


$table_choice_1=$_POST['choice1'];
$mysql="INSERT INTO $table_choice_1 (--etc etc)

I get this error every time:
Connection Succesful!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
I know the syntax is ok since i used it before but without trying to make a table variable. I'd appreaciate the help thank you.

Dan13071992
01-17-2012, 01:29 AM
we would need to see your code inorder to debug the problem

BluePanther
01-17-2012, 07:21 AM
Hello, I'm making a dropdown menu with about 5 choices from these choices I have 5 tables so if the user chooses "choice1" I want to insert data into table "choice1" so I made
a variable out of each option like


$table_choice_1=$_POST['choice1'];
$mysql="INSERT INTO $table_choice_1 (--etc etc)

I get this error every time:
Connection Succesful!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
I know the syntax is ok since i used it before but without trying to make a table variable. I'd appreaciate the help thank you.

The most likely cause is that $_POST['choice1'] is empty, or some other value in the query is empty. Echo out the query just before you execute it to make sure it's completely correct.

It should be said, to avoid SQL injection you should always use mysql_real_escape_string(). Without that, your site is wide open to database injection.

karlos81
01-21-2012, 08:51 AM
Try puting the $table_choice_1 into single quotes!

'$table_choice_1'

BluePanther
01-21-2012, 08:04 PM
Try puting the $table_choice_1 into single quotes!

'$table_choice_1'

it would most likely be ` rather than ' I would think, considering you're defining a table name. I could be wrong, though - you might be able to use both.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum