Jump to content

Variable association warning


nacunis

Recommended Posts

I get this message with the code at the bottom:

 

PHP Warning:  mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home1/acunishi/public_html/go/auth/birthdays_holidays-greetings.php on line 35

session_start();
$connection=mysql_connect("localhost","database username","db user password");
$db=mysql_select_db("database name",$connection );
$users_table = 'table name';

$username = $_POST['myusername'];

$result3 = mysql_query("SELECT `nickname` from `databasename`.`tablename` WHERE `loginsv4_md5`.`username` = '$myusername'");
$result4 = mysql_query("SELECT `lastlogin` from `databasename'.'tablename` WHERE `tablename`.`username` = '$myusername'");
$result5 = mysql_query("SELECT `announce` from `databasename`.`tablename` WHERE `tablename`.`username` = '$myusername'");
$num_rows = mysql_num_rows($result3);
$row3 = mysql_fetch_assoc($result3);
while ($row3 = mysql_fetch_assoc($result3))
{
echo " \n <br>";
echo $row3['nickname'];
echo "  ";
echo " \n";
}
$row5 = mysql_fetch_assoc($result5);
while ($row5 = mysql_fetch_assoc($result5))
{
echo $row5['announce'];
echo "  ";
}
$row4 = mysql_fetch_assoc($result4);
while ($row4 = mysql_fetch_assoc($result4))
{
echo $row4['lastlogin'];
echo "  ";
}
..... code not displayed

 

Error message seems to point to mysql_fetch_assoc.

 

Other pieces of this code are being executed, so I know the module is called and executing, and of course, there is the PHP warning message from the log.  Please help

Link to comment
Share on other sites

looks to me like you accidently placed single quotes where backticks are needed...try this

$result4 = mysql_query("SELECT `lastlogin` from `databasename`.`tablename` WHERE `tablename`.`username` = '$myusername'");

Link to comment
Share on other sites

Why are you performing three queries on the same table and only fetching one field at a time? MySQL can fetch more than one field per query.

Also if your query is only going to return one result you do not need to use a while loop.

 

As for the error you need to check whether your queries are returning any errors. You can do this using mysql_error

Link to comment
Share on other sites

To responder 1, thank you.  It didn't work because the actual code had a backtick.  Oh well. 8)8)8)8)

 

As for responder 2, that code came from a PHP programmer (not me) and it worked.  So the question about why I did it that way and not another way was not helpful for me.  :(:(:(:(:(:(:(:(:(    I wouldn't call myself a PHP programmer at all.

 

If the forum results in people debating code rather than being helpful, I'll drop my association with this forum.  Again, thanks to responder 1.  At least you tried to help rather than debate. 8)8)8)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.