dongqie4402 2014-02-08 16:05
浏览 13

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

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.

  • 写回答

3条回答 默认 最新

  • dook0034 2014-02-08 16:13
    关注

    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.

    评论

报告相同问题?

悬赏问题

  • ¥15 r语言神经网络自变量重要性分析
  • ¥15 基于双目测规则物体尺寸
  • ¥15 wegame打不开英雄联盟
  • ¥15 公司的电脑,win10系统自带远程协助,访问家里个人电脑,提示出现内部错误,各种常规的设置都已经尝试,感觉公司对此功能进行了限制(我们是集团公司)
  • ¥15 救!ENVI5.6深度学习初始化模型报错怎么办?
  • ¥30 eclipse开启服务后,网页无法打开
  • ¥30 雷达辐射源信号参考模型
  • ¥15 html+css+js如何实现这样子的效果?
  • ¥15 STM32单片机自主设计
  • ¥15 如何在node.js中或者java中给wav格式的音频编码成sil格式呢