Jump to content

Archived

This topic is now archived and is closed to further replies.

aebstract

error :(

Recommended Posts

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/.jaguar/onelastromance/carbenco.com/beta/pmbox.php on line 127... grrrr, these stupid errors are making me mad cause I don't know what the hell is wrong :(


Anyway, heres the code:


[code]
<?php  
session_start();
header("Cache-control: private");  
if(!isset($_SESSION["id"]))  
{  
header("Location: index.php?menu=mustlogin");  
}

















if($action == compose){
$content .= '<div id="pmbox">';


if (isset ($_POST['submit'])) {
$problem = FALSE;  
$_POST['reciever'] = strip_tags($_POST['reciever']);
$_POST['subject'] = strip_tags($_POST['subject']);
$_POST['message'] = strip_tags($_POST['message']);  

if (empty ($_POST['reciever'])) {
$problem = TRUE; $content .= 'Reciever is a required field<br />';
}  

if (empty ($_POST['subject'])) {
$problem = TRUE;
$content .= 'Subject is a required field<br />';
}  

if (empty ($_POST['message'])) {
$problem = TRUE;
$content .= 'Message is a required field<br />';
}  

$query = mysql_query("SELECT id FROM accounts WHERE username = '".$_POST['reciever']."'");
$query = mysql_fetch_array($query);         
if ($query){     
$recieverid = $query['id'];                  

} else {         

$problem = TRUE;         
$content .= 'Invalid Username<br />';

}  
if (!$problem) {  
$reciever = $_POST['reciever'];
$subject = $_POST['subject'];
$message = $_POST['message'];
$datesent = date('F j, Y - g:i a');  

$insert = mysql_query("INSERT INTO pmbox (recieverid,sender,senderid,message,subject,datesent,read)".
"VALUES ('$recieverid', '$username', '$id', '$message', '$subject', '$datesent', '0')");


header ("Location: index.php?menu=pmbox&action=pmsent");  
} else {
$content .= '<br />';
}
}    
$content .= '
  
<form action="index.php?menu=pmbox&action=compose" method="post">  
Reciever: <br />
<input type="text" maxlength="14" class="textfield" name="reciever" size="20" value="' . $_POST['reciever'] . '" />
<br />
Subject: <br />
<input type="text" class="textfield" name="subject" maxlength="15" size="20" value="' . $_POST['subject'] . '" />
<br />
Message: <br /><textarea class="textfield" name="message" rows="10" cols="40" value="' . $_POST['message'] . '"></textarea>
<br /><br />  
<input type="submit" name="submit" value="Send PM" class="textfield" />
</form>  

';



$content .= '</div>';























} elseif ($action == read){
$content .= '<div id="pmbox">



<table><tr id="trone"><td id="tdone">From:</td><td id="tdtwo">Subject:</td><td id="tdthree">Date:</td></tr>

';

$result = mysql_query("SELECT * FROM pmbox WHERE recieverid = '$id' && $pmid = '$mail'");    
while($r=mysql_fetch_array($result)) {  
$sender=$r["sender"];  
$senderid=$r["senderid"];  
$message=$r["message"];  
$subject=$r["subject"];
$datesent=$r["datesent"];
$pmid=$r["pmid"];  
$content .= "

<tr id=trtwo><td>$message</td></tr>


";
}




$content .= '</table></div>';























} elseif ($action == sentmail){

$content .= '
<div id="pmbox">
sent mail
</div>
';

























} else {
$content .= '<div id="pmbox">
<table><tr id="trone"><td id="tdone">From:</td><td id="tdtwo">Subject:</td><td id="tdthree">Date:</td></tr>

';

$result = mysql_query("SELECT * FROM pmbox WHERE recieverid = '$id'");    
while($r=mysql_fetch_array($result))  {  
$sender=$r["sender"];  
$senderid=$r["senderid"];  
$message=$r["message"];  
$subject=$r["subject"];
$datesent=$r["datesent"];
$pmid=$r["pmid"];  
$content .= "

<tr id=trtwo><td id=tdone><a href=index.php?menu=profileview&user=$senderid>$sender</a></td><td id=tdtwo><a href=index.php?menu=pmbox&action=read&mail=$pmid>$subject</a></td><td id=tdthree>$datesent</td></tr>


";
}

$content .= "</table></div>";
}



?>
[/code]

Share this post


Link to post
Share on other sites
[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--] these stupid errors are making me mad cause I don't know what the hell is wrong :([/quote]
Precisely.

I have no idea which of your statements is causing the error because you gave no clue as to which is line 127. You'll make life a lot simpler for yourself if you structure your query definitions and queries so they produce helpful error messages. For example:
[code]$query = "SELECT * from tablename WHERE column = '$somevalue'";
$result = mysql_query($query) or die("Error: ". mysql_error(). " with query ". $query);[/code]
Not only will that tell you what error you have, it will also tell you what the query [b]really[/b] was not what you hope it was. 99 times out of 100, using that method will point you straight towards a solution.

Share this post


Link to post
Share on other sites
[code]
$result = mysql_query("SELECT * FROM pmbox WHERE recieverid = '$id' && $pmid = '$mail'");    
while($r=mysql_fetch_array($result)) {  
$sender=$r["sender"];  
$senderid=$r["senderid"];  
$message=$r["message"];  
$subject=$r["subject"];
$datesent=$r["datesent"];
$pmid=$r["pmid"];  
$content .= "

<tr id=trtwo><td>$message</td></tr>


";
}
[/code]

$sender=$r["sender"]; is 127

Share this post


Link to post
Share on other sites
Uh huh ... and what was the error message and the exact query. I'm not asking what query did you code (expect), I'm suggesting you actually echo the query that was used, which is what the code example I gave would have produced. Where does $id come from in your example?

One of the reasons why it's so useful when debugging to see the [b]actual[/b] query used, is that you can paste that precise query right into something like phpMyAdmin and see just how it works (or fails).

Share this post


Link to post
Share on other sites
Error: Query was empty with query

$id comes from my connect.php file,

[code]
<?php
mysql_connect("mysql.carbenco.com","onelastromance","147258");
mysql_select_db("onelastromance");

$id = $_SESSION["id"];
$result = mysql_query("SELECT * FROM accounts WHERE id='$id'");

while($r=mysql_fetch_array($result))
{

$id=$r["id"];
$password=$r["password"];
$email=$r["email"];
$emailshow=$r["emailshow"];
$firstname=$r["firstname"];
$lastname=$r["lastname"];
$registerdate=$r["registerdate"];
$username=$r["username"];
$memlvl=$r["memlvl"];

}
?>[/code]
which is included in the index.php file,

Share this post


Link to post
Share on other sites
what you mean its not in this code?
$id=$r["id"];
its right there? in the connect.php file which is included in the index file.

Share this post


Link to post
Share on other sites
$id = $_SESSION["id"];
is this set?
try echoing the query

$sql = "SELECT * FROM accounts WHERE id='$id'";
$result = mysql_query($sql) or die (mysql_error ()."<br>"sql: ".$sql);

Share this post


Link to post
Share on other sites
Yes, it is set. I put the variable $id in another spot on the page that displays text and the correct id number shows up. Anyone have a [i]solution[/i]?

Share this post


Link to post
Share on other sites
try echoing the query

$sql = "SELECT * FROM accounts WHERE id='$id'";
$result = mysql_query($sql) or die (mysql_error ()."<br>"sql: ".$sql);

do this and get the error and query

Share this post


Link to post
Share on other sites
[!--quoteo(post=384801:date=Jun 16 2006, 06:48 PM:name=joquius)--][div class=\'quotetop\']QUOTE(joquius @ Jun 16 2006, 06:48 PM) [snapback]384801[/snapback][/div][div class=\'quotemain\'][!--quotec--]
try echoing the query

$sql = "SELECT * FROM accounts WHERE id='$id'";
$result = mysql_query($sql) or die (mysql_error ()."<br>"sql: ".$sql);

do this and get the error and query
[/quote]
That advice has already been provided in this thread, but ...

[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]Error: Query was empty with query [/quote]

Sigh! I bet if you [b]echo the query[/b] the solution will be obvious.

Share this post


Link to post
Share on other sites
if $id comes from a SESSION variable, where's the session_start() line in this code?

Share this post


Link to post
Share on other sites
line 2? not in any code you've posted or told anyone about so it seemed a reasonable question.

I'll ask one more time. What is the exact query that's used that results in the error message you reported? It seems pretty obvious that the root of the problem lies with your query. Until you [b]show the actual query used[/b], there isn't much more anyone can do.

Share this post


Link to post
Share on other sites
session_start() line 2 of the very first code i posted, please look before telling me you can not see it.

you want the coding or the little error message that your code produces? cause I put your code in and it didnt work the way you wanted it to i guess, since I couldn't figure out how or w/e. If you want the code that is being run, I have already told you this several times:

[code]} elseif ($action == read){
$content .= '<div id="pmbox">



<table><tr id="trone"><td id="tdone">From:</td><td id="tdtwo">Subject:</td><td id="tdthree">Date:</td></tr>

';


$result = mysql_query("SELECT * FROM pmbox WHERE recieverid = '$id' && $pmid = '$mail'");    

while($r=mysql_fetch_array($result)) {  
$sender=$r["sender"];  
$senderid=$r["senderid"];  
$message=$r["message"];  
$subject=$r["subject"];
$datesent=$r["datesent"];
$pmid=$r["pmid"];  

$content .= "

<tr id=trtwo><td>$message</td></tr>


";
}




$content .= '</table></div>';























} elseif ($act........[/code]

Share this post


Link to post
Share on other sites
dude don't take this the wrong way but you come here asking for help and you're being rude about it. And on top of that, you aren't even doing what people are asking you to try. Remember, you came here for help cuz you can't figure it out. So don't assume people don't know what they are talking about (and responding as such).

none of your queries show .. or die(mysql_error()); which several people told you to tack on to the end of your query and paste the result. You have not posted the query that is generating the error. You've just posted a big block of code.

invalid mysql result resource means that your query is somehow messed up. instead of doing this:
[code]
$result = mysql_query("SELECT * FROM pmbox WHERE recieverid = '$id' && $pmid = '$mail'");    
[/code]
do this:
[code]
$sql = "SELECT * FROM pmbox WHERE recieverid = '$id' && $pmid = '$mail'";    
echo $sql;
$result = mysql_query($sql) or die(mysql_error());
[/code]
this will help narrow down your problem, as you will be able to see the exact query string being sent to mysql (echo $sql;) and the error message that generates from it (the .. or die() part). You can also c/p the echoe'd $sql directly into phpmyadmin and run it through there.

it could be many things. you could have a misspelled/nonexistent table/column. your vars might not be going through. your connection might not even be establish.

try to show some patience with the people that are trying to help you, as they have been showing you a great deal themselves.

Share this post


Link to post
Share on other sites
im sorry if I seemed rude, I didn't mean to, but session_start [i]was[/i] right at the beginning and the code he kept telling me to put in didn't make sense of where or how to use it. Thanks for explaining it and whatnot, the error that it gave me was:

SELECT * FROM pmbox WHERE recieverid = '1' && = '1'You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '= '1'' at line 1

I figured out the problem since && ='1' the $pmid was showing nothing, needed to take the $ off. I am sorry and thank you a lot for the help.

Share this post


Link to post
Share on other sites
Ta da!

The error message that displays the query triumphs :)

Honestly, it's a great coding habit to adopt.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.