当我尝试此代码时,出现类似错误;
Warning: mysql_select_db() [function.mysql-select-db]: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) in /home/content/28/10527728/html/TestSite/page.php on line 20
Warning: mysql_select_db() [function.mysql-select-db]: A link to the server could not be established in /home/content/28/10527728/html/TestSite/page.php on line 20
Warning: mysql_query() expects parameter 2 to be resource, null given in /home/content/28/10527728/html/TestSite/page.php on line 21
Could not update data: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
代码:
<?php
ob_start();
session_start();
if(!isset($_SESSION['Username'])){
header("Location: page.php");
}
if(isset($_POST['update']))
{
$Memberid = $_POST['Memberid'];
$Username = $_POST['Username'];
$sql = "UPDATE members ".
"SET Username = $Username ".
"WHERE Memberid = $Memberid" ;
mysql_select_db($finalform);
$retval = mysql_query( $sql, $conn );
if(! $retval )
{
die('Could not update data: ' . mysql_error());
}
echo "Updated data successfully\n";
mysql_close($conn);
}
else
{
?>
用于编辑成员表的用户名的 HTML,采用数据库最终形式;
<form method="post" action="<?php $_PHP_SELF ?>">
<table width="400" border="0" cellspacing="1" cellpadding="2">
<tr>
<td width="100">Name</td>
<td><input name="Username" type="text" id="Username"></td>
</tr>
<td width="100"> </td>
<td>
<input name="update" type="submit" id="update" value="Update">
</td>
</tr>
</table>
</form>
<?php
} //Curly bracket close from the else from the begining
?>
</body>
</html>