Jump to content

[SOLVED] check


paulman888888

Recommended Posts

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

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 :P

Link to comment
https://forums.phpfreaks.com/topic/107767-solved-check/#findComment-552393
Share on other sites

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.