inserting data to database????

Discussion in 'Apache' started by akiko07, Feb 3, 2010.

  1. #1
    I am new in using php and mysql...I have this two testing page namely form.php and update.php. I want to insert data to my database.When I run the form.php it works but it did not go to update.php as what I'm thinking of.When i run the update.php it always says: (the following messages)...please send me some help or what will i add to my code to run it properly????thanks in advance

    Parse error: syntax error, unexpected T_STRING in C:\xampp\htdocs\e\Admin\update.php on line 15



    form.php

    <html>
    <head>
    <title>Update database</title>
    </head>

    <body>
    <form method="post" action="update.php">
    Customer Name:<br/>
    <input type="text" name="Customer_Name" size="30" /><br/>
    Item Description:<br/>
    <input type="text" name="Item_Description" size="30" /><br/>
    Date od Purchase:<br/>
    <input type="text" name="Date_of_Purchase" size="10" /><br/>
    Total Order:<br/>
    <input type="text" name="Total_order" size="10" /><br/>
    <input name="submit" value="update" type="button">
    </body>
    </html>




    update.php

    <?php

    $customer_name = $_POST['customer_name'];
    $item_description = $_POST['item_description'];
    $date = $_POST['date'];
    $total_order = $_POST['total_order'];

    mysql_connect("localhost","travel2","") or die ('Error:'.mysql_error());
    mysql_select_db ("travel2");

    $query="INSERT INTO travel2 (hobbes_id, customer_name, item_description, total_order) values ('NULL','" .$customer_name."' ,'" .$item_description."','" .$date."','" .$total_order."');

    mysql_query ($query) or die ('Error updating database');

    echo "Database Updated With:" " .$customer_name." ".$item_description." ".$date." ".$total_order.";

    ?>
     
    akiko07, Feb 3, 2010 IP
  2. antisocial

    antisocial Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    echo "Database Updated With:" " .$customer_name." ".$item_description." ".$date." ".$total_order.";

    you need to move the .'s outside the "s in that line..


    also $query="INSERT INTO travel2 (hobbes_id, customer_name, item_description, total_order) values ('NULL','" .$customer_name."' ,'" .$item_description."','" .$date."','" .$total_order."');

    Remove the .'s all together in that line and if you use a string variable (aka $customer_name). You can only use them inside double quotes ("s) not single. So remove the single quotes as well and leave the "s :)
     
    antisocial, Feb 3, 2010 IP
  3. akiko07

    akiko07 Peon

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    == okie thanks for replying, ill try it==
     
    akiko07, Feb 4, 2010 IP
  4. akiko07

    akiko07 Peon

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    hi,

    i already try your advice..I changed those line. when I hit the form.php file and input some info in it. It doesnt works....??

    <?php
    $hobbes_id = $_POST['hobbes_id'];
    $customer_name = $_POST['customer_name'];
    $item_description = $_POST['item_description'];
    $date = $_POST['date'];
    $total_order = $_POST['total_order'];

    mysql_connect("localhost","root","") or die ('Error:'.mysql_error());
    mysql_select_db ("travel2");

    $query="INSERT INTO hobbes (hobbes_id, customer_name, item_description, date, total_order) values ('NULL','.$customer_name.' ,' .$item_description.','.$date.',' .$total_order.')";

    mysql_query ($query) or die ('Error updating database');

    echo "Database Updated With:' .$customer_name.' '.$item_description.' '.$date.' '.$total_order.'";

    ?>
     
    akiko07, Feb 4, 2010 IP
  5. bogdanas

    bogdanas Peon

    Messages:
    17
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Don't mix " and '. php variables in " ar still variables, everything in ' is text. for example:
    <?php
    $test = "hi";
    echo "var: $test";
    echo "<br />";
    echo 'var: $test';
    ?>
    Code (markup):
    Will print:
    var: hi
    var: $test
    Code (markup):
    in Your case query should be:

    $query="INSERT INTO hobbes (hobbes_id, customer_name, item_description, date, total_order) values ('NULL', '".$customer_name."', '".$item_description."', '".$date."', '".$total_order."')";

    And:
    echo "Database Updated With: '".$customer_name."' '".$item_description."' '".$date."' '".$total_order."'";

    P. S. Use debuging for example after: $query="INSERT INTO hobbes (hobbes_id, customer_name, item_description, date, total_order) values ('NULL', '".$customer_name."', '".$item_description."', '".$date."', '".$total_order."')"; type:
    if (!$query) { echo mysql_error(); }
    Code (markup):
    Will be a lot easyer to learn :)
     
    bogdanas, Feb 16, 2010 IP