--------- Posted April 4, 2012 Author Share Posted April 4, 2012 PHP's too fun. http://pastebin.com/La8255fh Try that out, just changed a few things, can be viewed by "view the difference". Thanks a million! It works and adds +1 to the user's IP's cookienum each time the user visits/refreshes the page it it is meant to! Currently when someone views the page it only says "Cookies have been added". It only shows up in the database, and I'd also like it to display the IP's "cookienum" on the page. The page is at: http://enigmoweb.com/hg/command.jpg/cookie-data.php Quote Link to comment Share on other sites More sharing options...
Deja Q Posted April 4, 2012 Share Posted April 4, 2012 Added it after it says "cookies have been added"; look for "ECHO:". http://pastebin.com/eeT0YbeE The variable to hold their cookie count is set to; $CLIENT_TOTAL_COOKIES by Papa John. Also; you might as well change "cookienum" to an int field, since there's no text being stored there. Oh, and no problem, message me on here or Steam if you ever need any help in PHP, not too bad at Java either. Love them both. Quote Link to comment Share on other sites More sharing options...
--------- Posted April 4, 2012 Author Share Posted April 4, 2012 (edited) Added it after it says "cookies have been added"; look for "ECHO:".http://pastebin.com/eeT0YbeE The variable to hold their cookie count is set to; $CLIENT_TOTAL_COOKIES by Papa John. It worked perfectly. Although I have now come across one big problem. If the users ip isn't already manually entered into the database, it will display a blank page and the query to add the users ip won't run. I had replaced REMOTE_IP with 1234 to see if it works, with no result. /* If it doesn't exist insert */ } else { /* Insert record into database */ if( mysql_query("INSERT INTO `cookies_2403465`.`cookies` (`ip`, `cookienum`) VALUES ('1234', '1');")) echo "Your record has been added!"; else die(mysql_error()); } Edited April 4, 2012 by ENIGM0 Quote Link to comment Share on other sites More sharing options...
Guest The_Monkey Posted April 4, 2012 Share Posted April 4, 2012 It worked perfectly. Although I have now come across one big problem. If the users ip isn't already manually entered into the database, it will display a blank page and the query to add the users ip won't run. I had replaced REMOTE_IP with 1234 to see if it works, with no result. /* If it doesn't exist insert */ } else { /* Insert record into database */ if( mysql_query("INSERT INTO `cookies_2403465`.`cookies` (`ip`, `cookienum`) VALUES ('1234', '1');")) echo "Your record has been added!"; else die(mysql_error()); } The @ sign is your friend. Quote Link to comment Share on other sites More sharing options...
--------- Posted April 4, 2012 Author Share Posted April 4, 2012 The @ sign is your friend. Where does my friend go? Quote Link to comment Share on other sites More sharing options...
Papa John Posted April 4, 2012 Share Posted April 4, 2012 Wait Wait Wait... First its @mysql_query(... And second you don't need the database name "cookies_2403465" included in the insert statement when we selected the database at the top... Quote Link to comment Share on other sites More sharing options...
--------- Posted April 4, 2012 Author Share Posted April 4, 2012 (edited) Wait Wait Wait... First its @mysql_query(... And second you don't need the database name "cookies_2403465" included in the insert statement when we selected the database at the top... Have done everything you said, still returns a blank page and no rows were made in the database. If you want access to my DB, just say and i'll give you the login panel and info. Sorry to be such a pain.. <?php /* Start Config */ define("DATABASE_USERNAME", "cookies"); // Database Username define("DATABASE_PASSWORD", "**"); // Database Password define("DATABASE_HOST", "sql**.bravehost.com"); // Database Host define("DATABASE_NAME", "cookies_***3465"); // Database Name define("REMOTE_IP", $_SERVER['REMOTE_ADDR']); // Client's IP /** * Database Note: * Table should be called: cookies * Two text rows called: ip & cookienum */ /* End Config */ /* Connect to database */ mysql_connect(DATABASE_HOST, DATABASE_USERNAME, DATABASE_PASSWORD) or die(mysql_error()); mysql_select_db(DATABASE_NAME) or die(mysql_error()); /* Check Database For Record */ $query = "SELECT * FROM cookies WHERE ip = '" . REMOTE_IP . "' LIMIT 1"; $result = mysql_query($query) or die(mysql_error()); /* If the record exists */ if( $result ){ $row = mysql_fetch_array($result) or die(mysql_error()); $CLIENT_TOTAL_COOKIES = $row['cookienum'] + 1; /* Since the record exists, lets update the amount of "cookies" they have */ if( mysql_query("UPDATE cookies SET cookienum = cookienum + 1 WHERE ip = '" . REMOTE_IP . "' LIMIT 1") ) echo "You have been given 1 cookie!"; else die(mysql_error()); /* ECHO: Show client's current cookies */ echo "<br /><b>Total Cookies: $CLIENT_TOTAL_COOKIES</b>"; /* If it doesn't exist insert */ } else { /* Insert record into database */ if( @mysql_query("INSERT IGNORE INTO cookies ( ip, cookienum ) VALUES( '" . REMOTE_IP . "', '1'") ) echo "Your record has been added!"; else die(mysql_error()); } ?> Edited April 5, 2012 by ENIGM0 Quote Link to comment Share on other sites More sharing options...
Deja Q Posted April 5, 2012 Share Posted April 5, 2012 Have done everything you said, still returns a blank page and no rows were made in the database. If you want access to my DB, just say and i'll give you the login panel and info. Sorry to be such a pain.. <?php /* Start Config */ define("DATABASE_USERNAME", "cookies"); // Database Username define("DATABASE_PASSWORD", "**"); // Database Password define("DATABASE_HOST", "sql**.bravehost.com"); // Database Host define("DATABASE_NAME", "cookies_***3465"); // Database Name define("REMOTE_IP", $_SERVER['REMOTE_ADDR']); // Client's IP /** * Database Note: * Table should be called: cookies * Two text rows called: ip & cookienum */ /* End Config */ /* Connect to database */ mysql_connect(DATABASE_HOST, DATABASE_USERNAME, DATABASE_PASSWORD) or die(mysql_error()); mysql_select_db(DATABASE_NAME) or die(mysql_error()); /* Check Database For Record */ $query = "SELECT * FROM cookies WHERE ip = '" . REMOTE_IP . "' LIMIT 1"; $result = mysql_query($query) or die(mysql_error()); /* If the record exists */ if( $result ){ $row = mysql_fetch_array($result) or die(mysql_error()); $CLIENT_TOTAL_COOKIES = $row['cookienum'] + 1; /* Since the record exists, lets update the amount of "cookies" they have */ if( mysql_query("UPDATE cookies SET cookienum = cookienum + 1 WHERE ip = '" . REMOTE_IP . "' LIMIT 1") ) echo "You have been given 1 cookie!"; else die(mysql_error()); /* ECHO: Show client's current cookies */ echo "<br /><b>Total Cookies: $CLIENT_TOTAL_COOKIES</b>"; /* If it doesn't exist insert */ } else { /* Insert record into database */ if( @mysql_query("INSERT IGNORE INTO cookies ( ip, cookienum ) VALUES( '" . REMOTE_IP . "', '1'") ) echo "Your record has been added!"; else die(mysql_error()); /* ECHO: Show client's cookies after inserting into DB (any errors, cookie will be set to 0) */ $CLIENT_TOTAL_COOKIES = mysql_num_rows($result) >= 0 ? mysql_num_rows($result) : 0; echo "<br /><b>Total Cookies: $CLIENT_TOTAL_COOKIES</b>"; } ?> Changes cmmented with "ECHO:" again. Calling the row count after inserting new data. Quote Link to comment Share on other sites More sharing options...
--------- Posted April 5, 2012 Author Share Posted April 5, 2012 (edited) Thank you to everyone that helped, I owe you all! It is all working now! http://enigmoweb.com/hg/command.jpg/ Edited April 5, 2012 by ENIGM0 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.