1

I am trying to fetch the values of updated records from dp. Let me brief this-

1.I have two while loops ,one for displaying the records from database and second to fetched after edit operation.

2.After editing 1 of the fields the record should be updated in database [i have successfully updated record/records too in db ] but the problem is its updating successfully in database [ as i do have checked my db as i update record] but the records are not displayed of updated records. I think it does not enter the while loop of update query.

Please suggest some solution.

if(isset($_POST['recruiter_s_by_code'])
{
 //some code here...the query here is being a sucesss
 //SELECT STATEMENT here..
}
if(isset($_POST['recruiter_s_by_mail'])
{
 //some code here...the query here is being a sucesss
 //SELECT STATEMENT here..
}
if(isset($_POST['recruiter_s_by_name'])
{
 //some code here...the query here is being a sucesss
 //SELECT STATEMENT here..
}

if(isset($_POST['recruiter_s_by_code']) || isset($_POST['recruiter_s_by_name']) || isset($_POST['recruiter_s_by_mail'])) 
{
 $result=mysql_query($sql);
 echo "in result"
 while($row=mysql_fetch_array($result))
 {
    $viewrecruiter0=$row['recruiter_did'];
    $viewrecruiter1=$row['recruiter_name'];
    $viewrecruiter2=$row['recruiter_mail'];

 } 
 }

 else
 {
    if(isset($_GET['var']))
    {
      $id1=$_GET['var'];
      echo $id1;
    }
    //$query1=UPDATE .......SET......WHERE...   ->the update too is a success for me.
$res=mysql_query($query1);
while($row=mysql_fetch_array($res)) 
{       
 $viewrecruiter00=$row['recruiter_did']; //by code
 $viewrecruiter01=$row['recruiter_name'];
 $viewrecruiter02=$row['recruiter_mail'];
}
}
?>

The query of UPDATE is running successfully but the records are not displayed after UPDATE click. Only the Label are being displayed but not the values.

6
  • You have to run a select to get data; update only updates. Also things to note, if you are using $id1 in your update you are open to SQL injections. The mysql_ functions are outdated, you should use PDO or mysqli_. Commented May 14, 2015 at 4:14
  • An UPDATE query doesn't return a result set. Commented May 14, 2015 at 4:14
  • @HoboSapiens...what should I do then ? Suggest me. Commented May 14, 2015 at 4:18
  • Run a select with the same where clause, or you want only the IDs that were updated? Commented May 14, 2015 at 4:19
  • @chris85..have edited my post...the select statements are there in 1st three " if(isset()) " and as this is raw code ,as soon as it gets successfull, I have anothere backup where I have used mysqli for preventing sql injections. Commented May 14, 2015 at 4:24

1 Answer 1

2

It sounds like you are editing/updating one record at a time so execute your update then run a select on the same record.

//$query1=UPDATE .......SET......WHERE...   ->the update too is a success for me.
$res=mysql_query($query1);
//$query1='select yada yada yada from table where SAME CONDITIONS';
$res=mysql_query($query1);
while($row=mysql_fetch_array($res)) {

If $id1 is being used in the query it needs to be at minimum put into mysql_real_escape_string. I'm also unclear what you mean when you are saying I have anothere backup where I have used mysqli you should use mysqli over mysql_ whenever possible.

Sign up to request clarification or add additional context in comments.

2 Comments

@chris85...i will try out this now...and another back means "this same code where I don't use the deprecated version like mysql" inseated i have used mysqli. Thank you. :)
Thank you for the solution. The skeleton i followed and it worked for me. Thank You again :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.