<html>
<head>
<title> Register </title>
</head>
<body>
Thanks for showing interest, please register below.
<br>
<br/>
<form action="register.php" method="POST">
Username: <input type="text" name="username">
<br>
</br>
Password: <input type="password" name="password">
<br>
</br>
Age: <input type="text" name="age">
<br>
</br>
Car: <input type="text" name="car">
<br>
<input type="submit" value="register"/>
<input type="reset" value="Reset fields"/>
</form>
<?php
//db connect
$host="localhost";
$dbuser="site1login";
$dbpass="site1login";
$dbname="login";
$tblname="userdata";
//form post
$Username=$_POST['username'];
$Password=$_POST['password'];
$Age=$_POST['age'];
$Car=$_POST['car'];
$con = mysql_connect("$host","$dbuser","$dbpass") or die (mysql_error());
mysql_select_db($dbname, $con);
$result = mysql_query("INSERT INTO `userdata` (Username,Password,Age,Car) VALUES ($Username, $Password, $Age, $Car)" or die(mysql_error()));
echo "Success!";
?>
</body>
</html>
So, that’s my code – I’m confused – it doesn’t work – it says “success”, but not inserted e anything
Change the following portion –
into this –
If the above doesn’t work, try checking if your connection parameters are ok and if MySQL is running.
Also you should test the
$resutvalue to check whether any successful query execution has occured –Edit
As Pekka has mentioned, your database is vulnerable to SQL Injection attack since you are not sanitizing your input. You should use at least mysql_real_escape_string method to ensure that this doesn’t occur.