PHP driven form doesn't update data back to database!!!

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • immohito
    New Member
    • Jun 2012
    • 6

    PHP driven form doesn't update data back to database!!!

    Code:
            $name = sanitize($_POST['name'], "text"); 
    		$designation = sanitize($_POST['designation'], "text");
    		$phone = sanitize($_POST['phone'], "int");
    		$date = sanitize($_POST['date'], "text");
            $id = sanitize($_POST['id'], "text"); 
            $new_id = create_guid(); 
    		
    		include_once "connect.php";
    		
    		$update_sql = "UPDATE `projects` SET `Name`={$Name}, `id`='{$new_id}' WHERE `projects`.`id`={$id};"; 
            $update_result = mysql_query($update_sql); 
            mysql_free_result($update_result);
    I have built an html form that is filled out in two steps- first by an administrator and then by the user. The code above shows the user part after the admin has already filled a few fields and hit submit. The php generates a link to another page that contains these 4 fields- name, designation, phone and date. The code above is supposed to add data to the database in the column name but its not working. Also I get a warning and a few notices about undefined variables and indexes

    Warning: mysql_free_resu lt() expects parameter 1 to be resource, boolean given in C:\Program Files\xampp\htd ocs\badger.php on line 211

    Can anyone tell me whats the problem in the code? Is it the update statement? My connect.php has no error because the previous few fields filled by the admin are being saved. The phone field shows a 0, but the other 3 are empty. Urgent help will be much appreciated. :)
  • omerbutt
    Contributor
    • Nov 2006
    • 638

    #2
    thats because you dont use mysql_free_resu lts() with update or delete clause because it is used to free allocated memory which occurs in the case of SELECT STATEMENT which on executing returns the resource or recordset where as the update query return BOLLEAN TRUE/ FALSE . just remove this stateent from your code and do check if you record is being updated or not?
    regards,
    Omer Aslam

    Comment

    Working...