SQL error not found for beginners to die

Source: Internet
Author: User
Tags dbase sql error

Take the following code query as an example

<?phpheader ("content-type:text/html; Charset=utf-8 "); $host = "localhost"; $user = "root"; $password = "root"; $dbase _name= "Liuyan"; $table _name= "Contents"; $conn =mysql_ Connect ($host, $user, $password) or Die ("Connection server failed. ". Mysql_error ()); echo" Database server: $host user name: $user <br> "; echo" ...................................................<br> "; mysql_select_db ($dbase _name, $conn) or Die (" Failed to connect to database ". Mysql_error ()); echo" Database name: ". $dbase _name.", Data table name: ". $table _name." <br> "; mysql_query (" SET NAMES ' UTF8 ' "); $mysql _command=" select * from ". $table _name." where id=5 "; $result =mysql_query ($mysql _command, $conn) or Die (" <br> data Sheet no record <br> "); $i =0;while ($record = Mysql_fetch_row ($result)) {$i +=1;echo "ID Number:" $record [0]. " <br> "; echo" Name: ". $record [1]." <br> "; echo" Content: ". $record [2]." <br> "; echo" ...................................................<br> ";} echo "successfully displayed the datasheet". $table _name. " Records, the number of records is: ". $i;
Tips are as follows:

However, there is data in the data table, it is a long time to find the most common error when stitching SQL statements forget to add a space, the code to:

$mysql _command= "SELECT * from" $table _name. "Where id=5";
then runs through.


SQL error not found for beginners to die

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.