my code erronousely changes the variable

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • george

    my code erronousely changes the variable

    I don't get it. can anyone help me with this ? It's a simple preceding
    checkbox, either yes or no - if yes, add the details to a $db and if
    no, then don't. But I get the original variable being switched from
    yes to no, or from no to yes, and either way, the database gets
    accessed.

    (code page1)
    (snip)
    <SELECT NAME="radiobutt on" SIZE="1"><OPTIO N VALUE="yes" selected>yes
    please</OPTION><OPTION VALUE="no">no thanks</OPTION></SELECT>
    (/snip)(code)


    (code page2)
    -----------
    $cname = $_POST['cname'];
    $sname = $_POST['sname'];
    $radio = $_POST['radiobutton'];
    //collect the radio value
    $mail = "";
    $mail=$radio;
    // see what I've got
    echo $mail;
    //then it is supposed to be yes or no and act accordingly
    if ($mail = "yes") {
    // stick into database
    $host = "(host)";
    $login_name = "(name)";
    $password = "(password) ";
    MySQL_connect(" $host","$login_ name","$passwor d");
    MySQL_select_db ("(database" ) or die("Could not select database");
    $sql = "INSERT INTO (table) ( cname, sname) VALUES
    ('$cname','$sna me')";
    // save the result for later on
    $result = mysql_query($sq l);
    if ($result) {
    $post = "Yes, thanks";
    } else {
    $post = "No";
    }
    }
    // checking what I've got
    echo $mail;

    (/code)
  • Jon Kraft

    #2
    Re: my code erronousely changes the variable

    george <russell@waihek e.co.nz> wrote:
    [color=blue]
    > I don't get it. can anyone help me with this ? It's a simple preceding
    > checkbox, either yes or no - if yes, add the details to a $db and if
    > no, then don't. But I get the original variable being switched from
    > yes to no, or from no to yes, and either way, the database gets
    > accessed.[/color]
    [color=blue]
    > //then it is supposed to be yes or no and act accordingly
    > if ($mail = "yes") {[/color]

    if ($mail == "yes") {

    JOn

    Comment

    Working...