Welcome to Dream.In.Code
Become a PHP Expert!

Join 136,898 PHP Programmers for FREE! Get instant access to thousands of PHP experts, tutorials, code snippets, and more! There are 1,715 people online right now. Registration is fast and FREE... Join Now!




Check to make sure person entered the correct value in a form and if n

 
Reply to this topicStart new topic

Check to make sure person entered the correct value in a form and if n

inf4my
16 Mar, 2008 - 10:20 AM
Post #1

New D.I.C Head
*

Joined: 19 Nov, 2007
Posts: 23


My Contributions
Right now I have some code that takes input from a calendar and adds into a database and checks if the info is already in there for that time slot..but I want to set it up so that you can only make the time '00' or '30' so its in 30 min intervals, but the check isnt working..here is my current code.
CODE

       <?php    
        $host="localhost"; // Host name

        $username="root"; // Mysql username

        $password="original"; // Mysql password

        $db_name="cutting_edge"; // Database name

        $tbl_name="appoint"; // Table name
        
        // Connect to server and select databse.

        mysql_connect("$host", "$username", "$password")or die("cannot connect");

        mysql_select_db("$db_name")or die("cannot select DB");



        if($_POST[ok])

        {

      $date = "$_POST[month]-$_POST[day]-$_POST[year]";
          $name = $_POST['name'];
          $time = "$_POST[hour]:$_POST[minute]";
          $min = $_POST['minute'];
          
          if(($min != '00') || ($min != '30')){
            echo "Appointments are every 30 minutes please re-choose your time to accommodate this schedule";
            echo $min;
          }
          else{
            // To protect MySQL injection (more detail about MySQL injection)

            $date = stripslashes($date);

            $name = stripslashes($name);

            $date = mysql_real_escape_string($date);

            $name = mysql_real_escape_string($name);
            $time = stripslashes($time);

            $time = mysql_real_escape_string($time);



            $sql="SELECT * FROM $tbl_name WHERE date='$date' and time='$time'";
            $result=mysql_query($sql);
          
            $count=mysql_num_rows($result);
          
            if( $count == 0){

              $sql ="INSERT INTO appoint VALUES( '$date', '$time', '$name' )";
              mysql_query($sql);
              
              echo "$name, Scheduled an appointment for $time on $date";
             }
            else{
              echo "An Appointment Is already Scheduled for this time ";
              echo $time;
             }
           }
         }
?>

User is offlineProfile CardPM
+Quote Post

JBrace1990
RE: Check To Make Sure Person Entered The Correct Value In A Form And If N
16 Mar, 2008 - 10:40 AM
Post #2

D.I.C Regular
Group Icon

Joined: 9 Mar, 2008
Posts: 477



Thanked: 22 times
Dream Kudos: 350
My Contributions
CODE
if($min == '00'){
//code to be executed
}elseif($min == '30'){
//code to be executed
}else{echo "Appointments are every 30 minutes please re-choose your time to accommodate this schedule";
echo $min;}


that's one way to do it.... probably not the best way, but it should work =)

This post has been edited by JBrace1990: 16 Mar, 2008 - 10:40 AM
User is offlineProfile CardPM
+Quote Post

mocker
RE: Check To Make Sure Person Entered The Correct Value In A Form And If N
16 Mar, 2008 - 03:58 PM
Post #3

D.I.C Regular
Group Icon

Joined: 14 Oct, 2007
Posts: 259



Thanked: 15 times
Dream Kudos: 25
My Contributions
In your original code, you need to change the OR to AND..
(($min != '00') || ($min != '30'))
to
(($min != '00') && ($min != '30'))

otherwise it matches everything, including 30 and 00

what JBrace posted is just the opposite check, there really is no point in using it since they are both pretty much the same, you just needed to switch the ||

as an aside, JBrace, it seems pretty silly to put two identical code blocks in an elseif, you could just do
if(($min == '00') || ($min == '30)){
//code to be executed
}
else{ //other stuff
}
User is offlineProfile CardPM
+Quote Post

JBrace1990
RE: Check To Make Sure Person Entered The Correct Value In A Form And If N
16 Mar, 2008 - 04:22 PM
Post #4

D.I.C Regular
Group Icon

Joined: 9 Mar, 2008
Posts: 477



Thanked: 22 times
Dream Kudos: 350
My Contributions
i was half asleep when i wrote that tongue.gif

but it would work lol, so when I said it wasn't the best way, i was still right ^^"
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/3/08 09:30PM

Live PHP Help!

PHP Tutorials

Reference Sheets

PHP Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month