What's wrong with this form?

Discussion in 'PHP' started by Immaboy, May 8, 2009.

  1. #1
    On forms.php:

    <form action="/sendforms.php" method="post" >
    
    <b>Message:</b><br><textarea rows="4" cols="30" name="message"></textarea><br>
    
    <input type="text" name="1" value="1"><br>
    <input type="text" name="2" value="2"><br>
    <input type="text" name="3" value="3"><br>
    <input type="text" name="4" value="4"><br>
    
    <input type="submit" value="Submit your comments">
    
    </form>
    PHP:
    On sendforms.php:

    <?php
    
    $connect = mysql_connect("localhost","root","password"); 
    mysql_select_db(form) or die(mysql_error()); 
    
    $message = $_POST['message'];
    $1= $_POST['1'];
    $2 = $_POST['2'];
    $3 = $_POST['3'];
    $4 = $_POST['4'];
    $ip = getenv("REMOTE_ADDR");
    
    $query = mysql_query("INSERT INTO `formtable` (`message`, `1`, `2`, `3`, `4`) VALUES('$message', '$1', '$2', '$3', '$4')");
    
    echo "<META HTTP-EQUIV='REFRESH' CONTENT='5;URL=javascript:history.go(-1)'> 
    You've sent a form, and will be redirected to the page where you submitted the forms.
    ";
    
    ?>
    PHP:
    Can't get it submitting into my database, any ideas? :(
     
    Immaboy, May 8, 2009 IP
  2. Weirfire

    Weirfire Language Translation Company

    Messages:
    6,979
    Likes Received:
    365
    Best Answers:
    0
    Trophy Points:
    280
    #2
    Your action is "sendcomment.php" and you're trying to process the form on "sendforum.php"
     
    Weirfire, May 9, 2009 IP
  3. Immaboy

    Immaboy Peon

    Messages:
    47
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    That's my mistake, I typed wrongly. :S
     
    Immaboy, May 9, 2009 IP
  4. Weirfire

    Weirfire Language Translation Company

    Messages:
    6,979
    Likes Received:
    365
    Best Answers:
    0
    Trophy Points:
    280
    #4
    try using letters for the variables $one, $two, $three and $four

    Also set the query as a variable

    $qry = "INSERT INTO `formtable` (`message`, `1`, `2`, `3`, `4`) VALUES('$message', '$1', '$2', '$3', '$4')");echo "<META HTTP-EQUIV='REFRESH' CONTENT='5;URL=javascript:history.go(-1)'> You've sent a form, and will be redirected to the page where you submitted the forms.";

    echo $qry;

    $query = mysql_query($qry);

    You can then run the query via PHPMYAdmin which will give you better error reporting.
     
    Weirfire, May 9, 2009 IP
  5. kblessinggr

    kblessinggr Peon

    Messages:
    539
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    0
    #5
    what does mysql_error(); output after the failed query?
     
    kblessinggr, May 9, 2009 IP
  6. Immaboy

    Immaboy Peon

    Messages:
    47
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    It'll show what the error is.

    Thanks everyone, I already got it working.
     
    Immaboy, May 10, 2009 IP
  7. Weirfire

    Weirfire Language Translation Company

    Messages:
    6,979
    Likes Received:
    365
    Best Answers:
    0
    Trophy Points:
    280
    #7
    Glad to hear it! :)
     
    Weirfire, May 14, 2009 IP