Solved

PHP - sql script

Posted on 2010-08-26
4
282 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
ID: 33528928
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
ID: 33529106
you are great..
0
 
LVL 1

Author Comment

by:Braveheartli
ID: 33529128
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]
ID: 33529171
I changed:

echo $row['Approve'];

into:

echo "1";
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

863 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

25 Experts available now in Live!

Get 1:1 Help Now