$result = mysql_query('"SELECT * FROM jo_postWHERE id='.$id.'"');
So why can't I output the database content?
Reply content:
$result = mysql_query('"SELECT * FROM jo_postWHERE id='.$id.'"');
So why can't I output the database content?
PHP three major MySQL connection methods (5.4 start to drive the underlying implementation are all MYSQLND):
http://php.net/manual/zh/mysqli.overview.php
Mysqli (preferred) pdo_mysql (recommended) MySQL (not recommended)
PHP7 has not supported the MySQL extension, recommended landlord instead of mysqli extension.
In addition, the landlord directly splicing strings as SQL query conditions, there is a risk of SQL injection, it is recommended to first intval to integer type, or use preprocessing binding parameter query.
query('SELECT * FROM post WHERE id='.intval($id))->fetch_all());//MySQLi绑定参数查询:$db = @new mysqli('127.0.0.1','user','pass','dbname',3306);$stmt = $db->prepare('SELECT * FROM posts WHERE id=?'); //预处理$stmt->bind_param('i', $id); //绑定参数(可以防止SQL注入)$stmt->execute(); //查询var_export($stmt->get_result()->fetch_all());
$result = mysql_query ("select * from Jo_post WHERE id= $id");
You're not talking to MySQL that way.
You try it first.echo '"SELECT * FROM jo_postWHERE id='.$id.'"';
And let MySQL do it.
The SELECT statement should be a keyword, and you're taking him as a string.
As you write your hair, you perform a "select * from Jo_post WHERE id=xx" includes these two quotes
Will you $result variables, with the Echo statement output to the screen, and then copied out, in the MySQL Management interface (Common phpMyAdmin) hit the corresponding data table, open the SQL menu, paste the variable SQL statement, execute, you can know the statement is right, General SQL statements are written in double quotes and single quotes, with double quotation marks in the outside and single quotes. You can't output data content, which is the SQL syntax error.
Find out the use of single and double quotes.