Jump to content

Recommended Posts

Site uses php and mysql.

 

I have an avatar system where certain avatars are locked until the user unlocks them by going to certain pages of the site.

 

So far ( being the newb I am ) I only know how to INSERT data from a form. Is there a way to do it on page load or similar?

 

I also need it to first check if the data already exists and if not it inserts the data and then displays a message to the user that they have unlocked the avatar. ( not working )

 

The current code is...

 

$query = mysql_query("SELECT * FROM avatar_blank WHERE 'user_name' = '$username' AND 'avatar_name' = 'ecard'");
$num = mysql_numrows($query);
if($num < 1){

mysql_query("INSERT INTO avatar_blank (user_name, avatar_name) VALUES ('$user_name','ecard')");
echo "<table width=300 border=1 cellpadding=4 cellspacing=0 bordercolor=#000000 bgcolor=white><tr><td><img src=/images/avatars/ecard.gif width=80 height=80 hspace=10 align=left><font color=#FF3399 size=3 face=Arial, Helvetica, sans-serif><b>Congratulations</b></font><font size=2 face=Arial, Helvetica, sans-serif><br><br>You can now use ECard as an avatar on the chat forum </font></td></tr></table>";

}

You have it basically right

 

The only thing you need to change is

 

$num = mysql_numrows($query);

 

to

 

$num = mysql_num_rows($query);

 

to have it on page load change this

 

$num = mysql_num_rows($query);

 

to

 

mysql_num_rows($query);

 

 

Hope that helps :D

 

~ Chocopi

ok now im trying this after reading many tutorials and examples...

 

 

$sql = mysql_query("SELECT * FROM avatar_blank WHERE username = '$username' AND avatar_name = 'ecard'");
$result = mysql_num_rows($sql);

if($result=="0")
{

exit;
} 

else 

{

$sql = mysql_query("INSERT INTO avatar_blank (user_name, avatar_name) VALUES ('$user_name','ecard')");
if(!$sql)
        { 
    echo "Error performing query: ".mysql_error(); 
        }
else 
            { 
   echo "<table width=300 border=1 cellpadding=4 cellspacing=0 bordercolor=#000000 bgcolor=#ffffff><tr><td><img src=/images/ecard.gif width=80 height=80 hspace=10 align=left><font color=#FF3399 size=3 face=Arial, Helvetica, sans-serif><b>Congratulations $username</b></font><font size=2 face=Arial, Helvetica, sans-serif><br><br>You can now use ECard as an avatar on the chat forum </font></td></tr></table>"; 
            } 
}

 

I get the error...

 

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/chicka/public_html/cards/processCompose.php on line 34

 

 

Ok now tearing my hair out!!!

 

Im desperate here

 

$sql = mysql_query("SELECT * FROM avatar_blank WHERE username = '$username' AND avatar_name = 'ecard'");
$result = mysql_num_rows($sql);

if($result=="0")
{
$sql = mysql_query("INSERT INTO avatar_blank (user_name, avatar_name) VALUES ('$username','ecard')");
if(!$sql)
        { 
    echo "Error performing query: ".mysql_error(); 
        }
else 
            { 
   echo "<table width=300 border=1 cellpadding=4 cellspacing=0 bordercolor=#000000 bgcolor=#ffffff><tr><td><img src=/images/ecard.gif width=80 height=80 hspace=10 align=left><font color=#FF3399 size=3 face=Arial, Helvetica, sans-serif><b>Congratulations $username</b></font><font size=2 face=Arial, Helvetica, sans-serif><br><br>You can now use ECard as an avatar on the chat forum </font></td></tr></table>"; 
            } 

} 

 

ERROR

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/chicka/public_html/cards/processCompose.php on line 34

 

I always get this num rows error - is there another option?

Ok solved

 

for those who ever need it heres the code

 

<?
$sql = mysql_query("SELECT * FROM avatar_blank WHERE user_name = '$username' AND avatar_name = 'ecard'");
$result = mysql_num_rows($sql);

if($result=="0")
{
$sql = mysql_query("INSERT INTO avatar_blank (user_name, avatar_name) VALUES ('$username','ecard')");
if(!$sql)
        { 
    echo "Error performing query: ".mysql_error(); 
        }
else 
            { 
   echo "<table width=300 border=1 cellpadding=4 cellspacing=0 bordercolor=#000000 bgcolor=#ffffff><tr><td><img src=/avatars/ecard.gif width=80 height=80 hspace=10 align=left><font color=#FF3399 size=3 face=Arial, Helvetica, sans-serif><b>Congratulations $username</b></font><font size=2 face=Arial, Helvetica, sans-serif><br><br>You can now use ECard as an avatar on the chat forum </font></td></tr></table>"; 
            } 

} 
?>

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.