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
You
post
到后端的时候是个空值吗? 您用echo
为空时就看不到的,您用var_dump($_POST)
print it like thisThe 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
Hmm, I recommend jquery as a simpler ajax post method
This method is simpler
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 pictureYou try it
...
You haven’t posted anything worth it, how can it be worth it?
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
The error level is too high
Add a sentence to the header
error_reporting(0);
Can be used
Cut it off and take a look!
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?
The logic is wrong. The value queried in the database is not the value submitted this time, but the value inserted previously