我想使用php mysql自动填充我的数据字段。我使用stu_id
的id搜索我的数据。我的数据库是这样的
stu_id s_name reg program
等
然后我添加了3个新的输入字段,并希望插入一个名为payment_all
的新表。
这是我的auto.php
文件
<!DOCTYPE HTML>
<head>
<title></title>
</head>
<body>
<!-- form to get key detail of record in database -->
<form name="form" method="POST" action="">
Keyfield <input type="text" name="search"> <br><br>
<input type="submit" value="submit">
</form>
<?php
$connection = mysql_connect('localhost','root','') or die ("Couldn't connect to server.");
$db = mysql_select_db('assignment', $connection) or die ("Couldn't select database.");
$search=$_POST['search'];
$data = 'SELECT * FROM `stu_tbl` WHERE `stu_id` = "'.$search.'"';
$query = mysql_query($data) or die("Couldn't execute query. ". mysql_error());
$datas = mysql_fetch_array($query);
?>
<!-- form to display record from database -->
<form name="form" method="POST" action="search.php">
Name: <input type="text" name="s_name" value="<?php echo $datas['s_name']?>"/> <br>
Reg: <input type="text" name="reg" value="<?php echo $datas['reg']?>"/> <br>
Faculty: <input type="text" name="factxt" value="<?php echo $datas['program']?>"/><br><br>
<input type="hidden" name="stu_id" value="<?php echo $search?>">
Semester: <input type="text" name="semtxt"><br>
Payment Category: <input type="text" name="papytxt"><br>
Total Pay: <input type="text" name="tptxt"><br>
<input type="submit" value="submit"><br>
</form>
</body>
</html>
这是我的search.php
文件
<?php
$connection = mysql_connect('localhost','root','') or die ("Couldn't connect to server.");
$db = mysql_select_db('assignment', $connection) or die ("Couldn't select database.");
$stu_id=$_POST['stu_id'];
$semester=$_POST['semtxt'];
$s_name=$_POST['s_name'];
$reg=$_POST['reg'];
$fa_name=$_POST['factxt'];
$pay_name=$_POST['papytxt'];
$totalpay=$_POST['tptxt'];
$data = mysql_query("INSERT INTO payment_all
VALUES(
NULL,
'stu_id',
'$semester',
'$s_name',
'$reg',
'$fa_name' ,
'$pay_name',
'$totalpay'
)
");
$query = mysql_query($data) or die("Couldn't execute query. ". mysql_error());
?>
<!DOCTYPE HTML>
<head>
<title></title>
</head>
<body>
<!-- display the changed record from database -->
Name: <?php echo $s_name?><br>
Reg: <?php echo $reg?> <br>
Departyment: <?php echo $program?><br><br>
</body>
</html>
我收到了错误。它说Couldn't execute query. Column count doesn't match value count at row 1