0

I am new to PHP and databases, here is my PHP code:

<?php 

$email = $_POST['Email'];
$tc = $_POST['TotalCash'];
$tr = $_POST['TotalReferalls'];

// Connects to your Database 
mysql_connect("205.178.146.92", "user", "pass") or die(mysql_error()); 
mysql_select_db("db") or die(mysql_error()); 
mysql_query("INSERT INTO UserInformation(Email, TotalCash, TotalReferalls) VALUES('$email', '$tc', '$tr')"); 
Print "Your table has been populated"; 
?>

and this works when I change $email and all of the variables to a set value, like $email = '[email protected]', $tc = 3, $tr = 4, but when I try to set it by calling a url (mysite.com/myphp.php?$email='[email protected]'&$tc=4&$tr=2) it does not work, please show a working way to set the parameters from the url.

Thanks in advance!

2 Answers 2

1

If you want the parameters from the URL, switch $_POST to $_GET.

Also, you will need to use mysql_real_escape_string() with those outside strings, otherwise you have a SQL injection vulnerability.

Even better, because you are new to PHP and databases, learn it the best way from the start. Drop mysql_*() and use PDO.

Sign up to request clarification or add additional context in comments.

Comments

0

For URl, you have to change $_POST to $_GET.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.