Hi,

I have created table in database mysql and I created register form and I wrote insert code ,when we run the php file there is no but given data is not inserted in database....I need help,I am new to php....


This is my code i have used,........

<?php
if(isset($_POST)){
$host= "localhost";
$username= "root";
$password= "";
$db_name= "register";
$tbl_name="form";

mysql_connect("$host","$username","$password") ;
mysql_select_db("$register") ;

$fname= $_POST;
$lname =$_POST;
$eid =$_POST;
$pwd=$_POST;
$cpwd=$_POST;

$sql="INSERT INTO $form (id , fname ,lname, eid , pwd,cpwd) VALUES('NULL',' $fname','$lname','$eid','$pwd','$cpwd')";
$result=mysql_query($sql);

// close connection
mysql_close();
}

?>

Recommended Answers

All 3 Replies

if id is primarykey, replace NULL with ' ' and try once.

use die(mysql_error()) to see whats wrong into your query.

<?php
if(isset($_POST['submit'])){
$host= "localhost";
$username= "root";
$password= "";
$db_name= "register";
$tbl_name="form";

mysql_connect("$host","$username","$password") or die(mysql_error());;
mysql_select_db("$register") or die(mysql_error());;

$fname= $_POST['fname'];
$lname =$_POST['lname'];
$eid =$_POST['eid'];
$pwd=$_POST['pwd'];
$cpwd=$_POST['cpwd'];

$sql="INSERT INTO $form (id , fname ,lname, eid , pwd,cpwd) VALUES('NULL',' $fname','$lname','$eid','$pwd','$cpwd')";
$result=mysql_query($sql) or die(mysql_error());

// close connection
mysql_close();
}

?>

What is $form in insert query?
Bcz it doesn't defined in above code.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.