i have created two pages, 1. login.php 2. connect.php 3. same fields in database. but data could not inserted in database, ???? <head> <title>Hello!</title> </head> <body> <form action="connect.php" mathod="post"> Username :<input type="text" name="fname"></br> Password :<input type="password" name="pwd"></br> Click here :<input type="submit" name="submit" value="Submit"> </form> </body> </html> ========== <?php mysql_connect('localhost','root','') or die ('Could not connect'); echo('Connected Successfully!')."<br />"; mysql_select_db('yasir') or die ('Database not found'); echo('Connected Successfully with Database!'); $name = $_POST['fname']; $company = $_POST['pwd']; $sql ="INSERT into user(`firstname`, `password`) values('$name','$company')"; $query = mysql_query($sql); if($query){ echo mysql_error(); } else { echo 'inserted successfully'; } ?>
add id too .. and try Username :<input type="text" name="fname" id="fname"></br> Password :<input type="password" name="pwd" id="pwd"></br>
you'll have bigger problems using deprecated mysql functions, throw it away and start using PDO, There's a couple of tut's here to get you going. http://wiki.hashphp.org/PDO_Tutorial_for_MySQL_Developers http://net.tutsplus.com/tutorials/php/php-database-access-are-you-doing-it-correctly/ If your host doesn't support PDO get a new host.
IDs aren't important in this case. if($query){ echo mysql_error(); } else { echo 'inserted successfully'; } PHP: What was this supposed to do?
Yeah, as sorindsd said, you have a misspelled method to 'mathod' causing the form varialbles $_POST['fname'] and $_POST['pwd'] to be empty. I am guessing that multiple entries were added in the tables, all with empty name and password.
Hi! Every thing i perfect just check spilling mistake in html tags and attributes. To solve the issue change this line : <form action="connect.php" mathod="post"> Code (markup): to this : <form action="connect.php" method="post"> Code (markup): To avoid these kind of mistakes, It will be better if you use a good text editor like Note++ or Dreamweaver !
Oh and you can also check if the script receives a POST from a form with if ($_SERVER['REQUEST_METHOD'] == "POST") { // do your thing } PHP: