I am new to PHP and database design. I'm having trouble deleting a row from my database using PHP. I get these errors when I click the "delete" button on my webpage:
- Warning: mysqli_connect(): MySQL server has gone away in H:\wamp64\www\cs3100hw3\hw3.php on line 63
- Warning: mysqli_connect(): Error while reading greeting packet. PID=13284 in H:\wamp64\www\cs3100hw3\hw3.php on line 63
- Warning: mysqli_connect(): (HY000/2006): MySQL server has gone away in H:\wamp64\www\cs3100hw3\hw3.php on line 63
Line 63 begins with $conn
. Additionally, execution takes quite a while, so I assume there's some kind of timing out issue. I am using WampServer, if that makes a difference. Any help is appreciated!
<?php
if(isset($_POST['delete'])) {
$dbhost = 'localhost:8000';
$dbuser = 'root';
$dbpass = '';
$db = 'hw2';
$conn = mysqli_connect($dbhost, $dbuser, $dbpass, $db);
if(! $conn ) {
die('Could not connect: ' . mysql_error());
}
$last_name = $_POST['last_name'];
$sql = "DELETE FROM hockeyplayers WHERE lastname = $last_name" ;
mysqli_select_db('test_db');
$retval = mysql_query( $sql, $conn );
if(! $retval ) {
die('Could not delete data: ' . mysql_error($conn));
}
echo "Deleted data successfully\n";
mysqli_close($conn);
}else {
?>
<form method = "post" action = "<?php $_PHP_SELF ?>">
<table width = "400" border = "0" cellspacing = "1"
cellpadding = "2">
<tr>
<td width = "100">Last Name</td>
<td><input name = "last_name" type = "text"
id = "last_name"></td>
</tr>
<tr>
<td width = "100"> </td>
<td> </td>
</tr>
<tr>
<td width = "100"> </td>
<td>
<input name = "delete" type = "submit"
id = "delete" value = "Delete">
</td>
</tr>
</table>
</form>
<?php
}
?>