paulman888888 Posted May 29, 2008 Share Posted May 29, 2008 please can you check my code for errors. <?php mysql_connect("popcorn.com", "something", "its tony") or die(mysql_error()); echo "Connected to MySQL<br />"; mysql_select_db("pauhut5_db2") or die('Theres an error. Please try again.'); echo "Connected to Database"; // Insert a row of information into the table "example" mysql_query("INSERT INTO example (name, score) VALUES('$_GET[name]', '$_GET[score]' ) ") or die('Theres an error. Please try again.'); echo "Score Uploaded!"; ?> Quote Link to comment Share on other sites More sharing options...
ILYAS415 Posted May 29, 2008 Share Posted May 29, 2008 Its all right but theres unnessecary stuff in the code (the echoes but im not sure if you hose to include those yourself). Also your query is very vunerable to sql injection because you aren't parsing the $_GET stuff. No errors tho i think... If you don not know how to secure against sql injection or even what it is we will be glad to help Quote Link to comment Share on other sites More sharing options...
paulman888888 Posted May 29, 2008 Author Share Posted May 29, 2008 How do i make it safer then? Quote Link to comment Share on other sites More sharing options...
thebadbad Posted May 29, 2008 Share Posted May 29, 2008 You've got two errors. $_GET[name] should be $_GET['name'] (the key is a string, not an integer). Also applies to 'score' of course. To insert them properly, and prevent SQL injections like ILYAS is pointing out, you should escape them with mysql_real_escape_string(): <?php mysql_connect("popcorn.com", "something", "its tony") or die(mysql_error()); echo "Connected to MySQL<br />"; mysql_select_db("pauhut5_db2") or die('Theres an error. Please try again.'); echo "Connected to Database"; // Insert a row of information into the table "example" mysql_query("INSERT INTO example (name, score) VALUES('" . mysql_real_escape_string($_GET['name']) . "', '" . mysql_real_escape_string($_GET['score']) . "')") or die('Theres an error. Please try again.'); echo "Score Uploaded!"; ?> Quote Link to comment Share on other sites More sharing options...
paulman888888 Posted May 29, 2008 Author Share Posted May 29, 2008 THankyou very much. 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.