完成 PHP 新手,但尝试将简单的表单提交到 MySQL 数据库。我不断收到通知:未定义的索引:我的表单输入变量上的警告。这里可能有什么问题。该表单位于提交到 process.php 文件的单独 PHP 页面上。
表格代码:
<form name="example" id="example" method="POST" action="process.php" enctype="multipart/form-data">
<p>
<label for="first_name">First Name:</label>
<input size="20" name="first_name" id="first_name" />
</p>
<p>
<label for="city">city</label>
<input size="20" name="city" id="city" />
</p>
<p>
<label for="state">state</label>
<input size="20" name="state" id="state" />
</p>
<p>
<label for="zip">zip</label>
<input size="20" name="zip" id="zip" />
</p>
<p>
<label for="email">e-mail</label>
<input size="20" name="email" id="email" />
</p>
<p>
<label for="form_upload">file</label>
<input size="40" type="file" name="form_data" id="form_data" />
</p>
<p>
<input type="submit" value="Submit form" name="submit" />
</p>
</form>
进程.php
<?php
mysql_connect("localhost", 'root', '') or die('Could not connect:' . mysql_error());
mysql_select_db("practice") or die(mysql_error());
mysql_query("CREATE TABLE user (id INT(5)NOT NULL AUTO, name VARCHAR(30), email VARCHAR(40), city VARCHAR(40), state VARCHAR(3), zip INT(5) )");
if (isset($_POST)) {
$name = $_POST['first_name'];
$email = $_POST['email'];
$city = $_POST['city'];
$state = $_POST['state'];
$zip = $_POST['zip'];
}
mysql_query("INSERT INTO user VALUES('$name', '$email', '$city', '$state', '$zip')");
?>