Solved

PHP - sql script

Posted on 2010-08-26
4
284 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 143

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 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 33529171
I changed:

echo $row['Approve'];

into:

echo "1";
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
comma true 6 37
mysqli_query() expects parameter 1 to be msqli, string given in 4 62
Test if unique ID is in log file 5 21
Wordpress Query 5 25
Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
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 dynamically set the form action using jQuery.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

808 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