Skip to main content
gamedev.net
🔒 Locked 🤖 Godot

[web] a php problem (solved)

Started by bigfooot Oct 16, 2005 at 9:03 PM 3 replies 850+ views
Original Post
bigfooot
bigfooot
hi guys, im making a text-based mmorpg and im getting the following errors with this code Notice: Undefined variable: MONEY in c:\program files\easyphp1-7\www\v 0.0.1\register.php on line 107 Notice: Undefined variable: FANS in c:\program files\easyphp1-7\www\v 0.0.1\register.php on line 107 Erreur de syntaxe près de 'now())' à la ligne 2 here is my code: $info2 = htmlspecialchars($info); $sql = mysql_query("INSERT INTO users (first_name, last_name, email_address, username, password, info, signup_date) VALUES('$first_name', '$last_name', '$email_address', '$username', '$db_password', '$info2', now())") or die (mysql_error()); $money = 500; $fans = 10; $sql2 = mysql_query("INSERT INTO userstats (money, fans) VALUES('$MONEY', '$FANS' now())") or die (mysql_error()); if(!$sql){ echo 'There has been an error creating your account. Please contact the webmaster.'; } else if(!$sql2){ echo 'Please try again.'; } else { $userid = mysql_insert_id(); // Let's mail the user! $subject = "Your Membership at MyWebsite!"; $message = "Dear $first_name $last_name, Thank you for signing up at our website, http://v491400027/v%200.0.1/ You are two steps away from logging in and accessing our new game. To activate your membership, please click here: http://v491400027/v%200.0.1/activate.php?id=$userid&code=$db_password Once you activate your memebership, you will be able to login with the following information: Username: $username Password: $random_password Thanks! Alex Please do not reply!"; mail($email_address, $subject, $message, "From: Music MMORPG \nX-Mailer: PHP/" . phpversion()); echo 'Your membership information has been mailed to your email address! Please check it and follow the directions!'; } the email does not get sent, (yes i have SMTP and everything set-up), and the data only gets saved in the table "users", and not "userstats". thanks alex [Edited by - bigfooot on October 21, 2005 12:51:27 AM]
Frequency
Frequency
$sql2 = mysql_query("INSERT INTO userstats (money, fans)
VALUES('$MONEY', '$FANS' now())") or die
(mysql_error());


I don't know quite what now() is doing, but you have a comma before it when you INSERT it into users, and not when you INSERT it into userstats ('$FANS' now()), so I think that may be why userstats is not updating. I don't understand why your mail() call wouldn't work, maybe you could try it without the headers?
It only takes one mistake to wake up dead the next morning.
Kristafarii
Kristafarii
Isn't php case sensitive

so

$sql2 = mysql_query("INSERT INTO userstats (money, fans)
VALUES('$MONEY', '$FANS' now())") or die
(mysql_error());

should be

$sql2 = mysql_query("INSERT INTO userstats (money, fans)
VALUES('$money', '$fans' now())") or die
(mysql_error());
Sander
Sander
Both above posters are correct. Try this one:

$sql2 = mysql_query("INSERT INTO userstats (money, fans) VALUES ('$money', '$fans')") or die (mysql_error());


PHP is case sensitive (so vars changed to lowercase), plus you were messing with that now() statement. If you wanted it to be a separate variable then you need to have a 3rd field in your field listing and you needed a comma before it, like:

$sql2 = mysql_query("INSERT INTO userstats (money, fans, field3) VALUES ('$money', '$fans', now())") or die (mysql_error());


Also, the rest of the script has some errors. Firstply, you are using mysql_insert_id() after the second SQL query. Be aware that that will get you the ID of the userstats row, not the ID of the users row.

Finally, you are not declaring your $email_address. While I presume that it has been set in a form, you should not rely on variables passed by a form to be globals. Only really old PHP installations have that. You should use $_REQUEST[' email_address'] or $_GET[' email_address'] or $_POST['email_address'] instead. Same goes with all the other form variables.
bigfooot
bigfooot
thanks a lot guys i have now got it working.

I took away the now(), and did other corrections

im so happy now :D

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.