search

Home  >  Q&A  >  body text

ajax - Problems with php getting values ​​from the front end

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

仅有的幸福仅有的幸福2753 days ago1271

reply all(12)I'll reply

  • ringa_lee

    ringa_lee2017-05-16 13:05:16

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

    reply
    0
  • PHP中文网

    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

    reply
    0
  • 为情所困

    为情所困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

    reply
    0
  • 给我你的怀抱

    给我你的怀抱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

    reply
    0
  • phpcn_u1582

    phpcn_u15822017-05-16 13:05:16

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

    reply
    0
  • 过去多啦不再A梦

    过去多啦不再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

    reply
    0
  • 为情所困

    为情所困2017-05-16 13:05:16

    The error level is too high
    Add a sentence to the header
    error_reporting(0);

    reply
    0
  • 習慣沉默

    習慣沉默2017-05-16 13:05:16

    Can be used

    >var_dump($name);die();

    Cut it off and take a look!

    reply
    0
  • 过去多啦不再A梦

    过去多啦不再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?

    reply
    0
  • 世界只因有你

    世界只因有你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

    reply
    0
  • Cancelreply