Create mysql table with php variable not working

后端 未结 4 1016
生来不讨喜
生来不讨喜 2020-12-07 06:28

I\'m pretty new to php.. and this is probably a stupid mistake... but I have no idea what is going on. I\'m trying to create a table in my database using php. I want to name

4条回答
  •  难免孤独
    2020-12-07 07:01

    Add this after your SQL querys - (It really helps and speeds up error correcting time)

    or die("A MySQL error has occurred.
    Error: (" . mysql_errno() . ") " . mysql_error());

    echos this in your instance:

    A MySQL error has occurred. Error: (1064) 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 '' . ' ID INT NOT NULL AUTO_INCREMENT PRIMARY KEY, ' . ' please VARCH' at line 1

    This then indicates to me that the error regards " & '.


    After changing the code to contain single quotes and executing it, there is now no echo.

       Error: (" . mysql_errno() . ") " . mysql_error());
    
        ?>
    

    Note: Please refer to the MySQLi extension when using SQL embedded in PHP. mysql_* is in a deprecation process.

    Hope this helps.

提交回复
热议问题