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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.