当我提交数据时,它不会显示在表格中并显示错误。 刷新后显示正确

I want to assign the value from database

HTML

<?php

$dbhost = 'localhost:3306';
$dbuser = 'root';
$dbpass = 'root';
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
mysql_select_db("test_db", $conn);



if(isset($_POST['submit']))
{
if(!empty($_FILES))
  {
$allowedExts = array("gif", "jpeg", "jpg", "png","txt");
$temp = explode(".", $_FILES["resume"]["name"]);
$extension = end($temp);

if (($_FILES["resume"]["size"] < 50000)
&& in_array($extension, $allowedExts))
  {
  if ($_FILES["resume"]["error"] > 0)
    {
    echo "Error: " . $_FILES["resume"]["error"] . "<br>";
    }
  else
    {
    echo "Upload: " . $_FILES["resume"]["name"] . "<br>";
    echo "Type: " . $_FILES["resume"]["type"] . "<br>";
    echo "Size: " . ($_FILES["resume"]["size"] / 1024) . " kB<br>";
    echo "Stored in: " . $_FILES["resume"]["tmp_name"];
    }
  }
else
  {
  echo "Invalid file
";
  }

$name = $_POST['name'];
$age = $_POST['age'];
$quali = $_POST['quali'];
$state = $_POST['state'];
$country = $_POST['country'];
$msg = $_POST['msg'];
$resume = $_FILES["resume"]["name"];



$sql = "INSERT INTO form ".
       "(name,age,quali,state,country,msg,resume) ".
       "VALUES('$name','$age', '$quali', '$state','$country','$msg','$resume')";

mysql_select_db('test_db');

$retval = mysql_query( $sql, $conn );
if(! $retval )
{
  die('Could not enter data: ' . mysql_error());
}

echo "Entered data successfully
";

move_uploaded_file( $_FILES["resume"]["tmp_name"], "files/".$_FILES["resume"]["name"]);
}

mysql_close($conn);

}
?>
<div>
    <form action="<?php $_PHP_SELF ?>" method="POST" enctype="multipart/form-data">
        <div>Name:<input type="text" name="name" /></div>
        <div style="height:10px"></div>
        <div>Age:<input type="text" name="age" /></div>
        <div style="height:10px"></div>
        <div>Qualification:<input type="text" name="quali" /></div>
        <div style="height:10px"></div>
        <div>State:
        <select name="state">
          <option value="tn">TamilNadu</option>
          <option value="kl">Kerala</option>
          <option value="ka">Karnataka</option>
          <option value="ani">Andhara</option>
        </select>
</div>
        <div style="height:10px"></div>
        <div>Country:<input type="text" name="country" /></div>
        <div style="height:10px"></div>
        <div>Resume:<input type="file" name="resume" /></div>
        <div style="height:10px"></div>
        <div>Message:<textarea cols="10" rows="5" name="msg"></textarea></div>
        <div style="height:10px"></div>
        <div><input type="Submit" name="submit" value="Submit" /></div>
    </form>
</div>
<div style="height:30px"></div>

<div>
<table class="table">
    <tr>
        <th>Name</th>
        <th>Age</th>
        <th>Qualification</th>
        <th>State</th>
        <th>Country</th>
        <th>Resume</th>
        <th>Message</th>
    </tr>
    <?php
$sql1 = "SELECT * FROM form";
$retval1 = mysql_query($sql1,$conn);
while($row = mysql_fetch_array($retval1))
{
$name_s = $row['name'];
$age_s = $row['age'];
$quali_s = $row['quali'];
$state_s = $row['state'];
$country_s = $row['country'];
$resume_s = $row['resume'];
$msg_s = $row['msg'];
?>
<tr>
    <td><label name="name_s"><?php echo $name_s; ?></label></td>
    <td><label name="age_s"><?php echo $age_s; ?></label></td>
    <td><label name="quali_s"><?php echo $quali_s; ?></label></td>
    <td><label name="state_s"><?php echo $state_s; ?></label></td>
    <td><label name="country_s"><?php echo $country_s; ?></label></td>
    <td><label name="resume_s"><?php echo $resume_s; ?></label></td>
    <td><label name="msg_s"><?php echo $msg_s; ?></label></td>
</tr>
<?php
}
?>
</table>
</div>

when i submit the data, it is not shown in table and show error. after refreshing it shown correctly

It is my testing program only not for any application. tell me some suggestion. do i use ajax for that? or any other.

You should then be able to access your '$name_s' variable, and place it into your table like:

<td><label name="name_s"><?= $name_s ?></label></td>

Where the <?= $name_s ?> is a shortcut to output the variable's value outputting the value inside the label element.

<?php
$sql1 = "SELECT * FROM form";
$retval1 = mysql_query($sql1);
while($row = mysqli_fetch_array($retval1))
{
$name_s = $row['name_s'];
$age_s = $row['age_s'];
$quali_s = $row['quali_s'];
$state_s = $row['state_s'];
$resume_s = $row['resume_s'];
$msg_s = $row['msg_s'];
?>
<tr>
    <td><label name="name_s"><?php echo $name_s; ?></label></td>
    <td><label name="age_s"><?php echo $age_s; ?></label></td>
    <td><label name="quali_s"><?php echo $quali_s; ?></label></td>
    <td><label name="state_s"><?php echo $state_s; ?></label></td>
    <td><label name="resume_s"><?php echo $resume_s; ?></label></td>
    <td><label name="msg_s"><?php echo $msg_s; ?></label></td>
</tr>
<?php
}
?>

Using mysqli_connect

<?php
  $connect = mysqli_connect("localhost","user","password","your_database") or die("Error " . mysqli_error($connect));
  $query = "SELECT * FROM form" or die("Error in the consult.." . mysqli_error($connect));
  $result = $connect->query($query);
  while($row = mysqli_fetch_array($result)) {

  ?>
 <tr>
        <td><label name="name_s"><?php echo $row['name_s']; ?></label></td>
        <td><label name="age_s"><?php echo $row['age_s']; ?></label></td>
        <td><label name="quali_s"><?php echo $row['quali_s']; ?></label></td>
        <td><label name="state_s"><?php echo $row['state_s']; ?></label></td>
        <td><label name="resume_s"><?php echo $row['resume_s']; ?></label></td>
        <td><label name="msg_s"><?php echo $row['msg_s']; ?></label></td>
    </tr>
} 
?>

Using mysql_connect

 <?php
    $connect = mysql_connect("localhost","user","password");
    mysql_select_db("your_database", $connect);

    $sql = "SELECT * FROM form";
    $retval = mysql_query($sql, $connect);
    while($row = mysql_fetch_array($retval))
    { ?>
    <tr>
        <td><label name="name_s"><?php echo $row['name_s']; ?></label></td>
        <td><label name="age_s"><?php echo $row['age_s']; ?></label></td>
        <td><label name="quali_s"><?php echo $row['quali_s']; ?></label></td>
        <td><label name="state_s"><?php echo $row['state_s']; ?></label></td>
        <td><label name="resume_s"><?php echo $row['resume_s']; ?></label></td>
        <td><label name="msg_s"><?php echo $row['msg_s']; ?></label></td>
    </tr>
    <?php } ?>