I’m new to php and am making a simple login system.
When someone wants to register, they go to register.html, then insert.php.
The code below should add the data from the form to the table but is doesn’t come up in it.
I suspect it is probably the line: $sql=INSERT INTO…
The only thing appearing is the echo statement at the bottom of the code
I know there probably is a simple answer to this, but I still can’t find it.
Thanks, any help is really appreciated!
The code for insert.php
<?php
$email=$_POST['email'];
$name=$_POST['name'];
$password=$_POST['password'];
$con = mysql_connect("localhost","user","p@ssword");
mysql_select_db("database", $con);
$sql="INSERT INTO table_name (email, name, password)
VALUES ('$email', '$name', '$password')";
echo"Thank you, you are now registered and can login on our homepage";
mysql_close($con);
?>
Thanks again!
You established the connection and prepared the query, but you didn’t actually execute it! You need to call mysql_query(), passing in the SQL and the connection handle, to instruct the database to perform the statement.
Since you say you’re new to PHP (and probably database development in general?), let me also point you in the direction of the PHP tutorial on SQL injection, which explains what it is and why you need to guard against it – your example code, for instance, is vulnerable.