Jump to content


Photo

error :(


  • Please log in to reply
18 replies to this topic

#1 aebstract

aebstract
  • Members
  • PipPipPip
  • Advanced Member
  • 1,105 posts

Posted 16 June 2006 - 08:39 PM

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:


<?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>";
}



?>

There is an area of the mind that could be called unsane, beyond sanity, and yet
not insane. Think of a circle with a fine split in it. At one end there's
insanity. You go around the circle to sanity, and on the other end of the
circle, close to insanity, but not insanity, is unsanity.


#2 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 16 June 2006 - 09:31 PM

[!--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:
$query = "SELECT * from tablename WHERE column = '$somevalue'";
$result = mysql_query($query) or die("Error: ". mysql_error(). " with query ". $query);
Not only will that tell you what error you have, it will also tell you what the query really was not what you hope it was. 99 times out of 100, using that method will point you straight towards a solution.
Legend has it that reading the manual never killed anyone.
My site

#3 aebstract

aebstract
  • Members
  • PipPipPip
  • Advanced Member
  • 1,105 posts

Posted 16 June 2006 - 09:49 PM

$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>


";
}

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

There is an area of the mind that could be called unsane, beyond sanity, and yet
not insane. Think of a circle with a fine split in it. At one end there's
insanity. You go around the circle to sanity, and on the other end of the
circle, close to insanity, but not insanity, is unsanity.


#4 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 16 June 2006 - 09:57 PM

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 actual query used, is that you can paste that precise query right into something like phpMyAdmin and see just how it works (or fails).
Legend has it that reading the manual never killed anyone.
My site

#5 aebstract

aebstract
  • Members
  • PipPipPip
  • Advanced Member
  • 1,105 posts

Posted 16 June 2006 - 10:11 PM

Error: Query was empty with query

$id comes from my connect.php file,

<?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"];

}
?>
which is included in the index.php file,

There is an area of the mind that could be called unsane, beyond sanity, and yet
not insane. Think of a circle with a fine split in it. At one end there's
insanity. You go around the circle to sanity, and on the other end of the
circle, close to insanity, but not insanity, is unsanity.


#6 joquius

joquius
  • Members
  • PipPipPip
  • Advanced Member
  • 319 posts

Posted 16 June 2006 - 10:15 PM

ok so your problem is the $id or the db, with is not in this code
z..z..z..z..z..z..z..z..

#7 aebstract

aebstract
  • Members
  • PipPipPip
  • Advanced Member
  • 1,105 posts

Posted 16 June 2006 - 10:18 PM

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.

There is an area of the mind that could be called unsane, beyond sanity, and yet
not insane. Think of a circle with a fine split in it. At one end there's
insanity. You go around the circle to sanity, and on the other end of the
circle, close to insanity, but not insanity, is unsanity.


#8 joquius

joquius
  • Members
  • PipPipPip
  • Advanced Member
  • 319 posts

Posted 16 June 2006 - 10:22 PM

$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);
z..z..z..z..z..z..z..z..

#9 aebstract

aebstract
  • Members
  • PipPipPip
  • Advanced Member
  • 1,105 posts

Posted 16 June 2006 - 10:47 PM

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 solution?

There is an area of the mind that could be called unsane, beyond sanity, and yet
not insane. Think of a circle with a fine split in it. At one end there's
insanity. You go around the circle to sanity, and on the other end of the
circle, close to insanity, but not insanity, is unsanity.


#10 joquius

joquius
  • Members
  • PipPipPip
  • Advanced Member
  • 319 posts

Posted 16 June 2006 - 10:48 PM

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
z..z..z..z..z..z..z..z..

#11 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 16 June 2006 - 10:50 PM

[!--quoteo(post=384801:date=Jun 16 2006, 06:48 PM:name=joquius)--][div class=\'quotetop\']QUOTE(joquius @ Jun 16 2006, 06:48 PM) View Post[/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 echo the query the solution will be obvious.
Legend has it that reading the manual never killed anyone.
My site

#12 joquius

joquius
  • Members
  • PipPipPip
  • Advanced Member
  • 319 posts

Posted 16 June 2006 - 10:52 PM

I know but there's no movement on it.
z..z..z..z..z..z..z..z..

#13 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 16 June 2006 - 10:54 PM

if $id comes from a SESSION variable, where's the session_start() line in this code?
Legend has it that reading the manual never killed anyone.
My site

#14 aebstract

aebstract
  • Members
  • PipPipPip
  • Advanced Member
  • 1,105 posts

Posted 16 June 2006 - 11:13 PM

session_start() = line 2? -.-

There is an area of the mind that could be called unsane, beyond sanity, and yet
not insane. Think of a circle with a fine split in it. At one end there's
insanity. You go around the circle to sanity, and on the other end of the
circle, close to insanity, but not insanity, is unsanity.


#15 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 16 June 2006 - 11:20 PM

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 show the actual query used, there isn't much more anyone can do.
Legend has it that reading the manual never killed anyone.
My site

#16 aebstract

aebstract
  • Members
  • PipPipPip
  • Advanced Member
  • 1,105 posts

Posted 16 June 2006 - 11:32 PM

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:

} 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........

There is an area of the mind that could be called unsane, beyond sanity, and yet
not insane. Think of a circle with a fine split in it. At one end there's
insanity. You go around the circle to sanity, and on the other end of the
circle, close to insanity, but not insanity, is unsanity.


#17 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 16 June 2006 - 11:49 PM

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:
$result = mysql_query("SELECT * FROM pmbox WHERE recieverid = '$id' && $pmid = '$mail'");    
do this:
$sql = "SELECT * FROM pmbox WHERE recieverid = '$id' && $pmid = '$mail'";    
echo $sql;
$result = mysql_query($sql) or die(mysql_error());
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.
Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#18 aebstract

aebstract
  • Members
  • PipPipPip
  • Advanced Member
  • 1,105 posts

Posted 17 June 2006 - 12:09 AM

im sorry if I seemed rude, I didn't mean to, but session_start was 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.

There is an area of the mind that could be called unsane, beyond sanity, and yet
not insane. Think of a circle with a fine split in it. At one end there's
insanity. You go around the circle to sanity, and on the other end of the
circle, close to insanity, but not insanity, is unsanity.


#19 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 17 June 2006 - 12:09 AM

Ta da!

The error message that displays the query triumphs :)

Honestly, it's a great coding habit to adopt.
Legend has it that reading the manual never killed anyone.
My site




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users