...

View Full Version : getting data from mysql "correct and incorrect"



cgibie
02-03-2007, 03:37 AM
Guys, my logic is not working very well .

<?php

include 'config.php';
include 'opendb.php';

if (isset($_GET['verify']))
{
$code = $_GET['code'];
$active = "not";

$query1 = "SELECT UserID, Activity from Member";
$result = mysql_query($query1) or die ('Error, query failed' .mysql_error());

while ($user = mysql_fetch_array($result, MYSQL_NUM))
{
// if the code entered is the sasm as UserID in the member table
if ($code == $user[0])
{
$query2 = "UPDATE member SET Activity = '$active' WHERE UserID = '$code'";
mysql_query($query2) or die ('Error, query failed' .mysql_errno());
echo "Correct";
}

}
if (mysql_query("SELECT UserID from Member WHERE UserID = '$code'")) {
echo "incorrect";
}
}
include 'closedb.php';

?>


If I put the right "code", I got the output "correctincorrect" I dont' want the output incorrect, how can I resolve this?

koyama
02-03-2007, 08:34 AM
Hi cgibie,
This part just checks whether the query is a valid. I figure that you instead want to know whether there are any rows returned from the query?


if (mysql_query("SELECT UserID from Member WHERE UserID = '$code'")) {
echo "incorrect";
}

Try using mysql_num_rows() to count the rows.


$result = mysql_query("SELECT UserID from Member WHERE UserID = '$code'");
if (mysql_num_rows($result)) {
echo "incorrect";
}



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum