gpt4 book ai didi

javascript - 这里我有一个 HTML 表单和 PHP MySQL 表,在表中输入值并按下提交按钮后,没有出现输出

转载 作者:行者123 更新时间:2023-11-29 21:52:27 25 4
gpt4 key购买 nike

这里我有一个 HTML 表单和 PHP MySQL 表,在表中输入值并按下提交按钮后,没有出现输出。

这是我用于创建、插入和显示 MySQL 表的 PHP 代码:

<?php
$id=$_POST["id"];
$cs=$_POST["cs"];


$tab="create table stock1 (id INT PRIMARYKEY, Closing_Stock INT)";
$in="INSERT into stock1 values('$id','$cs')";
$q="SELECT * FROM stock1";

$con=new mysqli("localhost","root","","test");


mysqli_query($con,$tab);
mySqli_query($con,$in);
$re=mysqli_query($con,$q)or die(mysql_error());

while($row=mysqli_fetch_array($re))


{
echo $row[0]."&nbsp &nbsp".$row[1]."&nbsp &nbsp".$row[2]."&nbsp &nbsp".$row[3]."&nbsp &nbsp".$row[4];
}
?>

这是我的 HTML 表单代码:

<html>
<head>
<title>Database</title>

</head>

<body>

<form name="form1" action="stk1.php" method="post" >
<table cellpadding=5 cellspacing=10 align="center" width="600" height="200">
<caption><font size=20 font color=black>DETAILS</font></caption>
<tr>
<td>
<font color="white">Id </font>
</td>
<td>
<input type="text" name="id"/>
</td></tr><br>
<tr>
<td>
<font color="white">Stock /Opening : </font>
</td>
<td>
<input type="text" name="cs" />
</td></tr>

<tr><td>
<input type="submit" />
</td>
<td>
<input type="reset" />
</td>
</tr>
</table>
</form>
</body>
</html>

最佳答案

阅读您犯错误并需要改进代码的行的注释。

$id = $_POST["id"];
$cs = $_POST["cs"];

if (isset($id) && isset($cs)) {// check for input values


$tab = "CREATE TABLE IF NOT EXISTS `stock1` (
`id` int(11) NOT NULL DEFAULT '0',
`Closing_Stock` int(11) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;";// use TABLE IF NOT EXISTS here

$in = "INSERT INTO stock1 (id,Closing_Stock) values('$id','$cs')";// forget column name
$q = "SELECT * FROM stock1";
$con = new mysqli("localhost", "root", "", "test");
mysqli_query($con, $tab);
mysqli_query($con, $in);// check spelling of mysqli
$re = mysqli_query($con, $q) or die(mysql_error());

while ($row = mysqli_fetch_array($re,MYSQLI_NUM)) {// add MYSQLI_NUM for numeric array
echo $row[0] . "&nbsp &nbsp" . $row[1];// only two column in your code
}
}

关于javascript - 这里我有一个 HTML 表单和 PHP MySQL 表,在表中输入值并按下提交按钮后,没有出现输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33498820/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com