SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    exit();
    Join Date
    Jul 2000
    Posts
    759
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    <BLOCKQUOTE><font size="1" face="Verdana, Arial">code/font><HR><pre>
    &lt;?php

    if($submit) {


    $dbcnx = @mysql_connect("localhost", "user", "password");
    mysql_select_db('database');


    $sql = "INSERT INTO Replies SET " .
    "ReplyText='$ReplyText', " .
    "threadid='$threadid'";


    }

    if (mysql_query($sql)) {

    echo("&lt;P&gt;Thank you for your reply...&lt;/P&gt;");

    } else {

    echo("&lt;P&gt;Uh oh! - " .

    mysql_error() . "&lt;/P&gt;"); }

    ?&gt;

    &lt;?php else: // Allow the user to enter a new author?&gt;


    &lt;FORM ACTION="&lt;?php echo($PHP_SELF); ?&gt;" METHOD=POST&gt;

    &lt;P&gt;Reply Text&lt;BR&gt;
    &lt;TEXTAREA NAME="ReplyText" ROWS=15 COLS=45 WRAP&gt;&lt;/TEXTAREA&gt;
    &lt;P&gt;&lt;INPUT TYPE=SUBMIT NAME="submit" VALUE="SUBMIT"&gt;&lt;/P&gt;
    &lt;/FORM&gt;


    &lt;?php endif; ?&gt;
    [/code]

    What's wrong? It just won't insert it at all I've looked over it a million times too

    ------------------
    WebDevHQ.com - The Web Developer Headquarters! HUNDREDS of articles, reviews tools and more!

    [This message has been edited by Matt Kaufman (edited August 19, 2000).]

  2. #2
    exit();
    Join Date
    Jul 2000
    Posts
    759
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, I got it to post if nothing else is in the database, but when I try and post again it says:


    Duplicate entry '2' for key 1

    and doesn't work



    ------------------
    WebDevHQ.com - The Web Developer Headquarters! HUNDREDS of articles, reviews tools and more!

  3. #3
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Your insert statement is a bit off
    $sql = "INSERT INTO Replies SET " ."ReplyText='$ReplyText', " ."threadid='$threadid'";

    Should be

    $sql = "INSERT INTO Replies "
    ."(ReplyText, threadid) VALUES " .
    "('$ReplyText', '$threadid')";

    That should do the trick

  4. #4
    SitePoint Wizard silver trophy Karl's Avatar
    Join Date
    Jul 1999
    Location
    Derbyshire, UK
    Posts
    4,411
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Freddy, the change you suggested should not make a difference ti the code, as it is the way Kevin has shown in his tutorial and is the better way of doing an Insert as you don't have to remember which way round you listed your variable before the VALUES section.

    Edit:

    Also Matt the error you got is from the table design you have implemented not because of the code above.


    ------------------
    Karl Austin
    KDA Web Services
    "Everyone has a photographic memory. Some just don't have film."

    [This message has been edited by Karl (edited August 20, 2000).]


Bookmarks

Posting Permissions

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