timmah1 Posted January 13, 2007 Share Posted January 13, 2007 I'm getting no results from this statement, even though the variables are being passed.[code]if ( $_GET["op"] == "view" ){include "dbConfig.php";$q=mysql_query("select * from mail where UserTo='$_SESSION[valid_user]' AND mail_id='&id'") or die ("Cannot View This Message");while ($row=mysql_fetch_array($q)){echo "$row[mail_id]";}}[/code]Can someone explain to me why?Thanks Link to comment https://forums.phpfreaks.com/topic/33989-mysql-no-results-why/ Share on other sites More sharing options...
timmah1 Posted January 13, 2007 Author Share Posted January 13, 2007 ok, I tried to modify this post, but it won't allow meI already fixed the query at the [code]mail_id='&id'[/code] to [code]mail_id='$id'[/code] Link to comment https://forums.phpfreaks.com/topic/33989-mysql-no-results-why/#findComment-159729 Share on other sites More sharing options...
trq Posted January 13, 2007 Share Posted January 13, 2007 So its working now? Link to comment https://forums.phpfreaks.com/topic/33989-mysql-no-results-why/#findComment-159732 Share on other sites More sharing options...
timmah1 Posted January 13, 2007 Author Share Posted January 13, 2007 no it's not, I get no results Link to comment https://forums.phpfreaks.com/topic/33989-mysql-no-results-why/#findComment-159733 Share on other sites More sharing options...
trq Posted January 13, 2007 Share Posted January 13, 2007 You dont have any call to session_start(). Also, complex variables (arrays) need to be surrounded by curly braces when within quotes, variables do NOT need to be within quotes and check your queries before trying to use there results.[code]<?phpsession_start();if (isset($_GET['op'])) { if ( $_GET['op'] == 'view' ) { include "dbConfig.php"; if ($result = mysql_query("select * from mail where UserTo='{$_SESSION['valid_user']}' AND mail_id = '$id'")) { if (mysql_num_rows($result)) { while ($row = mysql_fetch_array($result)) { echo $row['mail_id'].'<br />'; } } else { echo 'No results found'; } } else { echo mysql_error(); } }}?>Next. Where is $id comming from? Also, if your only expecting one result you do not need a while() loop.[/code] Link to comment https://forums.phpfreaks.com/topic/33989-mysql-no-results-why/#findComment-159736 Share on other sites More sharing options...
timmah1 Posted January 13, 2007 Author Share Posted January 13, 2007 the $id is being called from this[code]<a href=myaccount.php?op=view&UserTo=$_SESSION[valid_user]&id=$row[mail_id]>$row[Subject]</a>[/code]I'm not expecting just one result, i just put one in to test it Link to comment https://forums.phpfreaks.com/topic/33989-mysql-no-results-why/#findComment-159738 Share on other sites More sharing options...
trq Posted January 13, 2007 Share Posted January 13, 2007 [code]<?phpsession_start();if (isset($_GET['op']) && isset($_GET['id'])) { if ( $_GET['op'] == 'view' ) { include "dbConfig.php"; if ($result = mysql_query("select * from mail where UserTo='{$_SESSION['valid_user']}' AND mail_id = '{$_GET['id']}'")) { if (mysql_num_rows($result)) { while ($row = mysql_fetch_array($result)) { echo $row['mail_id'].'<br />'; } } else { echo 'No results found'; } } else { echo mysql_error(); } }}?>[/code] Link to comment https://forums.phpfreaks.com/topic/33989-mysql-no-results-why/#findComment-159739 Share on other sites More sharing options...
trq Posted January 13, 2007 Share Posted January 13, 2007 Actually, you might need to switch these lines around...[code=php:0]if (isset($_GET['op']) && isset($_GET['id'])) { if ( $_GET['op'] == 'view' ) {[/code]to...[code=php:0]if ($_GET['op'] == 'view')) { if (isset($_GET['op']) && isset($_GET['id'])) {[/code]should make it alittle less problematic. Link to comment https://forums.phpfreaks.com/topic/33989-mysql-no-results-why/#findComment-159743 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.