duncan_cowan Posted February 7, 2007 Share Posted February 7, 2007 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 More sharing options...
Mr_CHISOL Posted February 7, 2007 Share Posted February 7, 2007 Have you tried echo mysqli_error ( ); after you run the INSERT-query to check if there are any errors? Link to comment Share on other sites More sharing options...
vytas Posted February 7, 2007 Share Posted February 7, 2007 isn't it called mysql_error() ? Link to comment Share on other sites More sharing options...
Mr_CHISOL Posted February 7, 2007 Share Posted February 7, 2007 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 More sharing options...
justsomeguy Posted February 7, 2007 Share Posted February 7, 2007 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 More sharing options...
duncan_cowan Posted February 7, 2007 Author Share Posted February 7, 2007 dont worry i tried using the mysql error function but to do this I set the query as a variable and just setting it as a variable seemed to work.Thanks to all those who suggested! Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now