...

View Full Version : php insert problem



hassanab
11-07-2010, 06:52 AM
I have problem in inserting data into database please help me to find error on the code below:
connect.php:


<?php
$connection=mysql_connect("localhost","root","root");
mysql_select_db("system",$connection);
?>

insert.php:


<?php
include("connect.php");
if (isset($_POST['ok']))
{
$Book_no=$_POST["Book_no"];
$Book_title=$_POST["Book_title"];
$Book_author=$_POST[Book_author];
$publisher_date=$_POST["publisher_date"];
$publisher_place=$_POST["publisher_place"];
$query="insert into supply(Book_no, Book_title, Book_author, publisher_date, publisher_place) values ('$Book_no','$Book_title','$Book_author','$publisher_date','$publisher_place')";
mysql_query($query) or die ('Error in entering data');
}
else
{
?>
<html>
<head>
<script language="javascript">
function check1()
{
if (document.form1.Book_no.value=="")
{
window.alert("Please Enter Book Number");
return false;
}
if (document.form1.Book_title.value=="")
{
window.alert("Please Enter Book Title");
return false;
}
if (document.form1.Book_author.value=="")
{
window.alert("Please Enter Book Author");
return false;
}
if (document.form1.publisher_date.value=="")
{
window.alert("Please Enter Publisher Date");
return false;
}
if (document.form1.publisher_place.value=="")
{
window.alert("Please Enter Publisher Place");
return false;
}
else
{
return true;
}
}
</script>
</head>
<body>
<form name="form1" method="post" onsubmit="return check1()">
Book No<input type="text" name="Book_no"><br>
Book Title<input type="text" name="Book_title"><br>
Book Author<input type="text" name="Book_author"><br>
Publisher Date<input type="text" name="publisher_date"><br>
Publisher Place<input type="text" name="publisher_place"><br>
<input type="submit" name="ok" value="save">

</form>


Thanks in advance

Keleth
11-07-2010, 07:19 AM
Is there a quote in any of your POST data? I do notice that $_POST[Book_author] is not quoted, which is a bug in itself, but shouldn't cause the query to fail.

If you echo $query, what do you get? Does it show "Error in entering data"?

hassanab
11-08-2010, 08:17 AM
yes you are right book_author must be quoted, may be the problem from it I will try it but the problem it doesn't give me any error when I execute the code it gives me the page to insert data but data does not insert into database

abduraooft
11-08-2010, 08:28 AM
What do you get as the output for

echo $query="insert into supply(Book_no, Book_title, Book_author, publisher_date, publisher_place) values ('$Book_no','$Book_title','$Book_author','$publisher_date','$publisher_place')";

hassanab
11-10-2010, 09:19 AM
When execute the insert.php bring to me the form to enter data.after enterying data and press save show to me a form to insert data again. it doesn't show to me any errors.

bngari
11-10-2010, 09:59 AM
When you put your own custom error in the line:


mysql_query($query) or die ('Error in entering data');

it is impossible to know the syntax error thats causing your code not to work. Try using the code below and tell me how it goes.


mysql_query($query) or die (mysql_error());

Cheers.

hassanab
11-11-2010, 02:43 PM
I'm using the code below but no change. there are no errors it gives me the form to enter data again.


mysql_query($query) or die (mysql_error());

and the data not entering the database.

MattF
11-11-2010, 02:50 PM
<form name="form1" method="post" onsubmit="return check1()">
<input type="hidden" name="ok" value="1"/>
Book No<input type="text" name="Book_no"><br>
Book Title<input type="text" name="Book_title"><br>
Book Author<input type="text" name="Book_author"><br>
Publisher Date<input type="text" name="publisher_date"><br>
Publisher Place<input type="text" name="publisher_place"><br>
<input type="submit" name="submit" value="save">



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum