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!"; ?> Link to comment https://forums.phpfreaks.com/topic/107767-solved-check/ 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 Link to comment https://forums.phpfreaks.com/topic/107767-solved-check/#findComment-552393 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? Link to comment https://forums.phpfreaks.com/topic/107767-solved-check/#findComment-552407 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!"; ?> Link to comment https://forums.phpfreaks.com/topic/107767-solved-check/#findComment-552408 Share on other sites More sharing options...
paulman888888 Posted May 29, 2008 Author Share Posted May 29, 2008 THankyou very much. Link to comment https://forums.phpfreaks.com/topic/107767-solved-check/#findComment-552415 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.