• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 291
  • Last Modified:

PHP - sql script

I use this blow code which works fine..
but I need to refersh the page or click the link again, which I send for email verification, for it to  run the update statement.
mysql_query("UPDATE Mytable SET Approve='1' WHERE Email='$email'") it doesn't uptade the Approve column when I open the page. I need to refersh the page.. but it works
what do you suggest I should do?


$result = mysql_query("SELECT * FROM Mytable where Email='$email' and Confirmation='$ConfirmationCode'")
or die(mysql_error());  

if (mysql_num_rows($result)  == 0)
{
  echo "Error: No match found ";
}
else
{
mysql_query("UPDATE Mytable SET Approve='1' WHERE Email='$email'")
or die(mysql_error());  
}

echo "<table border='1'>";
echo "<tr> <th>Name</th> <th>Age</th> </tr>";
// keeps getting the next row until there are no more to get
while($row = mysql_fetch_array( $result )) {
      // Print out the contents of each row into a table
      echo "<tr><td>";
      echo $row['id'];
      echo "</td><td>";
      echo $row['Name'];
      echo "</td><td>";
      echo $row['Surname'];
      echo "</td><td>";
      echo $row['Email'];
      echo "</td><td>";
      echo $row['Confirmation'];
      echo "</td><td>";
      echo $row['IP'];
      echo "</td><td>";
      echo $row['Date'];
      echo "</td><td>";
      echo $row['Market'];
      echo "</td><td>";
      echo $row['Approve'];
      echo "</td></tr>";  }

echo "</table>";
}

Open in new window

0
Braveheartli
Asked:
Braveheartli
  • 2
  • 2
1 Solution
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
you are doing the update before the select, hence the select cannot expect the select to show that data.

as you update the value to 1, you could hard-code the output:

$result = mysql_query("SELECT * FROM Mytable where Email='$email' and Confirmation='$ConfirmationCode'")
or die(mysql_error());  

if (mysql_num_rows($result)  == 0)
{
  echo "Error: No match found ";
}
else
{
mysql_query("UPDATE Mytable SET Approve='1' WHERE Email='$email'")
or die(mysql_error());  
}

echo "<table border='1'>";
echo "<tr> <th>Name</th> <th>Age</th> </tr>";
// keeps getting the next row until there are no more to get
while($row = mysql_fetch_array( $result )) {
      // Print out the contents of each row into a table
      echo "<tr><td>";
      echo $row['id'];
      echo "</td><td>";
      echo $row['Name'];
      echo "</td><td>";
      echo $row['Surname'];
      echo "</td><td>";
      echo $row['Email'];
      echo "</td><td>";
      echo $row['Confirmation'];
      echo "</td><td>";
      echo $row['IP'];
      echo "</td><td>";
      echo $row['Date'];
      echo "</td><td>";
      echo $row['Market'];
      echo "</td><td>";
      echo "1";
      echo "</td></tr>";  }

echo "</table>";
}

Open in new window

0
 
BraveheartliMarketingAuthor Commented:
you are great..
0
 
BraveheartliMarketingAuthor Commented:
Dear angelll,
I wonder what you have changed? it works now.. but I couldn't see the diffrence..
thank you
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
I changed:

echo $row['Approve'];

into:

echo "1";
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now