Jump to content

Hey guys I am having an if problem


maltech

Recommended Posts

First of all everything else is working fine. Yes I am learning, I am doing this project to learn, and it is fun to me to learn new things. All of your help and advice is greatly appreciated!

 

Now here is the code I am trying to use:

 

// Load User into Database if they do not exist

mysql_query("INSERT INTO Usertable (userid, name)

VALUES ('$user_id', '<fb:name uid=\"$user_id\" useyou=\"false\" />')");

 

// Query the Usertable for Information

$query  = "SELECT * FROM Usertable WHERE userid = '$user_id'";

$result = mysql_query($query);

 

while($row = mysql_fetch_array($result, MYSQL_ASSOC))

{

echo '<div id="stats">';

    echo "Thanks for Stoping By {$row['name']} ";

// If they have no value in level add level 1 to the Usertable

if (empty($row['level'])) {

mysql_query("INSERT INTO Usertable (level)

VALUES ('1')");

}

echo "<br>";

echo "Your Level Is {$row['level']} ";

echo '</div>';

}

 

 

// Close the Database

mysql_close();

 

The problem I am having it it seems the level is not being set to 1 or anything else for that matter, because this is my output on the page:

 

Thanks for Stoping By Chuck Cagle

Your Level Is

 

Thanks in advance!

Link to comment
https://forums.phpfreaks.com/topic/165336-hey-guys-i-am-having-an-if-problem/
Share on other sites

OK After slapping myself and drinking coffee I found the solution. Thank you to everyone who was attempting to come up with one for me, As always I appreciate any help even if its not seen.

 

This was the solution:

 

if (empty($row['level'])) {

mysql_query("UPDATE Usertable SET level = '1'

WHERE userid = '$user_id'");

}

 

I was trying to set a new row instead of update the existing one.

Archived

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

×
×
  • 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.