Jump to content

Insert into database error


duncan_cowan

Recommended Posts

Hi I have made a script to insert a row into a database with the computers ip and a random number, but noting will be added to the database. Please could someone help...script:

<?php$ip = $_SERVER["REMOTE_ADDR"];$random = rand(600000000, 900000000); // between * and * inclusive$user_number = $ip.$random;if (isset($_COOKIE["user_online"])){echo $_COOKIE["user_online"];$sql_script = 'SELECT COUNT (*) FROM users_online';$users_online = mysql_query($sql_script);} else {setcookie("user_online", "$user_number");echo "Cookie set";mysql_query("INSERT INTO users_online (rand-num) VALUES ('".$user_number."')");$sql_script = mysql_query("SELECT * FROM users_online");$num_rows = mysql_num_rows($sql_script);echo $num_rows;}?>

Thankyou in advance... :)

Link to comment
Share on other sites

isn't it called mysql_error() ? :)
Yes it is, but there's an mysqli_error() too, but that requires a handler/link to the database (i as in Improved).
Link to comment
Share on other sites

I think it's the query:mysql_query("INSERT INTO users_online (rand-num) VALUES ('".$user_number."')");You are saying the field is called "rand minus num". Either don't use hyphens in field names, because in SQL and PHP it is an arithmetic operator, or put the fieldname in backquotes.mysql_query("INSERT INTO users_online (`rand-num`) VALUES ('".$user_number."')");

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...