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
    New Coder
    Join Date
    Nov 2011
    Location
    Notre Dame, IN
    Posts
    16
    Thanks
    10
    Thanked 0 Times in 0 Posts

    Variable out a dropdown menu item

    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
    Code:
    $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.

  • #2
    Regular Coder
    Join Date
    Dec 2010
    Location
    Kent, UK
    Posts
    573
    Thanks
    23
    Thanked 10 Times in 10 Posts
    we would need to see your code inorder to debug the problem
    http://360-tactics.co.uk/forum/index.php

    Crime-Wave

    please post your code wrapped in tags
    please post your PHP wrapped in tags

  • #3
    Senior Coder
    Join Date
    Jul 2011
    Posts
    1,226
    Thanks
    3
    Thanked 171 Times in 171 Posts
    Quote Originally Posted by SuperMode55 View Post
    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
    Code:
    $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.
    Useful function to retrieve difference in times
    The best PHP resource
    A good PHP FAQ
    PLEASE remember to wrap your code in [PHP] tags.
    PHP Code:
    // Replace this
    if(isset($_POST['submitButton']))
    // With this
    if(!empty($_POST))
    // Then check for values/forms. Some IE versions don't send the submit button 
    Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.

  • Users who have thanked BluePanther for this post:

    SuperMode55 (01-19-2012)

  • #4
    New to the CF scene
    Join Date
    Jan 2012
    Location
    Belgrade, Serbia
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    single quotes

    Try puting the $table_choice_1 into single quotes!
    PHP Code:
    '$table_choice_1' 

  • #5
    Senior Coder
    Join Date
    Jul 2011
    Posts
    1,226
    Thanks
    3
    Thanked 171 Times in 171 Posts
    Quote Originally Posted by karlos81 View Post
    Try puting the $table_choice_1 into single quotes!
    PHP Code:
    '$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.
    Useful function to retrieve difference in times
    The best PHP resource
    A good PHP FAQ
    PLEASE remember to wrap your code in [PHP] tags.
    PHP Code:
    // Replace this
    if(isset($_POST['submitButton']))
    // With this
    if(!empty($_POST))
    // Then check for values/forms. Some IE versions don't send the submit button 
    Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.


  •  

    Posting Permissions

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