Hi all,
I am very new to PHP and MYSQL and have a class assignment I need help with. I am trying to make a page with an HTML form that will update my MYSQL database. You can view my pages online here: http://baileyjumper.aisites.com/Scripting-Week7/homework4/exercise-five.php
I need help with the "Edit" section, if you look online.
Here is the code for my Edit page:
<?php
$hostname = "localhost";//host name
$dbname = "baileyjumper_imd203";//database name
$username = "baileyjumper_imd";//username you use to login to php my admin
$password = "chris4ever";//password you use to login
//CONNECTION OBJECT
//This Keeps the Connection to the Databade
$conn = new MySQLi($hostname, $username, $password, $dbname) or die('Can not connect to database')
?>
<!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>Untitled Document</title>
</head>
<body>
<?php
//Create a query
$sql = "SELECT * FROM Books WHERE BookID = '".$bookid."'";
//submit the query and capture the result
$result = $conn->query($sql) or die(mysql_error());
$query=getenv(QUERY_STRING);
parse_str($query);
//$ud_title = $_POST['Title'];
//$ud_pub = $_POST['Publisher'];
//$ud_pubdate = $_POST['PublishDate'];
//$ud_img = $_POST['Image'];
?>
<h2>Update Record <?php echo $bookid;?></h2>
<form action="" method="post">
<?php
while ($row = $result->fetch_assoc()) {?>
<table border="0" cellspacing="10">
<tr>
<td>Title:</td> <td><input type="text" name="updatetitle" value="<?php echo $row['Title']; ?>"></td>
</tr>
<tr>
<td>Publisher:</td> <td><input type="text" name="updatepublisher" value="<?php echo $row['Publisher']; ?>"></td>
</tr>
<tr>
<td>Publish Date:</td> <td><input type="text" name="updatepubdate" value="<?php echo $row['PublishDate']; ?>"></td>
</tr>
<tr>
<td>Image URL:</td> <td><input type="text" name="updateimg" size="100" value="<?php echo $row['Image']; ?>"></td>
</tr>
<tr>
<td><INPUT TYPE="Submit" VALUE="Update the Record" NAME="Submit"></td>
</tr>
</table>
<?php }
?>
</form>
<?php
if(isset($_POST['Submit'])){//if the submit button is clicked
$update = $_POST['updatepubdate'];
$query="UPDATE Books SET PublishDate=$update where BookID = '".$bookid."'";
//$query = "UPDATE Books WHERE BookID = '".$bookid."'";//update the database query
mysql_query($query) or die("Cannot update");//update or error
}
?>
</body>
</html>
I don't have the form currently redirecting to another page because right now I can't even get the update to work. But, I eventually want to display a confirmation message either on the same or a different page.
Thank You!!!!