Jump to content

Update the database


zeinaK

Recommended Posts

Hello,

 

I am trying to update my database using a form.

 

While submitting this function is called, but nothing is changed. If I replace the variables with values, the function works fine, but not with variables.

 

function updateCandidate($id, $F_Name, $L_Name, $Gender, $Bday, $PhoneNo, $Address, $City, $Country, $Nationality, $experience, $Stat)
{
      $q = "UPDATE candidates SET F_Name = '$F_Name', L_Name='$L_Name', Gender='$Gender', 
      Bday='$Bday', PhoneNo='$PhoneNo', Address = '$Address', City='$City', 
      Country = '$Country', Nationality = '$Nationality', Experience_idExperience='$experience', 
      Status= $Stat WHERE Users_UsersID = $id";
       return mysql_query($q, $this->connection);

Link to comment
Share on other sites

There are a few things that could prevent your query from working -

 

1) The $id variable either doesn't have any value (this would produce a query error) or it doesn't have a value that matches any row in your table (this would result in a query that affects zero rows),

 

2) One or more of the variables contains special sql characters and needs to be escaped (this would produce a query error),

 

3) The $Stat value is a non-numeric value and needs to be enclosed in single-quotes (this would produce a query error.)

 

Have you echoed the $q variable so that you can see what it actually contains?

 

Are you testing the value that mysql_query() returns somewhere so that you know if the query executed without or with an error? If the query executes without any errors, are you using mysql_affected_rows to find out if the query did or didn't update the row?

Link to comment
Share on other sites

What does this function return?

 

function updateCandidate($id, $F_Name, $L_Name, $Gender, $Bday, $PhoneNo, $Address, $City, $Country, $Nationality, $experience, $Stat)
{
      $q = "UPDATE candidates SET F_Name = '$F_Name', L_Name='$L_Name', Gender='$Gender', 
      Bday='$Bday', PhoneNo='$PhoneNo', Address = '$Address', City='$City', 
      Country = '$Country', Nationality = '$Nationality', Experience_idExperience='$experience', 
      Status= $Stat WHERE Users_UsersID = $id";
       if(mysql_query($q, $this->connection)) { return true; }
      else {echo $q . ' has encountered an error<br />' . mysql_error(); return false; }
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.