Gibbs Posted January 17, 2007 Share Posted January 17, 2007 I have a basic Private Message system working on my site. However i'm having problems with PHP getting the mail_id information from MySQL.If I do this I can get the mail ID:[code]$result=mysql_query("select * from $table where UserTo='$cookie' ORDER BY SentDate DESC") or die ("ERROR: PLEASE REPORT THIS");while ($row=mysql_fetch_array($result)) {echo $row[mail_id];[/code]However i'm trying to get the mail_id in a different part and am finding it difficult. When somebody selects a link this is used:[code]$result =mysql_query("select * from $table where UserTo='$cookie' and mail_id='[mail_id]'") or die ("cant do it1");//echo mysql_num_rows($result);$row = mysql_fetch_array($result);if($row[UserTo]==$cookie) [/code]However the mail_id isn't recognised like previously. Is there a way to use the code at the top to get the mail_id to work here?Any help appreciated. Thanks Link to comment https://forums.phpfreaks.com/topic/34561-phpmysql-need-help-getting-variable/ Share on other sites More sharing options...
paul2463 Posted January 17, 2007 Share Posted January 17, 2007 if you are pulling the mail_id from the first query and using it in the second query then you have to assign it to a variable and use it that way such as[code]<?php$result=mysql_query("select * from $table where UserTo='$cookie' ORDER BY SentDate DESC") or die ("ERROR: PLEASE REPORT THIS");$row=mysql_fetch_array($result); $mailId = $row[mail_id];$result =mysql_query("select * from $table where UserTo='$cookie' and mail_id='$mailId'") or die ("cant do it1");//echo mysql_num_rows($result);$row = mysql_fetch_array($result);if($row[UserTo]==$cookie) ?>[/code] Link to comment https://forums.phpfreaks.com/topic/34561-phpmysql-need-help-getting-variable/#findComment-162774 Share on other sites More sharing options...
Gibbs Posted January 17, 2007 Author Share Posted January 17, 2007 I'm still confused. I've tried this (i'll post the entire part as it may make more sense).[code=php:0]$result=mysql_query("select * from $table where UserTo='$cookie' ORDER BY SentDate DESC") or die ("ERROR: PLEASE REPORT THIS");echo "<table cellpadding=2 cellspacing=1 width=400 valign=top>";$row = mysql_fetch_array($result);$messageid = $row[mail_id]; // mail_idwhile ($row=mysql_fetch_array($result)) {echo "<tr><td width=30><p>Mail:</td><td><a href=pm.php?action=view&mail_id=$row[mail_id]>$row[Subject]</a></td><td width=50> <a href=pm.php?action=delete&id=$row[mail_id]><center>Delete</a><br></td></tr>";}echo "</table>";}if($action==view) {$result = mysql_query("select * from $table where UserTo='$cookie' and mail_id='$messageid'") or die ("cant do it1");$row = mysql_fetch_array($result);if($row[UserTo]==$cookie) {} else {echo "<p class=\"error\"><b>This isn't your mail!</b></p>" .$row;exit;[/code] Link to comment https://forums.phpfreaks.com/topic/34561-phpmysql-need-help-getting-variable/#findComment-162785 Share on other sites More sharing options...
paul2463 Posted January 17, 2007 Share Posted January 17, 2007 so if they click on view they are sent away and back to this page by the [code]<?phpecho "<tr><td width=30><p>Mail:</td><td><a href=pm.php?action=view&mail_id=$row[mail_id]>$row[Subject]</a></td><td width=50> <a href=pm.php?action=delete&id=$row[mail_id]><center>Delete</a><br></td></tr>";?>[/code]then you can use the mail_id in the url for the second queryyou would need[code]<?phpif($action==view) {if(isset($_GET['mail_id'])) { $mailId = $_GET['mail_id']; }$result = mysql_query("select * from $table where UserTo='$cookie' and mail_id='$mailId'") or die ("cant do it1");$row = mysql_fetch_array($result);if($row[UserTo]!=$cookie) {echo "<p class=\"error\"><b>This isn't your mail!</b></p>" .$row;exit;}?>[/code] Link to comment https://forums.phpfreaks.com/topic/34561-phpmysql-need-help-getting-variable/#findComment-162798 Share on other sites More sharing options...
paul2463 Posted January 17, 2007 Share Posted January 17, 2007 are you also getting the $action variable set from the URL??such as[code]if(isset($_GET['action'])) { $action = $_GET['action']; }if ($action = "view"){blah[/code] Link to comment https://forums.phpfreaks.com/topic/34561-phpmysql-need-help-getting-variable/#findComment-162803 Share on other sites More sharing options...
Gibbs Posted January 17, 2007 Author Share Posted January 17, 2007 It's all done in the same page. I'm getting action using[code=php:0]<?php$action = $_GET['action'];[/code] Link to comment https://forums.phpfreaks.com/topic/34561-phpmysql-need-help-getting-variable/#findComment-162808 Share on other sites More sharing options...
paul2463 Posted January 17, 2007 Share Posted January 17, 2007 then you can get the mail_id for the second bit by the same method as you pass the mail_id in the URL as well<php$mailId = $_GET['mail_id'];?>then use that in the query Link to comment https://forums.phpfreaks.com/topic/34561-phpmysql-need-help-getting-variable/#findComment-162818 Share on other sites More sharing options...
Gibbs Posted January 17, 2007 Author Share Posted January 17, 2007 So simple! I can't believe that ::)Thanks for your help! :P Link to comment https://forums.phpfreaks.com/topic/34561-phpmysql-need-help-getting-variable/#findComment-162823 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.