www.webdeveloper.com
Results 1 to 4 of 4

Thread: editing a single row in a mysql table using a form

  1. #1
    Join Date
    Mar 2012
    Posts
    7

    editing a single row in a mysql table using a form

    Hello

    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:

    PHP Code:
    [if(isset($_POST['Submit'])){
        
        
    $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

    Here is the form I have created:

    HTML Code:
     <form action="aboutadmin.php" name="adminAbout" method="POST" >
                
              	<div>
                	<label for="pageTitle"><h2>Page Title</h2></label>
                	<textarea name="text" cols="50" rows="3"><?php echo $row['page_title']; ?></textarea>
    			</div>
                
                <div>
    		     <label for= "pageText"><h2>Displayed Text</h2> </label>
    		     <textarea name="text" cols="50" rows="30"><?php echo $row['page_text']; ?></textarea>	
                 </div>     
    		     <div>
    		     <label for="pageImage"><h2>Image</h2></label>
    		     <input id="image" name="image" type="file" />
                 </div>
                 <div>	   
    		     <input type="Submit" value="Submit">
                 </div>
              </form>

  2. #2
    Join Date
    Jan 2007
    Location
    Wisconsin
    Posts
    2,120
    I'm 98% sure nothing in the code you've posted is deleting anything. Is there more?

  3. #3
    Join Date
    Mar 2012
    Posts
    7
    That is everything, I can't understand why its not updating anything

    Do you have any idea what I am doing wrong?

    Thanks

  4. #4
    Join Date
    Jan 2007
    Location
    Wisconsin
    Posts
    2,120
    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!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles