Php 当我提交数据时,它不会显示在表中,并显示错误。刷新后正确显示。我使用ajax来实现这一点吗?
我想从数据库中赋值 HTMLPhp 当我提交数据时,它不会显示在表中,并显示错误。刷新后正确显示。我使用ajax来实现这一点吗?,php,Php,我想从数据库中赋值 HTML 如果点击submit,无论是否附加了文件,都可以关闭第66行的数据库连接 然后尝试从关闭的连接获取新数据,这是不可能的 您必须将mysql\u关闭($conn)到脚本中的其他位置 <?php $dbhost = 'localhost:3306'; $dbuser = 'root'; $dbpass = 'root'; $conn = mysql_connect($dbhost, $dbuser, $dbpass); mysql_select_db("test
如果点击submit,无论是否附加了文件,都可以关闭第66行的数据库连接
然后尝试从关闭的连接获取新数据,这是不可能的
您必须将mysql\u关闭($conn)代码>到脚本中的其他位置
<?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\n";
}
$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\n";
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>