Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    New Coder
    Join Date
    Sep 2009
    Posts
    40
    Thanks
    3
    Thanked 0 Times in 0 Posts

    php insert problem

    I have problem in inserting data into database please help me to find error on the code below:
    connect.php:
    PHP Code:
    <?php
    $connection
    =mysql_connect("localhost","root","root");
    mysql_select_db("system",$connection);
    ?>
    insert.php:
    PHP Code:
    <?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

  • #2
    Senior Coder
    Join Date
    Jun 2008
    Location
    New Jersey
    Posts
    2,535
    Thanks
    45
    Thanked 259 Times in 256 Posts
    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"?

  • #3
    New Coder
    Join Date
    Sep 2009
    Posts
    40
    Thanks
    3
    Thanked 0 Times in 0 Posts
    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

  • #4
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,852
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    What do you get as the output for
    PHP Code:
    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')"
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #5
    New Coder
    Join Date
    Sep 2009
    Posts
    40
    Thanks
    3
    Thanked 0 Times in 0 Posts
    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.

  • #6
    New Coder
    Join Date
    Nov 2010
    Location
    Kenya
    Posts
    42
    Thanks
    4
    Thanked 1 Time in 1 Post
    When you put your own custom error in the line:

    PHP Code:
    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.

    PHP Code:
    mysql_query($query) or die (mysql_error()); 
    Cheers.

  • #7
    New Coder
    Join Date
    Sep 2009
    Posts
    40
    Thanks
    3
    Thanked 0 Times in 0 Posts
    I'm using the code below but no change. there are no errors it gives me the form to enter data again.
    PHP Code:
    mysql_query($query) or die (mysql_error()); 
    and the data not entering the database.

  • #8
    Senior Coder
    Join Date
    Jul 2009
    Location
    South Yorkshire, England
    Posts
    2,318
    Thanks
    6
    Thanked 304 Times in 303 Posts
    Code:
    <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">


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •