Page 2 of 2 FirstFirst 12
Results 11 to 19 of 19

Thread: form redirect

  1. #11
    Join Date
    Jul 2006
    Posts
    497
    Thanks
    8
    Thanked 70 Times in 70 Posts

    Default

    What's the exact error message? The parens look wrong to me, but I can't tell you for sure.
    -- Chris
    informal JavaScript student of Douglas Crockford
    I like wikis - a lot.

  2. #12
    Join Date
    Jul 2008
    Posts
    81
    Thanks
    38
    Thanked 2 Times in 2 Posts

    Default

    MY FORM:
    PHP Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <
    html xmlns="http://www.w3.org/1999/xhtml">
    <
    head>
    <
    meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <
    title>database first try</title>
    </
    head>

    <
    body>
    <
    form method="post" action="add2.php">
    <
    table>
    <
    tr>
    <
    td>link url:</td>
    <
    td><input name="link_url" type="text" /></td
    </
    tr>
    <
    tr>
    <
    td>link name:</td>
    <
    td><input name="link_name" type="text" /></td>
    </
    tr>
    <
    tr>
    <
    td>choose:</td>
    <
    td>
          <
    select name="selectgrade"
            <
    option value="option_a">A</option
            <
    option value="option_b">B</option
            <
    option value="option_c">C</option
            <
    option value="option_d">D</option
          </
    select>  
    </
    td>
    </
    tr>
    </
    table>
    <
    input type="submit" value="sumbit" />
    </
    form>
    </
    body>
    </
    html
    add2.php:
    PHP Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>database first try</title>
    </head>

    <body>
    <?php

    $connection 
    mysql_connect("localhost",
                                
    "XXX",
                                
    "XXX");
    if (!
    $connection)
      die(
    'Could not connect: ' mysql_error());

    mysql_select_db("XXX"$connection);

    $sql="INSERT INTO links (link_url, link_name, selectgrade)
    VALUES
    ('
    $_POST[link_url]','$_POST[link_name]','$_POST['selectgrade']')";

    if (!
    mysql_query($sql,$connection))
      die(
    'Error: ' mysql_error());


    echo 
    "1 record added";

    mysql_close($connection);
    ?>

    </body>
    </html>
    What I've tried to do is to get the selected value and insert it into a database.

  3. #13
    Join Date
    Jul 2006
    Posts
    497
    Thanks
    8
    Thanked 70 Times in 70 Posts

    Default

    Thank you for posting the entire source, but what's the error message?
    -- Chris
    informal JavaScript student of Douglas Crockford
    I like wikis - a lot.

  4. #14
    Join Date
    Jul 2008
    Posts
    81
    Thanks
    38
    Thanked 2 Times in 2 Posts

    Default

    Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING

  5. #15
    Join Date
    Jul 2006
    Posts
    497
    Thanks
    8
    Thanked 70 Times in 70 Posts

    Default

    The code you originally said was causing the problem was
    Code:
    $sql="INSERT INTO grades (selectgrade)
    VALUES
    ('$_POST['selectgrade']')";
    But if that line became this
    Code:
    $sql="INSERT INTO links (link_url, link_name, selectgrade)
    VALUES
    ('$_POST[link_url]','$_POST[link_name]','$_POST['selectgrade']')";
    then change it to this
    Code:
    $sql="INSERT INTO links (link_url, link_name, selectgrade)
    VALUES
    ('{$_POST['link_url']}','{$_POST['link_name']}','{$_POST['selectgrade']}')";
    See the second code-section at http://www.php.net/manual/en/languag...string.parsing.
    -- Chris
    informal JavaScript student of Douglas Crockford
    I like wikis - a lot.

  6. #16
    Join Date
    Jul 2008
    Posts
    81
    Thanks
    38
    Thanked 2 Times in 2 Posts

    Default

    Hi thank you,
    now there are no errors, but still it doesn't insert it in the right way. All the values from the select menu turned into 0 in the database.

  7. #17
    Join Date
    Jul 2006
    Posts
    497
    Thanks
    8
    Thanked 70 Times in 70 Posts

    Default

    Try this anywhere in that script and report the output:
    Code:
    var_dump(isset($_POST['selectgrade']));
    var_dump($_POST['selectgrade']);
    -- Chris
    informal JavaScript student of Douglas Crockford
    I like wikis - a lot.

  8. The Following User Says Thank You to Jesdisciple For This Useful Post:

    lord22 (08-07-2008)

  9. #18
    Join Date
    Oct 2006
    Posts
    183
    Thanks
    0
    Thanked 11 Times in 11 Posts

    Default

    I think it might have something to do with your single quotes. Here is the way it would be saved.

    Code:
    $sql="INSERT INTO grades (selectgrade) VALUES ('$_POST['selectgrade']')";
    Try this:
    Code:
    $grade = $_POST['selectgrade'];
    $sql="INSERT INTO grades (selectgrade) VALUES ('{$grade}')";
    Also as to the problem with changing to 0, make sure that the field in the DB is set to text/varchar and not int.

  10. The Following User Says Thank You to motormichael12 For This Useful Post:

    lord22 (08-07-2008)

  11. #19
    Join Date
    Jul 2008
    Posts
    81
    Thanks
    38
    Thanked 2 Times in 2 Posts

    Default

    Thank you very much!!
    Now it is working

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
  •