我无法将字符串添加到数据库中,我不知道为什么,但只添加了空字符串。我认为主要问题在于这部分代码(PHP):
$word=$_POST[".$i."];
mysql_query("INSERT INTO words(word) VALUES('$word')",$connection);
我需要添加几个字符串,我从(文本输入)s 到数据库
整个代码在这里:
<html>
<head>
<title>Admin Panel (Second Page)</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<?php
error_reporting(0);
$user="root";
$pass="";
$connection = mysql_connect("localhost",$user,$pass);
mysql_query("CREATE DATABASE IF NOT EXISTS quiz",$connection);
mysql_select_db("quiz",$connection);
mysql_query("CREATE TABLE IF NOT EXISTS words(id MEDIUMINT NOT NULL AUTO_INCREMENT,word TEXT,PRIMARY KEY(id))",$connection);
$number = $_POST['numberOfWords'];
echo "<form action=SecondAdminPage.php method=POST ENCTYPE='multipart/form-data'>";
for($i=1; $i<=$number; $i++)
{
echo "<input type='text' name='$i'>";
$word=$_POST[$i];
mysql_query("INSERT INTO words(word) VALUES('$word')",$connection);
}
echo "<input type='submit' value='Save'>";
?>
</form>
</body>
</html>
谢谢