Hi,
I am writing the code for editauthors.php and had a few syntax problems that I have weeded out and now the page displays after click 'edit' sending the query
http://localhost/mysql_database/editauthor.php?id10
The interface is a little unintuitive as you have no idea what user you are editing but I am sure I can fix that with an echo $name $email above the form.
The problem is that once I enter new information in to the edit form. It reports a success and I go back to the authors page to find the edit has not been made? I double checked via the terminal SELECT * FROM authors; and the read out matches the web page. So I am stuck, and I get no errors!?
Any help would be grand!Code:<?php // A new author has been entered // Using the form below // Connect to the database server $dbcnx = @mysql_connect('localhost', 'root', 'password'); if (!$dbcnx) { exit('<p>Unable to connect to' . 'Datadabe server at this time</p>'); }else{ echo '<p>You have sucessfully conneted to the database server</p>'; } // Select the jokes database if (!@mysql_select_db('ijdb')) { exit('<p>Unable to locate the joke ' . 'database at this time</p>'); }else{ echo '<p>You have sucessfully conneted to the jokes database</p>'; } if (isset($_POST['name'])): // The author's details have been updated. $name = $_POST['name']; $email = $_POST['email']; $id = $_POST['id']; $sql = "UPDATE author SET name='$name', email='$email' WHERE id='$id'"; if (@mysql_query($sql)) { echo '<p>Author details updated.</p>'; } else { echo '<p>Error updating author details: ' . mysql_error() . '</p>'; } ?> <p><a href="authors.php">Return to authors list</a></p> <?php else: // Allow the user to edit the author $id = $_GET['id']; $author = @mysql_query( "SELECT name, email FROM author WHERE id='$id'"); if (!$author) { exit('<p>Error fetching author details: ' . mysql_error() . '</p>'); } $author = mysql_fetch_array($author); $name = $author['name']; $email = $author['email']; // Convert special characters for safe use // as HTML attributes. $name = htmlspecialchars($name); $email = htmlspecialchars($email); ?> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <p>Edit the author:</p> <label>Name: <input type="text" name="name" value="<?php echo $name; ?>" /></label><br /> <label>Email: <input type="text" name="email" value="<?php echo $email; ?>" /></label><br /> <input type="hidden" name="id" value="<?php echo $id; ?>" /> <input type="submit" value="SUBMIT" /></p> </form> <?php endif; ?>




Bookmarks