IF and Radio Buttons

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

    IF and Radio Buttons

    I have the following code which connects to a database and sets the
    value of counter to '0' and the date to be either the current date or a
    users own date. The database connects via an included script as this is
    a contribution for OSCommerce. Each section (the set date today and set
    date custom) works fine by itself (with the other half commented out)
    but I cant make it so the option is available via radio buttons, what am
    I doing wrong?

    Thanks in advance,
    Ben

    P.S. This is the code I am using

    <?php
    include('includ es/application_top .php');
    ?>
    <html>
    <body>
    <?php
    //OS Commerce Counter Reset v0.15
    //Author: Ben Allen

    if ($submit) {
    //Validation
    $flag="OK"; // This is the flag and we set it to OK
    $msg=""; // Initializing the message to hold the error messages
    //Set Query Variables
    $query = "UPDATE counter SET counter = 0";
    $today = date("Ymd");
    $datetoday = "UPDATE counter SET startdate = $today";
    //Set Date=Today
    if ($setdate="true ") {
    $counterquery = mysql_query($qu ery);
    $datequery = mysql_query($da tetoday);
    echo "Counter Reset Succesfully";
    }else{
    //Set Date Custom
    if ($setdate="fals e") {
    //Edit Database:
    $customdate = mktime(0, 0, 0, $month, $day, $year);
    $datecustom = strftime("%Y%m% d", $customdate);
    $datecustomquer y = "UPDATE counter SET startdate = $datecustom";
    $counterquery = mysql_query($qu ery);
    $datecustomresu lt = mysql_query($da tecustomquery);
    echo "Counter Reset Succesfully";
    }
    }else {
    //Display Form
    ?>
    <form method="post" action="<?php echo $PHP_SELF?>">
    <table width="260" border="0" align="center" height="90"> <tr
    align="center" valign="middle" >
    <td height="31"> <div align="right" class="content" >
    <div align="left">
    <input name="setdate" type="radio" value="true">
    Today</div>
    </div>
    <div align="left"> </div></td></tr>
    <tr align="center" valign="middle" > <td height="25"> <div
    align="right">< font color="FBC300"> </font></div>
    <div align="left"><f ont color="FBC300">
    <input name="setdate" type="radio" value="false">
    </font>
    <input name="day" type="text" id="day" size="2" maxlength="2">
    <input name="month" type="text" id="month" size="2"
    maxlength="2">
    <input name="year" type="text" id="year" size="4" maxlength="4">

    (dd/mm/yyyy) </div></td></tr> <tr align="center"
    valign="middle" > <td> <div align="center">
    <input type="Submit" name="submit" value="Enter" class="button"> </div>
    <div align="center"> </div></td></tr> </table>
    <font color="FBC300"> </font></form>
    <?php
    } // end if
    require(DIR_WS_ INCLUDES . 'application_bo ttom.php');
    ?>
    </body>
    </html>
  • Kimmo Laine

    #2
    Re: IF and Radio Buttons

    "Ben Allen" <"ben.allen"@\" your.tonsils\"b tinternet.com> kirjoitti
    viestissä:da8n4 g$6ta$1@nwrdmz0 3.dmz.ncs.ea.ib s-infra.bt.com...[color=blue]
    >I have the following code which connects to a database and sets the value
    >of counter to '0' and the date to be either the current date or a users own
    >date. The database connects via an included script as this is a
    >contribution for OSCommerce. Each section (the set date today and set date
    >custom) works fine by itself (with the other half commented out) but I cant
    >make it so the option is available via radio buttons, what am I doing
    >wrong?
    >
    > if ($setdate="true ") {...
    > if ($setdate="fals e") {...[/color]

    == is the comparison operator, = is assignment. When you assign the string
    "true" to $setdate, of course it is true. Instead you need to compare
    them...

    if ($setdate=="tru e") {...
    if ($setdate=="fal se") {...



    --
    "I am pro death penalty. That way people learn
    their lesson for the next time." -- Britney Spears

    eternal.erectio nN0@5P4Mgmail.c om


    Comment

    • Ben Allen

      #3
      Re: IF and Radio Buttons

      Kimmo Laine wrote:[color=blue]
      > "Ben Allen" <"ben.allen"@\" your.tonsils\"b tinternet.com> kirjoitti
      > viestissä:da8n4 g$6ta$1@nwrdmz0 3.dmz.ncs.ea.ib s-infra.bt.com...
      >[color=green]
      >>I have the following code which connects to a database and sets the value
      >>of counter to '0' and the date to be either the current date or a users own
      >>date. The database connects via an included script as this is a
      >>contributio n for OSCommerce. Each section (the set date today and set date
      >>custom) works fine by itself (with the other half commented out) but I cant
      >>make it so the option is available via radio buttons, what am I doing
      >>wrong?
      >>
      >>if ($setdate="true ") {...
      >>if ($setdate="fals e") {...[/color]
      >
      >
      > == is the comparison operator, = is assignment. When you assign the string
      > "true" to $setdate, of course it is true. Instead you need to compare
      > them...
      >
      > if ($setdate=="tru e") {...
      > if ($setdate=="fal se") {...
      >
      >
      >[/color]
      Brilliant thanks, I knew it had to be some simple newbie mistake, thanks
      once again.

      Ben

      Comment

      Working...