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 6 of 6
  1. #1
    Regular Coder
    Join Date
    Jan 2011
    Posts
    136
    Thanks
    101
    Thanked 0 Times in 0 Posts

    Error loading data into Mysql

    I am getting the same below error no matter what I tried.

    Anyone has any clue? Thank you in advance!

    ====
    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 ''dname', 'demail', 'dphone') VALUES('a', 'b' , 'c' at line 1
    ===

    Code:
    	$server="localhost";
    	$user="xxx";
    	$password="xxx";
    	$database="xxx";
    	$table="xxx";
    	$connection=mysql_connect($server, $user,$password) or die ("<h3>Server Unreachable</h3>");
    
    	mysql_select_db($database) or die ("<h3>Database not reachable</h3>");
    
    	mysql_query("SET CHARACTER SET utf8", $connection); 
    
    	$insert2=mysql_query("INSERT INTO $table ('dname', 'demail', 'dphone') VALUES('$a', '$b' , '$c') ") or die(mysql_error());
    
    	MYSQL_CLOSE();
    Last edited by camaross; 03-20-2013 at 02:01 PM.

  • #2
    Regular Coder Arcticwarrio's Avatar
    Join Date
    May 2012
    Location
    UK
    Posts
    709
    Thanks
    20
    Thanked 84 Times in 84 Posts
    dont use quotes, if you need them use backsticks ` not '

    PHP Code:
    $server="localhost";
        
    $user="xxx";
        
    $password="xxx";
        
    $database="xxx";
        
    $table="xxx";
        
    $connection=mysql_connect($server$user,$password) or die ("<h3>Server Unreachable</h3>");

        
    mysql_select_db($database) or die ("<h3>Database not reachable</h3>");

        
    mysql_query("SET CHARACTER SET utf8"$connection); 

        
    $insert2=mysql_query("INSERT INTO $table (`dname`, `demail`, `dphone`) VALUES($a, $b , $c) ") or die(mysql_error());

        
    MYSQL_CLOSE(); 
    There are 10 types of people on CodingForums,
    Those who understand Binary and those who dont.
    Get Cloud Hosting now from only£59 / month

  • Users who have thanked Arcticwarrio for this post:

    camaross (03-20-2013)

  • #3
    Regular Coder
    Join Date
    Jan 2011
    Posts
    136
    Thanks
    101
    Thanked 0 Times in 0 Posts
    Thank you so much! That was the problem.

    Now I am getting a new error:

    Unknown column 'aa' in 'field list'

    'aa' is the value of $a --- the input for dname. I tried to delete anything related to dname for a test, but only get the same error for the next column that I want to input values to. Looks like the problem is the first column it runs across.





    Quote Originally Posted by Arcticwarrio View Post
    dont use quotes, if you need them use backsticks ` not '

    PHP Code:
    $server="localhost";
        
    $user="xxx";
        
    $password="xxx";
        
    $database="xxx";
        
    $table="xxx";
        
    $connection=mysql_connect($server$user,$password) or die ("<h3>Server Unreachable</h3>");

        
    mysql_select_db($database) or die ("<h3>Database not reachable</h3>");

        
    mysql_query("SET CHARACTER SET utf8"$connection); 

        
    $insert2=mysql_query("INSERT INTO $table (`dname`, `demail`, `dphone`) VALUES($a, $b , $c) ") or die(mysql_error());

        
    MYSQL_CLOSE(); 

  • #4
    Regular Coder Arcticwarrio's Avatar
    Join Date
    May 2012
    Location
    UK
    Posts
    709
    Thanks
    20
    Thanked 84 Times in 84 Posts
    how are you setting variables $a $b and $c?
    There are 10 types of people on CodingForums,
    Those who understand Binary and those who dont.
    Get Cloud Hosting now from only£59 / month

  • Users who have thanked Arcticwarrio for this post:

    camaross (03-20-2013)

  • #5
    Regular Coder Arcticwarrio's Avatar
    Join Date
    May 2012
    Location
    UK
    Posts
    709
    Thanks
    20
    Thanked 84 Times in 84 Posts
    my bad looks like you will need quotes for the variables

    PHP Code:

    $server
    ="localhost";
        
    $user="xxx";
        
    $password="xxx";
        
    $database="xxx";
        
    $table="xxx";
        
    $connection=mysql_connect($server$user,$password) or die ("<h3>Server Unreachable</h3>");

        
    mysql_select_db($database) or die ("<h3>Database not reachable</h3>");

        
    mysql_query("SET CHARACTER SET utf8"$connection); 

        
    $insert2=mysql_query("INSERT INTO $table (`dname`, `demail`, `dphone`) VALUES('$a', '$b' , '$c') ") or die(mysql_error());

        
    MYSQL_CLOSE(); 
    There are 10 types of people on CodingForums,
    Those who understand Binary and those who dont.
    Get Cloud Hosting now from only£59 / month

  • Users who have thanked Arcticwarrio for this post:

    camaross (03-20-2013)

  • #6
    Regular Coder
    Join Date
    Jan 2011
    Posts
    136
    Thanks
    101
    Thanked 0 Times in 0 Posts
    It is now working

    Thank you so much for the help! I really appreciate it.




    Quote Originally Posted by Arcticwarrio View Post
    my bad looks like you will need quotes for the variables

    PHP Code:

    $server
    ="localhost";
        
    $user="xxx";
        
    $password="xxx";
        
    $database="xxx";
        
    $table="xxx";
        
    $connection=mysql_connect($server$user,$password) or die ("<h3>Server Unreachable</h3>");

        
    mysql_select_db($database) or die ("<h3>Database not reachable</h3>");

        
    mysql_query("SET CHARACTER SET utf8"$connection); 

        
    $insert2=mysql_query("INSERT INTO $table (`dname`, `demail`, `dphone`) VALUES('$a', '$b' , '$c') ") or die(mysql_error());

        
    MYSQL_CLOSE(); 


  •  

    Posting Permissions

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