它一直告訴我它無法插入到數據庫中。 有人可以概述我做錯了什麼嗎?直到現在,我從未遇到任何問題。PHP腳本無法插入到數據庫中
<html>
<title>Server logs</title>
<style type="text/css">
body{
background-color:#fff;
font-family:tahoma;
}
</style>
<body>
<center>
<h3>Server updates</h3>
<?php
//variables for connecting.
$host="localhost";
$user="root";
$pass="aion";
$db="website";
//connection to the server.
$con=mysql_connect($host, $user, $pass);
if($con)
{
echo "Connection: <font color='lime'>Connected to the database</font><br>";
}
else{
echo "Connection: <font color='red'>Couldn't connect to the database</font><br>";
}
$select=mysql_select_db($db);
if($select)
{
echo "Db status: <font color='lime'>Selected the db successfully</font>";
}
else{
echo "Db status: <font color='red'>couldn't select the database</font>";
}
?>
<br><br>
<form action="" method="post">
<table width="300" style="text-align:center;">
<tr>
<td>Username: </td>
<td><input type="text" name="username" placeholder="Enter your name here"></td>
</tr>
<tr>
<td>Update: </td>
<td><input type="text" name="update" placeholder="Enter update information here" style="width:300px;"></td>
</tr>
<tr>
<td></td>
<td><input type="submit" name="submit" value="Add"></td>
</tr>
</table>
</form>
<p>This was made so we can keep track of the updates we do to the server.</p>
<?php
if(isset($_POST['submit']))
{
if(!empty($_POST['username'] && !empty($_POST['update'])))
{
//the information that we passed from the 2 textboxes
$name=$_POST['username'];
$update=$_POST['update'];
//variables for connecting.
$host="localhost";
$user="root";
$pass="aion";
$db="website";
//connection to the server.
$con=mysql_connect($host, $user, $pass);
mysql_select_db($db);
//running a query to insert the previous information gathered into the database.
$sql=mysql_query("INSERT INTO logs (name,update) VALUES ('$name','$update') ");
//running an if statement to see if the info was inserted, if it was it will display that it was inserted else display that it wasn't.
if($sql)
{
echo "Successfully inserted the update";
}
else{
echo "There was an error inserting the info into the database";
}
}
else
{
echo "no information was entered! Please go back and input some information";
}
}
?>
</body>
</html> `
檢查'mysql_error':http://php.net/manual/en/function.mysql-error.php – danronmoon 2014-11-23 07:24:04