FinalFrontier Posted December 15, 2011 Share Posted December 15, 2011 I just wrote this small piece of code and not getting a result from it and wonder if someone could shed some light. $query = "SELECT * FROM orders WHERE customeremail = '".mysql_real_escape_string($_POST['customere-mail'])."'"; $result = mysql_query($query); $row = mysql_fetch_array($result); mysql_query ($query); if ($row['customeremail'] != "") { foreach ($row['id'] as $whatever) { echo "lol"; } } I have two $row['id']'s, yet I am not getting any lols. Does anyone know why? Quote Link to comment https://forums.phpfreaks.com/topic/253208-im-not-laughing/ Share on other sites More sharing options...
Shazer2 Posted December 15, 2011 Share Posted December 15, 2011 $cemail = mysql_real_escape_string($_POST['customere-email']); $query = "SELECT * FROM orders WHERE customeremail = '{$cemail}'"; $result = mysql_query($query); while ($row = mysql_fetch_array($result)) { if ($row['customeremail'] != "") { foreach ($row['id'] as $whatever) { echo "lol"; } } } Try that code. Untested, but should work. Quote Link to comment https://forums.phpfreaks.com/topic/253208-im-not-laughing/#findComment-1298045 Share on other sites More sharing options...
FinalFrontier Posted December 15, 2011 Author Share Posted December 15, 2011 Thanks for trying dude, but it didn't help. Quote Link to comment https://forums.phpfreaks.com/topic/253208-im-not-laughing/#findComment-1298046 Share on other sites More sharing options...
Shazer2 Posted December 15, 2011 Share Posted December 15, 2011 Actually, why do you need the foreach, the while loop loops through it all anyway. Quote Link to comment https://forums.phpfreaks.com/topic/253208-im-not-laughing/#findComment-1298047 Share on other sites More sharing options...
FinalFrontier Posted December 15, 2011 Author Share Posted December 15, 2011 Does it? I don't know. I just checked my error log: Invalid argument supplied for foreach() Quote Link to comment https://forums.phpfreaks.com/topic/253208-im-not-laughing/#findComment-1298048 Share on other sites More sharing options...
FinalFrontier Posted December 15, 2011 Author Share Posted December 15, 2011 So, I tried your suggestion, but still got the same result. $query = "SELECT * FROM orders WHERE customeremail = '".mysql_real_escape_string($_POST['customere-mail'])."'"; $result = mysql_query($query); $row = mysql_fetch_array($result); mysql_query ($query); if ($row['customeremail'] != "") { while (mysql_fetch_array($result)) { echo "lol"; } } Quote Link to comment https://forums.phpfreaks.com/topic/253208-im-not-laughing/#findComment-1298050 Share on other sites More sharing options...
FinalFrontier Posted December 15, 2011 Author Share Posted December 15, 2011 Thanks for the effort, but it seems a real long way round. What I've done is echo these with > the results: $row > Array $result > Resource id #3 So, it seems something is up with the actual MySQL query. I will investigate some more.. Quote Link to comment https://forums.phpfreaks.com/topic/253208-im-not-laughing/#findComment-1298077 Share on other sites More sharing options...
FinalFrontier Posted December 15, 2011 Author Share Posted December 15, 2011 This is beyond a fricken joke!!!!!! Ok, here is the code. And a friendly note. Please don't criticize my 'inefficiency' of code. I really don't care right now and all it does is frustrate me. I won't respond to critisizsm that is not in relation to this problem. I am just trying to find out why this isn't working. Here is the full source code of the entire page and the problem is at line 6. The problem is that "LOL" is not echoing. If I remove the while() the $row echo's fine. But why isn't it working in a while() string?: <?php session_start(); $link = mysql_connect('localhost', 'testusr', 'testpw'); mysql_select_db('testdb', $link); $query = "SELECT * FROM orders WHERE customeremail = '".mysql_real_escape_string($_POST['customere-mail'])."'"; $result = mysql_query($query); $row = mysql_fetch_array($result); mysql_query ($query); if ($row['customeremail'] != "") { while (mysql_fetch_array($result)) { echo "LOL"; } $subject = "Lay-by password recovery"; if ($row['customertitle'] != "") { $customer = $row['customertitle']." ".$row['customerlastname']; } else { $customer = $row['customerfirstname']; } $body = " Dear ".$customer." I received a request from the IP address ".$_SERVER['SERVER_ADDR']." for lay-by access recovery on your lay-by. Your lay-by access information: ".$accessinformation." Kind regards,"; $header = 'From: A B <[email protected]>'; // mail($_POST['customere-mail'], $subject, $body, $header); $result = ' <FORM action="../" style="left: 50%; margin-left: -22px; margin-top: -5px; position: absolute; text-align: center; top: 50%"> <DIV> Done. <BR> <BR> <INPUT class="verdana" type="submit" value="OK"> </DIV> </FORM> '; } else { $result = ' <FORM action="../" style="left: 50%; margin-left: -160px; margin-top: -5px; position: absolute; text-align: center; top: 50%"> <DIV> '.$_POST['customere-mail'].' was not found in the lay-by database. <BR> <BR> <INPUT class="verdana" type="submit" value="OK"> </DIV> </FORM> '; } ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <TITLE>My Site</TITLE> <META content="charset=windows-1252;text/html" http-equiv="content-type"> <LINK href="../../css/body.css" rel="stylesheet" type="text/css"> <STYLE type="text/css"> A.gold { color: rgb(255,215,0) } DIV.path { left: 50%; margin-left: -565px; margin-top: -266px; position: absolute; top: 50% } </STYLE> <DIV> <IMG alt="" class="logo" src="../../images/structural/logo.png"> <DIV class="customermenu"><?php include '../../rawcode/menus/customermenu/payofflay-by'; ?></DIV> <DIV class="mainmenu"><?php include '../../rawcode/menus/mainmenu/mainmenu'; ?></DIV> <DIV class="topseparator"></DIV> <DIV class="path">> <A class="gold" href="../../">Payoff lay-by</A> > <A class="gold" href="../accessrecovery">Access recovery</A> > Result</DIV> <?php echo $result; ?> <DIV class="bottomseparator"></DIV> <DIV class="informationmenu"><?php include '../../rawcode/menus/information/information'; ?></DIV> <DIV class="copyright"><?php include '../../rawcode/menus/copyright/acopyright'; ?></DIV> </DIV> Quote Link to comment https://forums.phpfreaks.com/topic/253208-im-not-laughing/#findComment-1298092 Share on other sites More sharing options...
FinalFrontier Posted December 15, 2011 Author Share Posted December 15, 2011 Problem solved: $query = "SELECT * FROM orders WHERE customeremail = '".mysql_real_escape_string($_POST['customere-mail'])."'"; $result = mysql_query($query); mysql_query ($query); while ($row = mysql_fetch_array($result)) { echo "LOL"; } $query = "SELECT * FROM orders WHERE customeremail = '".mysql_real_escape_string($_POST['customere-mail'])."'"; $result = mysql_query($query); $row = mysql_fetch_array($result); mysql_query ($query); if ($row['customeremail'] != "") { Quote Link to comment https://forums.phpfreaks.com/topic/253208-im-not-laughing/#findComment-1298109 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.