ajax - Problems with php getting values ​​from the front end
仅有的幸福
仅有的幸福 2017-05-16 13:03:16
0
12
1319

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

仅有的幸福
仅有的幸福

reply all(12)
左手右手慢动作

Youpost到后端的时候是个空值吗? 您用echo 为空时就看不到的,您用var_dump($_POST)print it like this

洪涛

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

为情所困

Hmm, I recommend jquery as a simpler ajax post method

$.post(uri,{'argu':data},function(res){
...你的回调操作...
})

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 picture

You try it

phpcn_u1582

...
You haven’t posted anything worth it, how can it be worth it?

过去多啦不再A梦

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

>var_dump($name);die();

Cut it off and take a look!

过去多啦不再A梦

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

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template