editing a single row in a mysql table using a form
I am attempting to update a row in a table using a html form and a sumbit button, however instead of updating the row its deleted everything instead. Any help would be appreciated! All of this is within a php page called "aboutadmin.php"
I want to update the table "pages", I want the table columns "page_title", "page_text" and "page_image" to be updated where the "page_id" = '4'.
Here is the code I am currently using:
Here is the form I have created:
$title = $_POST['page_title'];
$text = $_POST['page_text'];
$image = $_POST['page_image'];
$query= "UPDATE pages SET page_title = '$title', page_text = '$text', page_image = '$image' WHERE page_id = 4";
mysql_query($query) or die("Cannot update");//update or error
<form action="aboutadmin.php" name="adminAbout" method="POST" >
<label for="pageTitle"><h2>Page Title</h2></label>
<textarea name="text" cols="50" rows="3"><?php echo $row['page_title']; ?></textarea>
<label for= "pageText"><h2>Displayed Text</h2> </label>
<textarea name="text" cols="50" rows="30"><?php echo $row['page_text']; ?></textarea>
<input id="image" name="image" type="file" />
<input type="Submit" value="Submit">
I'm 98% sure nothing in the code you've posted is deleting anything. Is there more?
That is everything, I can't understand why its not updating anything
Do you have any idea what I am doing wrong?
If the top block is correct, you have a leading [ in the code. That'll prevent it from processing correctly -- but should also yield an error and/or prevent the page from rendering.
Still, nothing there should be deleting anything.
Where's the rest of your code!? There's gotta be more -- don't tell us there's not. You've got nothing here that defines the $row array used in your second block. Nothing here that INSERTS rows. Nothing here that SELECTS rows ... etc. And nothing here DELETES anything, except for the 1337 hacker who notices you're not sanitizing your query parameters!
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)