Solved

PHP - sql script

Posted on 2010-08-26
4
281 Views
Last Modified: 2013-12-13
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
Comment
Question by:Braveheartli
  • 2
  • 2
4 Comments
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
Comment Utility
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
 
LVL 1

Author Closing Comment

by:Braveheartli
Comment Utility
you are great..
0
 
LVL 1

Author Comment

by:Braveheartli
Comment Utility
Dear angelll,
I wonder what you have changed? it works now.. but I couldn't see the diffrence..
thank you
0
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
Comment Utility
I changed:

echo $row['Approve'];

into:

echo "1";
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now