Page 1 of 1

unable to connect php to mysql using xampp

PostPosted: 20. March 2013 19:25
by sprouts11
I am having trouble connecting to mysql database. The page loads fine with my 3 text boxes. When I populate the text boxes and click 'register' nothing happens. What I'm expecting to see is '1 row inserted' and for the data to be populated in mysql.

Can anybody HELP! Thanks!

Here is my code below...
------------------------------------------------------------------------------------
<html>
<head>
<title></title>
</head>
<body>
<form>
<form method="POST" action="insert.php">
Name: <input type="text" name="name" /> <br />
Email: <input type="text" name="email" /><br />
Password: <input type="password" name="password" /><br />
<p>
<input type="submit" name="submit" value="register" /><br />
</form>
</body>
</html>
---------------------------------------------------------------------------------------------
<?php

$name = $_POST['name'];
$email = $_POST['email'];
$password = $_POST['password'];

if($name && $email && $password){

mysql_connect("localhost", "root", "") or die("We could not connect!");

mysql_select_db("testing");

mysql_query("INSERT INTO accounts(name,email,password) VALUES('$name','$email','$password')");

$registered = mysql_affected_rows();

echo "$registered was inserted";

}else{

echo "you have to complete the form!";

}

mysql_close();
?>

Re: unable to connect php to mysql using xampp

PostPosted: 20. March 2013 19:39
by Altrea
sprouts11 wrote:<form>
<form method="POST" action="insert.php">


And you should learn how to debug your code.