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 4 of 4
  1. #1
    New Coder
    Join Date
    Oct 2008
    Posts
    30
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Form problem / updating

    hi,

    i have a simple php form, to enter names, email, etc. When submitted it will insert data into DB and show a page that has a newsletter "radio" button. when click on the radio button, it will update the inserted data before to inlcude newsletter (Y/N)..

    but i cant seem to update the last record to apply the radio button...

    i have 2 php scripts....

    first one to insert normal data...
    PHP Code:
    <html>
    <head>
    <title>PHP and Forms</title>
    </head>
    <body>

    <?php
    //connect to server
    $conn mysql_connect("localhost","admin","");
    if(!
    $conn){
        die(
    "Connection Failed: " .mysql_error());
            }
            
    //connect to database
    mysql_select_db("activity4",$conn);

    //inserting data into table 'mycustomers'
    $sql "INSERT INTO customers (gname,fname,email)
    VALUES
    ('$_POST[gname]','$_POST[fname]','$_POST[email]')"
    ;

    $result mysql_query($sql,$conn);

    $cookieID mysql_insert_id();

    //set customer ID as a COOKIE
    setcookie('customerid'$cookieID);
    echo 
    $_COOKIE['customerid'];

    ?>

    <form method="post" action="part3form2.php">

    <br>
    Newsletter?? <input type="radio" name="newsletter">
    <br>
    <input type="submit" name="submit" value="Submit">
    <input type="reset" name="reset" value="Reset">

    </form>


    </body>
    </html>
    and the second to update data to apply newsletter (Y/N)...

    PHP Code:
    <?php

    //connect to server
    $conn mysql_connect("localhost","admin","");
    if(!
    $conn){
        die(
    "Connection Failed: " .mysql_error());
            }
            
    //connect to database
    mysql_select_db("activity4",$conn);

    $newsletter $_POST['newsletter'];
    $id $_POST['customerid'];

    //updating data into table 'mycustomers'
    $sql mysql_query("update customers set newsletter='$newsletter' where customerid='$id'");

    $result mysql_query($sql,$conn);

    echo 
    "Your Customer ID is: " mysql_insert_id();

    ?>
    still learning php and dont have the knowledge to figure it out. can someone please point out what i'm doin wrong.

    Cheers for the help everyone

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,865
    Thanks
    160
    Thanked 2,224 Times in 2,211 Posts
    when click on the radio button, it will update the inserted data before to inlcude newsletter (Y/N)..
    Don't you need two radio inputs then?, like

    Code:
    <input type="radio" name="newsletter" value="Yes"> Yes
    <input type="radio" name="newsletter" value="No"> No
    and then the php side like
    PHP Code:
    if(isset($_POST['newsletter']))
     { 
       if(
    $_POST['newsletter'] == "Yes")
        
    $newsletter='Y';
       else
        
    $newsletter='N';
      
    $sql mysql_query("update customers set newsletter='$newsletter' where customerid='$id'");

    $result mysql_query($sql,$conn) or die(mysql_error());


    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #3
    New Coder
    Join Date
    Oct 2008
    Posts
    30
    Thanks
    5
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by abduraooft View Post
    Don't you need two radio inputs then?, like

    Code:
    <input type="radio" name="newsletter" value="Yes"> Yes
    <input type="radio" name="newsletter" value="No"> No
    I'v got the submit button and reset button there, so i guess if i click on the radio button then submit, logically that means yes. and if i dont click on the button and submit it , thats a no. Do i have to write up a function for that???

  • #4
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    Just use the code that abduraooft was so kind to write up for you. You want two radio buttons, one for yes and one for no.


  •  

    Posting Permissions

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