Hi,
I have a mysql database with some student info records. I am trying to Update a record in the db using a html form and a php script however it wont update.
It doesnt give me any errors.
Can anyone assit me please. Here is the code.
editingRecord.php
<?php
$conn = @new mysqli('localhost', 'root', '', 'ccm3413');
$conn->query("SET NAMES 'utf8'");
$recordID = $_GET['recordID'];
$query_str = "SELECT * FROM StudentInfo WHERE $recordID = recordID";
$result = $conn->query($query_str);
$row_data = $result->fetch_assoc();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>adding a new data record</title>
</head>
<body>
<form id="form1" name="form1" method="post" action="updateRecord.php">
<p>
<label>Student Number:
<input name="StudentNumber" type="text" id="StudentNumber" size="10" value="<?=$row_data['StudentNumber'] ?>" />
</label>
</p>
<p>
<label>First Name:
<input name="FirstName" type="text" id="FirstName" size="20" value="<?=$row_data['FirstName'] ?>" />
</label>
</p>
<p>
<label>Last Name:
<input name="LastName" type="text" id="LastName" size="20" value="<?=$row_data['LastName'] ?>" />
</label>
</p>
<p>
<label>Email Address:
<input name="EmailAddr" type="text" id="EmailAddr" size="50" value="<?=$row_data['EmailAddr'] ?>" />
</label>
</p>
<p>
<label>Telephone:
<input name="PhoneNumber" type="text" id="PhoneNumber" size="20" value="<?=$row_data['PhoneNumber'] ?>" />
</label>
</p>
<p>
<input name="recordID" type="hidden" id="recordID" value="<? $row_data['recordID'] ?>" />
<input type="submit" name="Submit" id="Submit" value="Submit" />
</p>
</form>
</body>
</html>
updateRecord.php
<?php
//connect to the database
$conn = @new mysqli('localhost', 'root', '', 'CCM3413');
if (mysqli_connect_errno() != 0)
{
$errno = mysqli_connect_errno();
$errmsg = mysqli_connect_error();
echo "Connect Failed with: ($errno) $errmsg<br/>\n";
exit;
}
$conn->query("SET NAMES 'utf8'");
//get values from HTML page
$StudentNumber = $_POST["StudentNumber"];
$FirstName = $_POST["FirstName"];
$LastName = $_POST["LastName"];
$EmailAddr = $_POST["EmailAddr"];
$PhoneNumber = $_POST["PhoneNumber"];
$recordID = $_GET['recordID'];
//add a new record into the table StudentInfo
$query_str = "UPDATE StudentInfo SET StudentNumber='$StudentNumber', FirstName='$FirstName', LastName='$LastName', EmailAddr='$EmailAddr', PhoneNumber=
'$PhoneNumber' WHERE recordID= '$recordID'";
$result = @$conn->query($query_str);
if(mysql_query($query_str)){
echo "updated";}
else{
echo "fail";}
if ($result === FALSE)
{
echo "Connection Failed <br/>";
$conn->close();
exit;
}
else
{
header('Location: displaying.php');
}
?>