我能够连接到mysql数据库但是我无法将表单中的数据显示到我的数据库中。我不知道为什么会这样,但我能够从我的数据库中检索数据我只是无法输入信息。现在我只想输入First_Name。在向表单输入数据时,我也没有错误。任何帮助将不胜感激!!
<p>
<form name="input1" action="http://seanfagan.webuda.com/Final/club.php" method="post">
First_Name:<input type="text" name="First_Name"><br>
Last_Name: <input type="text" name="Last_Name"><br>
Club_Name: <input type="text" name="Club_Name"><br>
Email: <input type="text" name="Email"><br>
Club_Type: <input type="text" name="Club_Type"><br>
Members: <input type="text" name="Members"><br>
<input type="submit" value="Send"><br>
</form>
<?php
$mysql_host = "mysql14.000webhost.com";
$mysql_database = "a9576602_Final";
$mysql_user = "a9576602_Final";
$mysql_password = "*****![enter image description here][1]";
$mysql_error = "Could not connect to database!";
$conn = mysql_connect($mysql_host, $mysql_user, $mysql_password) or die ("$mysql_error");
$select_db= mysql_select_db('a9576602_Final') or die ("Couldn't select database!");
$value = $_Post['input1'];
$sql = "INSERT INTO Club (First_Name) VALUES ('First_Name')";
if (!mysql_query($sql)) {
die('Errorss: ' . mysql_error());
}
mysql_close();
?>
</p>
答案 0 :(得分:0)
假设您与数据库的连接没问题。您可以为提交按钮添加<name>
属性,以作为通过$ _POST方法发送表单的参考:
<input type = "submit" name = "input1" value = "Submit">
然后使用它,你可以触发你的insert语句:
<?php if(isset($_POST['input1'])) { // make sure you also declare the variables in your form such as the first name, etc. $firstName = $_POST['First_Name']; mysql_query("INSERT INTO Club (First_Name) VALUES ('$firstName')"); } ?>
希望这可以帮助你:D