Results 1 to 7 of 7

Thread: poop (mysql) *RESOLVED*

  1. #1

    Thread Starter
    Lively Member morrowasted's Avatar
    Join Date
    Aug 2003
    Location
    Houston, TX
    Posts
    118

    poop (mysql) *RESOLVED*

    PHP:
    --------------------------------------------------------------------------------

    <?php
    $username = "morrowasted";
    $password = "[edited]";
    $hostname = "localhost";
    $dbh = mysql_connect($hostname, $username, $password)
    or die("Unable to connect to MySQL");
    print "Connected to MySQL<br>";
    $selected = mysql_select_db("www",$dbh)
    or die("Could not select first_test");
    if (mysql_query("insert into people values('4','$name1','$post1')")) {
    print "successfully inserted record";
    }
    else {
    print "Failed to insert record";
    }
    mysql_close($dbh);

    mysql_close($dbh);

    ?>

    --------------------------------------------------------------------------------



    PHP:
    --------------------------------------------------------------------------------

    <?php
    $username = "morrowasted";
    $password = "[edited]";
    $hostname = "localhost";
    $dbh = mysql_connect($hostname, $username, $password)
    or die("Unable to connect to MySQL");
    $selected = mysql_select_db("www",$dbh)
    or die("Could not select first_test");
    $result = mysql_query("SELECT id, name,post FROM people");
    while ($row = mysql_fetch_array($result,MYSQL_ASSOC)) {
    echo "<div style='background:black;font:10pt;color:white'>";
    echo "<center>";
    print " Name:".$row{'name'}." <br>Comment:
    ".$row{'post'}."<br><br>";
    echo "</center>";
    print "</div>";

    }

    mysql_close($dbh);
    ?>

    --------------------------------------------------------------------------------



    PHP:
    --------------------------------------------------------------------------------

    <html>
    <title> Post Comment </title>
    </head>
    <body bgcolor=black>
    <form action="test.php" method="get">
    Name: <input type="text" name="name1" value="Enter Username"><br>
    Comment: <input type="text" name="post1" value="comment" size="20"><br>
    <input type="submit" value="Post">
    </form>

    --------------------------------------------------------------------------------



    everything works except im getting my "Failed to insert record" error (its not inserting it).
    Last edited by morrowasted; Sep 18th, 2003 at 08:58 PM.

    -morrowasted

  2. #2
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Code:
    mysql_query("insert into people values('4','$name1','$post1')")
    I believe you need to specify field names? Such as:

    Code:
    mysql_query("INSERT INTO people (id, name, post) VALUES ('4','$name1','$post1')")
    Not sure, though. The BEST way to find out what's going on is to do this:

    Code:
    $result = mysql_query("INSERT INTO people (id, name, post) VALUES ('4','$name1','$post1')") 
       or die(mysql_error());
    
    if ($result) {
        //do your cool stuff here...
    } else {
        //echo failed...
    }
    Then the error will tell you exactly what's not right.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  3. #3

    Thread Starter
    Lively Member morrowasted's Avatar
    Join Date
    Aug 2003
    Location
    Houston, TX
    Posts
    118
    thanks!

    -morrowasted

  4. #4
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Was I right about the field names, or was it something else?
    My evil laugh has a squeak in it.

    kristopherwilson.com

  5. #5

    Thread Starter
    Lively Member morrowasted's Avatar
    Join Date
    Aug 2003
    Location
    Houston, TX
    Posts
    118
    yeah, it was the field names.

    -morrowasted

  6. #6
    Frenzied Member
    Join Date
    Nov 1999
    Posts
    1,337
    you don't need field names. but you must have all of the values for every field in that table. by default it will add to all, unless you specify fieldnames.

  7. #7

    Thread Starter
    Lively Member morrowasted's Avatar
    Join Date
    Aug 2003
    Location
    Houston, TX
    Posts
    118
    Originally posted by phpman
    you don't need field names. but you must have all of the values for every field in that table. by default it will add to all, unless you specify fieldnames.
    well, it works, so thats all that matters right now

    -morrowasted

Posting Permissions

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



Click Here to Expand Forum to Full Width