Good day! Made the form with request and function of record in a DB, but it brings empty values. What's wrong?

Actually source:

The form

<form action="zapros.php" method="post" name="form"> Имя: <input type="text" name"name"><br> Год: <input type="text" name"year"><br> Хозяин: <input type="text" name"xoz"><br> <input type="submit" value="Запрос" name="submit"> </form> 

request handler:

 <? $name = $_POST['name']; $year = $_POST['year']; $xoz = $_POST['xoz']; $db = mysql_connect ("localhost","test","12345"); mysql_select_db("test",$db); $result = mysql_query("INSERT INTO names (name,year,xoz) VALUES ('$name','$year','$xoz')"); if ($result == 'true') { echo "Успешно!"; } else { echo "Неудачно!"; } ?> 
  • one
    1. Show the form or at least the fully opening <form> tag with all its attributes. 2. Form data is sent to a separate file handler or on the same page? 3. What is the coding of your documents? 4. In the example is not visible, but do you screen the data? 5. Have you tried to display "flown" variables from a POST request? If so, was there any data? - Deonis
  • @ bazaev05, you somehow did not notice four more leading questions)) - Deonis

2 answers 2

Take a closer look at your form code. Do you everywhere name "name" as well forgot? :) It must be so name = "name".

PS Please remember as 2 * 2, ALL the data coming from the user MUST BE SCROLLED! There is no more terrible error for a WEB programmer than $ name = $ _POST ['name'];

    For starters - where did you get such vulgarity? )) Is it again Popov-detected?

     if ($result == 'true') { // ... } 

    Simple enough:

     if ($result) { // ... } 

    Secondly, try to do the following in the handler file:

     if(isset($_POST['name'], $_POST['year'], $_POST['xoz'])){ $db = mysql_connect ("localhost","test","12345"); mysql_select_db("test",$db); $name = mysql_real_escape_string($_POST['name']); $year = mysql_real_escape_string($_POST['year']); $xoz= mysql_real_escape_string($_POST['xoz']); $query = "INSERT INTO names (name,year,xoz) VALUES ('$name','$year','$xoz')"; echo $query; } else { echo "А запросик то и не долетел!"; } 

    If everything is fine, then we look at the encoding in which the data is displayed. If the encoding is all good, then remove the echo $ query; and write the query:

     // ... $query = "INSERT INTO names (name,year,xoz) VALUES ('$name','$year','$xoz')"; $result = mysql_query($query, $db); // ... 

    By the way, I forgot to ask what encoding do you have in the database?