Insert data into DB

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rednarjess
    New Member
    • May 2007
    • 6

    Insert data into DB

    Dear all;

    I write a HTML form that ask user to post an announcement, the subject and body must be inserted into DB. But the problem that I face is the data is not inserted.
    Any body can help me please to tell me what is the error.
    Thanks.
    Here are my code.[php]<?php
    $host = "localhost" ;
    $user = "";
    $password = "";
    $db = "e-school";
    $table = "announceme nt";
    mysql_connect($ host,$user,$pas sword) or die("The connection the the specified DataBase is failed. Please try again!");
    mysql_select_db ($db);
    ?>
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta http-equiv="Content-Language" content="ar-sa">
    <title>POSTIN G ANNOUNCEMENT</title>
    </head>
    <body>
    <?php
    if (isset("submit" )) {
    $subject = $_POST['subject'];
    $body = $_POST['body'];
    $date = "20/4/2008";
    $sql = "INSERT INTO $table VALUES('$subjec t', '$body', '$date')";
    if (!mysql_query($ sql)) {
    die('ERROR..');
    }else{
    echo "Successful l... ";
    }
    mysql_close($co n);
    }else{
    ?>
    <form action="" method="POST" >
    <dl>
    <dd>
    <p dir="rtl"><b><s pan lang="ar-ae"><font size="4" color="#800000" >
    Subject </font></span></b></dd>
    <dd>
    <p dir="rtl"><font size="4" color="#800000" >
    <input size="54" maxlength="256" name="subject" style="font-size: 12pt; font-family: Times New Roman"></font></dd>
    </dl>
    <p dir="rtl"><b><s pan lang="ar-ae"><font size="4" color="#800000" >Body:</font></span></b></p>
    <dl>
    <dd>
    <p dir="rtl"><font size="4" face="Times New Roman" color="#0000FF" >
    <textarea name="body" rows="10" cols="57" style="font-size: 12pt; font-family: Times New Roman" dir="rtl"></textarea></font></dd>
    </dl>
    <p dir="rtl"><font color="#800000" size="4">
    <input type="submit" value="Submit" name="submit" style="font-size: 12pt"></font><b><font size="4" color="#800000" >
    </font></b><font size="3" color="#800000" >
    <input type="reset" value="Reset" name="clear" style="font-size: 12pt"></font></p>
    </form>
    <?php
    }
    ?>
    </body>
    </html>[/php]
    Last edited by ronverdonk; Apr 21 '08, 10:05 PM. Reason: warning: use code tags!
  • ronverdonk
    Recognized Expert Specialist
    • Jul 2006
    • 4259

    #2
    WARNING:
    Please enclose your posted code in [code] tags (See How to Ask a Question).

    This makes it easier for our Experts to read and understand it. Failing to do so creates extra work for the moderators, thus wasting resources, otherwise available to answer the members' questions.

    Please use [code] tags in future.

    MODERATOR

    Comment

    • ronverdonk
      Recognized Expert Specialist
      • Jul 2006
      • 4259

      #3
      Only way to find ouit what is the error is to display the MySQL return error messge when an error occurs, like[php]die('ERROR..' . mysql_error());[/php]You'd better do that with all your MySQL statement executions, so you don't have to ask.

      Ronald

      Comment

      • rednarjess
        New Member
        • May 2007
        • 6

        #4
        Originally posted by ronverdonk
        Only way to find ouit what is the error is to display the MySQL return error messge when an error occurs, like[php]die('ERROR..' . mysql_error());[/php]You'd better do that with all your MySQL statement executions, so you don't have to ask.

        Ronald
        Dear;
        Thank you for your replay, but the problem is that no data entry in My database?
        I don't know why?
        Could you please guide me?

        Thank you alot

        Comment

        • ajos
          Contributor
          • Aug 2007
          • 283

          #5
          Originally posted by rednarjess
          Dear;
          Thank you for your replay, but the problem is that no data entry in My database?
          I don't know why?
          Could you please guide me?

          Thank you alot
          Please ignore if this may sound stupid, i dont do php. Why is your [HTML]<form action="">[/HTML] blank?.

          Comment

          Working...