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
    Nov 2011
    Posts
    41
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Error in this Mysql to PHP script

    I am sending data to my MySQL database. This script was working fine, until I included the 'TIME: auto NOW(TIME' )"; code. So I'm pretty sure I made an error with inserting the time, or it's not formatted correctly. Can anyone locate the problem I've made?


    PHP Code:
     <?php
    $con 
    mysql_connect("localhost","myusername","mypassword");
    if (!
    $con)
      {
      die(
    'Could not connect: ' mysql_error());
      }
    mysql_select_db("silviafilms_ca_4"$con);
    $sql="INSERT INTO Comments (FirstName, Comments, TIME, )
    VALUES
    ('$_POST[firstname]','$_POST[comments]','TIME: Auto NOW(TIME)' )"
    ;
    if (!
    mysql_query($sql,$con))
      {
      die(
    'Error: ' mysql_error());
      }
    header'Location: http://www.mywebsite.com' ) ;
     {
    mysql_close($con)
    ?>
    Last edited by Inigoesdr; 11-13-2011 at 03:11 AM.

  • #2
    New Coder
    Join Date
    Nov 2011
    Posts
    41
    Thanks
    2
    Thanked 0 Times in 0 Posts
    It works fine when I have it like this, but then it creates two table:
    PHP Code:
    <?php
    $con 
    mysql_connect("localhost","myusername","mypassowrd");
    if (!
    $con)
      {
      die(
    'Could not connect: ' mysql_error());
      }
    mysql_select_db("silviafilms_ca_4"$con);
    $sql="INSERT INTO Comments (FirstName, Comments)
    VALUES
    ('$_POST[firstname]','$_POST[comments]')"
    ;
    if (!
    mysql_query($sql,$con))
      {
      die(
    'Error: ' mysql_error());
      }
    header'Location: http://mywebsite.com' ) ;
     {
    $query_auto "INSERT INTO Comments (TIMER, TIME)
        VALUE ('TIME: Auto NOW()', NOW() )"
    ;
    mysql_query($query_auto) or die(mysql_error());
     }
    mysql_close($con)
    ?>
    Last edited by Inigoesdr; 11-13-2011 at 03:11 AM.

  • #3
    Senior Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Location
    Behind the Wall
    Posts
    3,133
    Thanks
    12
    Thanked 332 Times in 328 Posts
    well, you’re doing two queries …
    The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
    André Behrens, NY Times Software Developer

  • #4
    New Coder
    Join Date
    Nov 2011
    Posts
    41
    Thanks
    2
    Thanked 0 Times in 0 Posts
    I did this, and it actually works how I want it to. I'm surprised as you are:
    PHP Code:
    <?php
    $con 
    mysql_connect("localhost","username","password");
    if (!
    $con)
      {
      die(
    'Could not connect: ' mysql_error());
      }
    mysql_select_db("silviafilms_ca_4"$con);
    $query_auto "INSERT INTO Comments (firstname, comments, TIMER, TIME)
        VALUE ('$_POST[firstname]','$_POST[comments]','TIME: Auto NOW()', NOW() )"
    ;
    mysql_query($query_auto) or die(mysql_error());
     {
    header'Location: http://www.google.ca/images/persons.html' ) ;
     }
    mysql_close($con)
    ?>
    Last edited by Inigoesdr; 11-13-2011 at 03:12 AM.

  • #5
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,638
    Thanks
    2
    Thanked 404 Times in 396 Posts
    Quote Originally Posted by johnnycabbage View Post
    I'm surprised as you are
    So, not surprised? You were running two INSERT queries; you should be getting two rows. When you removed one of the INSERT queries you get one row.

  • #6
    New Coder
    Join Date
    Nov 2011
    Posts
    41
    Thanks
    2
    Thanked 0 Times in 0 Posts
    No, I was surprised that I was able to combine both of the insert queries, and have it run fine:
    Code:
    $query_auto = "INSERT INTO Comments (firstname, comments, TIMER, TIME)
        VALUE ('$_POST[firstname]','$_POST[comments]','TIME: Auto NOW()', NOW() )";
    Because one query was transferred data, and the other query was generated data.

  • #7
    Senior Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Location
    Behind the Wall
    Posts
    3,133
    Thanks
    12
    Thanked 332 Times in 328 Posts
    after evaluating the query string you only have a string where you can’t determine (from looking at the string itself) which parts originate where.
    The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
    André Behrens, NY Times Software Developer

  • #8
    New Coder
    Join Date
    Nov 2011
    Posts
    41
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Dormilich View Post
    after evaluating the query string you only have a string where you can’t determine (from looking at the string itself) which parts originate where.
    They originated from a previous page.


  •  

    Posting Permissions

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