I'm trying to make an If/Else option in the case a database query comes back
with nothing. But when I use the code included below, it always comes back
saying there is no result.
I'm guessing it's because it's asking if there are any results to the query
after it's already finished and the array created.
How can I get it to say basically: If there are no database records fitting
the query, then do this...otherwis e do this?
Thanks!!
Liam
$query_RS_con = "SELECT * FROM $conTBL WHERE $field = \"$item\"";
$RS_con = @mysql_query($q uery_RS_con, $connection) or die("Couldn't query:
" . mysql_error());
while ($row_RS_con = mysql_fetch_arr ay($RS_con)) {
$procid = $row_RS_con['uid'];
$procid2 = $row_RS_con['id'];
$procpass = $row_RS_con['cont_password'];
}
if (!($row_RS_con) ) {
$statusmsg = "Your Username was not found. Please go back and try
again.<br><br>< A HREF='javascrip t:history.go(-1)'>Click Here to go back and
try again.</a><br>(You may need to click the ACCESS menu option
twice.)<br>";
} else {
if (($pass1) == ($procpass)) {
header("Locatio n:
http://www.url.org/contact/change.php?uid= $procid$procid2 ");
} else {
$statusmsg = "Your Password did not match your Username. Please go back
and try again.<br><br>< A HREF='javascrip t:history.go(-1)'>Click Here to go
back and try again.</a><br>(You may need to click the ACCESS menu option
twice.)<br>";
}
}
with nothing. But when I use the code included below, it always comes back
saying there is no result.
I'm guessing it's because it's asking if there are any results to the query
after it's already finished and the array created.
How can I get it to say basically: If there are no database records fitting
the query, then do this...otherwis e do this?
Thanks!!
Liam
$query_RS_con = "SELECT * FROM $conTBL WHERE $field = \"$item\"";
$RS_con = @mysql_query($q uery_RS_con, $connection) or die("Couldn't query:
" . mysql_error());
while ($row_RS_con = mysql_fetch_arr ay($RS_con)) {
$procid = $row_RS_con['uid'];
$procid2 = $row_RS_con['id'];
$procpass = $row_RS_con['cont_password'];
}
if (!($row_RS_con) ) {
$statusmsg = "Your Username was not found. Please go back and try
again.<br><br>< A HREF='javascrip t:history.go(-1)'>Click Here to go back and
try again.</a><br>(You may need to click the ACCESS menu option
twice.)<br>";
} else {
if (($pass1) == ($procpass)) {
header("Locatio n:
http://www.url.org/contact/change.php?uid= $procid$procid2 ");
} else {
$statusmsg = "Your Password did not match your Username. Please go back
and try again.<br><br>< A HREF='javascrip t:history.go(-1)'>Click Here to go
back and try again.</a><br>(You may need to click the ACCESS menu option
twice.)<br>";
}
}
Comment