In
$sql = "INSERT into reply (id,id_p,time,content) VALUES (', ' $_get[post] ', now (), ' $_post[content] ')";
, the value of id_p has been 0, the rest of the value is normal, do not know why
. $_get[post] is a value that can be used above and below this code, but not in this SQL statement ...
Think of a lot of ways, such as in front of the code with $ A = $_get[post], with $row[id] (the ID in the message table is actually the value of $_get[post], do not read the value;
Is it
echo "
The problem?
Reply content:
In
$sql = "INSERT into reply (id,id_p,time,content) VALUES (', ' $_get[post] ', now (), ' $_post[content] ')";
, the value of id_p has been 0, the rest of the value is normal, do not know why
. $_get[post] is a value that can be used above and below this code, but not in this SQL statement ...Think of a lot of ways, such as in front of the code with $ A = $_get[post], with $row[id] (the ID in the message table is actually the value of $_get[post], do not read the value;
Is it
echo "
The problem?
I think you'd better define a variable to get over the value, because I have tried before, seemingly in the SQL statement of the red fruit of the write $_get such is not feasible, personal humble opinion.
PS: Inside the code low-level error looks like a lot of ... Suggested changes in the test ...
Change the SQL to $_GET[post]{$_GET['post']}
In addition, you have to strengthen the coding habits of the training, the indentation of this code makes people look crazy, and this sentenceecho "
输出的html居然没有用>闭合,属性也没有用双引号。。。需要修炼下程序员的气质
First of all, you have to figure out that MySQL will not perform any of the values submitted by the page;
Secondly, according to the code you posted, PHP will parse your page to submit the value, generate SQL statements;
Again, your code is very uncomfortable to write, disorderly indentation, no sense of hierarchy;
Again, please determine how your page is submitted, whether it is GET, or POST, if not sure, please directly with request, a GET, a will POST, really awkward ah;
Finally, "" when you write complex variables inside, remember to add {}, such as{$POST['post']}
Add:
Confirm if the parameters you submitted to the page arepost
You can print out all the values submitted by the page in the page that you posted, and add the following code in the open header:
echo
;</code><br /><code>var_dump($_REQUEST);</code><br /><code>echo
;
Your field is tinyint,tinyint from -128~127, will it overflow?
Also, in fact, Int (10) and int (1) are not different, so generally not the kind of true or false or the status type of the field, do not use INT (1), you give an int (10) just fine.
To do this, change the table structure.
$sql = "ALTER TABLE reply change ID ID int (TEN) not NULL auto_increment", mysql_query ($sql) or Die (Mysql_error ()); $sql = "Al ter table reply Change id_p id_p int (ten) not NULL "; mysql_query ($sql) or Die (Mysql_error ());
Then change the code so that all the information can be seen.
if ($_post[' submit ') { $sql = "INSERT into reply (id_p,time,content) values (' {$_get[' POST '} ', now (), ' {$_post[' Content ']} '); echo $sql; mysql_query ($sql) or Die (Mysql_error ()); $sql = "SELECT * from reply order by ID DESC limit 1"; $query = mysql_query ($sql); $result = Mysql_fetch_array ($query); Var_dump ($result);// echo "
";}
There are a few problems with SQL:
- Since the ID is already self-increasing, it is not necessary to explicitly insert the
- The variables in double quotes are best enclosed in {}.
- Mysql_query to do error handling, such as the use of or Die (Mysql_error ())