Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Old 06-05-2005, 01:27 PM slight problem..
feraira's Avatar
BeTheBand!

Posts: 350
Trades: 0
hey, im having a slight problem with this script im making, its meant to show what messages the user has sent and who to, connect to the message database and pull out the messages which have the users id as the author, then connect to the user database and pull out the information for the name who it is to, doesnt seem to be working tho... i get the error:

Warning: mysql_close(): no MySQL-Link resource supplied in /home/xingeh/public_html/sentmsgs.php on line 38

this is the code i have :
PHP Code:
 <?
 
 $id 
=  $HTTP_COOKIE_VARS['id'];
 
 if(
$_SESSION['username']) {
 
 
mysql_connect("stuff") or die("Could not connect to DB because: ".mysql_error());
 
mysql_select_db("stuff") or die("Could not select the DB because: ".mysql_error());
 
 echo(
"Sent messages:");
 echo(
"<br><br>");
 
 
$query=mysql_query("SELECT * FROM messenger WHERE authorid = '$id' ORDER BY messid DESC");
 
$num=mysql_num_rows($query);
 
$row mysql_fetch_array($query);
 
 
$messid $row['messid'];
 
$messtitle $row['messtitle'];
 
$userid $row['userid'];
 
 
$query2=mysql_query("SELECT * FROM users WHERE id = '$userid'");
 
$row2 mysql_fetch_array($query2);
 
 
$username $row['username'];
 
 if(
$num == 0) {
 echo(
"You havent sent any messages!");
 
 } else {
 
 echo(
"You have sent $num message(s)");
 echo(
"<br><br>");
 
 echo(
"[$messid$messtitle - $username");
 
 
 }}
 
 
mysql_close();
 
?>

Last edited by 0beron; 06-05-2005 at 02:30 PM..
feraira is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 06-05-2005, 11:32 PM
.Mike's Avatar
Novice Talker

Posts: 9
Location: Savannah, GA
Trades: 0
Your code is written as such so that the MySQL connection is created only if $_SESSION['username'] is true, but mysql_close() is called even if $_SESSION['username'] is false.

According to the PHP Manual for mysql_close:

Quote:
If the link identifier is not specified, the last link opened by mysql_connect() is assumed. If no such link is found, it will try to create one as if mysql_connect() was called with no arguments. If by chance no connection is found or established, an E_WARNING level warning is generated.
It seems that if no $_SESSION['username'] is supplied, your script tries to close a non-existent MySQL connection by opening a MySQL connection without using the proper arguments, and the error is thrown.

Try this instead:

Code:
echo("[$messid] $messtitle - $username");

}
mysql_close();
}

?>
.Mike is offline
Reply With Quote
View Public Profile Visit .Mike's homepage!
 
Old 06-06-2005, 01:17 AM
Logical Program's Avatar
Super Talker

Posts: 130
Location: Atlanta, Georgia
Trades: 0
Yeah, take one of the brackets from line 36 and put it AFTER the mysql_close function.
__________________

Please login or register to view this content. Registration is FREE
- For all of your website programming and design needs, make the logical choice. Logical Assistance For Real-World Clients.
Logical Program is offline
Reply With Quote
View Public Profile Visit Logical Program's homepage!
 
Old 06-06-2005, 05:36 AM
feraira's Avatar
BeTheBand!

Posts: 350
Trades: 0
yeah erm.. ive just checked it now, and i found another error i had put $row2...

then $row['username']; ... thats another thing why it wasnt working!

also, i was trying to get it to work last night, and i edited it and kinda lost what i had before, so ive just had to copy this again lol, just up[loaded it, fixed both errors and now i cant log in on my site?
feraira is offline
Reply With Quote
View Public Profile
 
Old 06-06-2005, 05:50 AM
feraira's Avatar
BeTheBand!

Posts: 350
Trades: 0
ok, right thats all sorted. There is one new problem. It only shows one message, not all of them, I have 3, it shows 1, can anyone help with that one?
feraira is offline
Reply With Quote
View Public Profile
 
Old 06-06-2005, 09:50 AM
.Mike's Avatar
Novice Talker

Posts: 9
Location: Savannah, GA
Trades: 0
mysql_fetch_array only pulls one row, not the entire dataset. (link)

You will need to loop through the results for the first query... something like...

Code:
$results = array();
while ($row = mysql_fetch_array($query)){
$results[] = $row;
}
...will put the results of your query into an array called $results.

You will then need to use the loop of your choice to accomplish echoing your results. Something like...
Code:
for($i=0; $i < count($results); $i++)
{
   echo "[" . $results[$i]['messid'] . "] " . $results[$i]['messtitle'] . " - " . $username . "<br />";
}
Untested, of course, but it should put you on the right track as to what sections of the PHP manual to research.

Hope that helps...!

Mike

Last edited by .Mike; 06-06-2005 at 09:54 AM..
.Mike is offline
Reply With Quote
View Public Profile Visit .Mike's homepage!
 
Reply     « Reply to slight problem..
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.31452 seconds with 12 queries