bora.dev
bora.dev

Reputation: 31

Input values doesnt get display in the browser instead shows blank field

I just need to insert my form data into mysql database & display it in browser. But, when I fill up the form & click submit , the row gets added but with no data except for ID field which is autoincremented.. even the table in phpmyadmin looks same with the row added & empty fileds. any suggestions will be highly appreciated...

my html form looks like this,

<table border="1">
  <tr>
    <td align="center">Form Input Students Data</td>
  </tr>
  <tr>
    <td>
      <table>
        <form method="POST" action="data_insert_htmlform.php/">
        <tr>
          <td><label for="Name">Name</label></td>
          <td><input type="text" name="name" size="20">
          </td>
        </tr>
        <tr>
          <td><label for="Age">Age</label></td>
          <td><input type="text" name="age" size="20">
          </td>
        </tr>
        <tr>
          <td><label for="Birth_Date">Birth_Date</label></td>
          <td><input type="text" name="Birth_Date" size="20">
          </td>
        </tr>
        <tr>
          <td><label for="Address"Address</label></td>
          <td><input type="text" name="address" size="40">
          </td>
        </tr>
        <tr>
          <td></td>
          <td align="center">
              <input type="submit" name="submit" value="Sent">
          </td>
        </tr>
        </form>
        </table>
      </td>
    </tr>
</table>

and my php code,

<?php

error_reporting(E_ERROR | E_PARSE);

$database = 'students';
$continued=mysql_connect("localhost" , "root", "");

if(mysql_select_db($database))
echo ("<br><br>connection to the database succeeds");
else
echo ("connection failed");

/*$name = $_POST['name'];
$age = $_POST['age'];
$birth_date = $_POST['Birth_date'];
$address = $_POST['address'];*/

$insert = "INSERT INTO students_basicinfo(Name, Age, Birth_Date, Address) VALUES ('{$_POST['name']}','{$_POST['age']}' , '{$_POST['Birth_date']}' , '{$_POST['address']}')";

$abc = mysql_query($insert);
if($abc){
    echo("<br>Input data is succeed");
}else{
    echo("<br>Input data is fail");
}

$order = "SELECT * FROM students_basicinfo";
$result = mysql_query($order);

if($result === FALSE) {
die(mysql_error()); // TODO: better error handling
}

echo "<table border='1'>";

    while($data = mysql_fetch_array($result))
    {
        echo "<tr>";
               echo "<td>".$data[ID]."</td>";
               echo "<td>".$data[Name]."</td>";
               echo "<td>".$data[Age]."</td>";
               echo "<td>".$data[Birth_Date]."</td>";
               echo "<td>".$data[Address]."</td>";
        echo "</tr>";
    }

echo "</table>";

?>

Upvotes: 1

Views: 270

Answers (4)

Joop Eggen
Joop Eggen

Reputation: 109547

(Use prepared statements.)

  • Dump the statement, in a HTML comment <!-- ... ---> so you can try it yourself.
  • Use echo mysql_error() to check for errors.
  • I mistrust the date field, DATE? Use '2013-08-31or '2013-08-31 14_:07 / '2013-08-31T14_:07`.

Upvotes: 0

Bora
Bora

Reputation: 10717

This issue about input name case sensitive

Change $_POST['Birth_date'] to $_POST['Birth_Date'] with uppercase D

Try following query, this will work.

$insert = "INSERT INTO students_basicinfo(Name, Age, Birth_Date, Address) VALUES ('{$_POST['name']}','{$_POST['age']}' , '{$_POST['Birth_Date']}' , '{$_POST['address']}')";

Upvotes: 1

trrrrrrm
trrrrrrm

Reputation: 11802

Try :

 echo "<tr>";
               echo "<td>".$data['ID']."</td>";
               echo "<td>".$data['Name']."</td>";
               echo "<td>".$data['Age']."</td>";
               echo "<td>".$data['Birth_Date']."</td>";
               echo "<td>".$data['Address']."</td>";
        echo "</tr>";

Upvotes: 0

Dipesh Parmar
Dipesh Parmar

Reputation: 27364

Replace

'{$_POST['name']}','{$_POST['age']}' , '{$_POST['Birth_date']}' , '{$_POST['address']}'

with

'".$_POST['name']."','".$_POST['age']."' , '".$_POST['Birth_date']."' , '".$_POST['address']."'

Upvotes: 0

Related Questions