Dear friends, I am new to PHP. As shown in the picture, the same variable $name has no value when outputted by echo. However, the input value can be found from the database below. Why is this? , detailed questions, code attached below
This is a screenshot of the ajax request of the front-end page
ringa_lee2017-05-16 13:05:16
Youpost
到后端的时候是个空值吗? 您用echo
为空时就看不到的,您用var_dump($_POST)
print it like this
PHP中文网2017-05-16 13:05:16
The first name is taken from the form (ie: submitted by the user), and the latter name is from the database (and name is a field in the database)
The previous name can be named whatever you want. For example, $a = $_POST['name']; var_dump($a); If it is empty, it means that the user did not enter when submitting the form.
The $row['name'] at the end cannot be written randomly. For example: if you write $row['abc'], it will have no value. Because there is no abc field in the data table
为情所困2017-05-16 13:05:16
Hmm, I recommend jquery as a simpler ajax post method
$.post(uri,{'argu':data},function(res){
...你的回调操作...
})
This method is simpler
给我你的怀抱2017-05-16 13:05:16
The value of your $name is to assign the name of the post, so the name and data you want to output need to be executed first (that is to say, there will be no output if this processing page onlinedb.php is accessed directly)
Then when you After performing the ajax operation. Post has passed an array. At this time, if you echo $name;
have not deleted this line, you should be able to see the output in the network status, as shown in the picture
You try it
phpcn_u15822017-05-16 13:05:16
...
You haven’t posted anything worth it, how can it be worth it?
过去多啦不再A梦2017-05-16 13:05:16
1. Check whether inputname has data in JS.
2. Use the browser debug to see if there is data in the name in the requested onlinedb.php
为情所困2017-05-16 13:05:16
The error level is too high
Add a sentence to the header
error_reporting(0);
过去多啦不再A梦2017-05-16 13:05:16
What you print at the top is the value passed in this time.
The value you print at the bottom is traversed through the database. How do you know which one is generated this time?
世界只因有你2017-05-16 13:05:16
The logic is wrong. The value queried in the database is not the value submitted this time, but the value inserted previously