#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2004
    Location
    Marbella, Spain
    Posts
    381
    Rep Power
    0

    Radiobuttons, if empty do...else....does not work, canīt see the error


    Hi,
    Been all day yesterday looking at this code, think im going crazy as it looks correct to me, must me somengthing so stupid that I canīt see it.

    I have one page with a form where one choose between two values in radiobuttons, if one click on the sendbutton without checking any of the buttons, a javascript function is ejectuded telling to choose one of them.
    first the javescript then this code comes:
    PHP Code:
    <?php $propiedad = @mysql_real_escape_string($_POST['propiedad']); $bookingway = @mysql_real_escape_string($_POST['bookingway']); $instant = @mysql_real_escape_string($_POST['instant']); $enquirer = @mysql_real_escape_string($_POST['enquirer']); ?><br> <div class="bookingway"> <form action="bookingways.php" method="post" name="bookingways" id="bookingways" onSubmit="return validate_form2 ( );"> <input type="text" name="propiedad" value="<?php print $propiedad;?>"> <p class="bookingway"> <br> <input name="bookingway" type="radio" value="instant">Instant booking (I have read terms and conditions).<br> <input name="bookingway" type="radio" value="enquirer">Send enquirer or book by email. </p> <p align="center"><input class="boton" type="submit" name="enviar" value="Send"> </p> </form> <br> </div>"]<?php $propiedad = @mysql_real_escape_string($_POST['propiedad']); $bookingway = @mysql_real_escape_string($_POST['bookingway']); $instant = @mysql_real_escape_string($_POST['instant']); $enquirer = @mysql_real_escape_string($_POST['enquirer']); ?> <div class="bookingway"> <form action="bookingways.php" method="post" name="bookingways" id="bookingways" onSubmit="return validate_form2 ( );"> <br> <input type="text" name="propiedad" value="<?php print $propiedad;?>"> <p class="bookingway"> <input name="bookingway" type="radio" value="instant">Instant booking (I have read terms and conditions).<br> <input name="bookingway" type="radio" value="enquirer">Send enquirer or book by email. </p> <p align="center"><input class="boton" type="submit" name="enviar" value="Send"> </p> </form> </div>
    When I choose one and click on the submitbutton I am taking to a controlpage wich checks in php if one of the buttons where checked, if none are checked one should be told in php to check one of them, but if one of them were checked one should be redirected to another page depending on button choosen, however it does not work. I chek one of the buttons and get the errormessage saying me to please choose one of them...
    This is the code on that page:
    PHP Code:
    <?php $propiedad = @mysql_real_escape_string($_POST['propiedad']); $bookingway = @mysql_real_escape_string($_POST['bookingway']); $instant = @mysql_real_escape_string($_POST['instant']); $enquirer = @mysql_real_escape_string($_POST['enquirer']); if ($_POST['enviar']) { if (empty($bookingway)) { echo "Please choose instant booking or send enquirer"; } else{ if ($bookingway=="instant"){ header ("Location: bookingform.php"); } if ($bookingway=="enquirer"){ header ("Location: bookingform.php"); } }//else }//if enviar  ?>"]<?php $propiedad = @mysql_real_escape_string($_POST['propiedad']); $bookingway = @mysql_real_escape_string($_POST['bookingway']); $instant = @mysql_real_escape_string($_POST['instant']); $enquirer = @mysql_real_escape_string($_POST['enquirer']); if ($_POST['enviar']) { if (empty($bookingway)) { echo "Please choose instant booking or send enquirer"; } else{ if ($bookingway=="instant"){ header ("Location: bookingform.php"); } if ($bookingway=="enquirer"){ header ("Location: bookingform.php"); } }//else }//if enviar  ?>
    Any help please,
    thanks
    Last edited by helenp; November 24th, 2012 at 11:57 AM.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2003
    Posts
    3,604
    Rep Power
    595
    1) Please enclose your code in [ PHP ] tags not [ CODE ] tags. See ManiacDan's New User Guide. It would be helpful if you edit your post and include indentation.
    2) Remove the 'mysql_real_escape_string' calls. Since the MySQL extensions are depreciated you should be using PDO and prepared statements so those calls are unnecessary. However, a radio button would not be used in a MySQL query in any case so that much makes no sense and may well be messing up its value.
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2004
    Location
    Marbella, Spain
    Posts
    381
    Rep Power
    0
    Originally Posted by gw1500se
    1) Please enclose your code in [ PHP ] tags not [ CODE ] tags. See ManiacDan's New User Guide. It would be helpful if you edit your post and include indentation.
    2) Remove the 'mysql_real_escape_string' calls. Since the MySQL extensions are depreciated you should be using PDO and prepared statements so those calls are unnecessary. However, a radio button would not be used in a MySQL query in any case so that much makes no sense and may well be messing up its value.
    Thanks, didnt know about the php tag, but its complicated to read that way, suppose have to add line breaks.

    Anyway I donīt get it, the mysql escape I always use as 99% of my php is with mysql, so I just copy and past without thinking. And I have the same code in another page that also has that call with radiobuttons and it works there, strange.
    I deleted the mysql call and it works......thanks a lot.

    What I didnīt know and has not hear about as the site are years old is that mysql statements are deprecated.....and I ever heard about pdo.....does that mean that 'mysql_real_escape_string' doesnīt do anything????
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2003
    Posts
    3,604
    Rep Power
    595
    You didn't do the PHP tags quite right. You can still fix it. Format the code the way you want first. Highlight the PHP code and THEN click the PHP icon.

    As for MySQL extensions, they still work as does 'mysql_real_escape_string' but their use is discouraged. You should be using PDO for any new code you write and as time permits you should should be converting old code to PDO. I found that using OOP and PDO means a lot of my MySQL code could be written and debugged once and sufficiently generalized such that all I needed to do was include it in my php pages as needed. Then programming was a whole lot easier and took less time to debug.
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2004
    Location
    Marbella, Spain
    Posts
    381
    Rep Power
    0
    Originally Posted by gw1500se
    You didn't do the PHP tags quite right. You can still fix it. Format the code the way you want first. Highlight the PHP code and THEN click the PHP icon.

    As for MySQL extensions, they still work as does 'mysql_real_escape_string' but their use is discouraged. You should be using PDO for any new code you write and as time permits you should should be converting old code to PDO. I found that using OOP and PDO means a lot of my MySQL code could be written and debugged once and sufficiently generalized such that all I needed to do was include it in my php pages as needed. Then programming was a whole lot easier and took less time to debug.
    Transform......the site is only about 1000 pages, about 500 pages using only mysql. Really nice.
    I save this thread for when I have time as that is a big thing.....
    I suppose therefor my new host offer 2 clases of php versions.
    Thanks
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2004
    Location
    Marbella, Spain
    Posts
    381
    Rep Power
    0
    Originally Posted by gw1500se
    You didn't do the PHP tags quite right. You can still fix it. Format the code the way you want first. Highlight the PHP code and THEN click the PHP icon.
    Sorry, I tried to fix it, but donīt get how I can get it on several lines, anyway it works, but the code is not readable

IMN logo majestic logo threadwatch logo seochat tools logo