0

Hi I have created a function whereby the appointment slot times selected using checkboxes on a previous page are added to my database, at the same time the slot times are stored stored so they can be used further down the page in my mail function.

$savedData = array();
foreach ($_POST as $key=>$value)
{       $key = mysql_real_escape_string($key);
        echo($key. "<br>"); // show times selected on previous page
        mysql_query("INSERT INTO appointment(Patient_ID, Appointment_Date, Appointment_Time
            , Practice_ID, Appointment_ID)
            VALUES('$patid','$insertdate','$key','$pracid','$apptype')");   
        //To save the variables for later:
        $savedData[] = $key;
}

I now need to use the slot times the user has selected to identify the appointment number which has been autogenerated when they were inserted into my database, the code I have tried to use is as follows:

        $insertedapps = mysql_query("SELECT * FROM appointment 
        WHERE Appointment_Date='".$insertdate."' 
        AND Appointment_Time='".$key."'");
        while($row3 = mysql_fetch_array($insertedapps))
    {   $appno = $row3['Appointment_No.'];
    }

Mail Function:

$to = "$pemail";
       $subject = "Booking Confirmation";
       $message = "Hello $pfname 
       This e-mail is to confirm your $appname appointment has been booked for the below times for $insertdate at the the following time(s) below:
       Appointment No:      Appointment Time:
       $appno[0]            $savedData[0]
       $appno[1]            $savedData[1]
       $appno[2]            $savedData[2]
       $appno[3]            $savedData[3]
       The above appointment(s) are booked at the $pracname practice
       Should you wish to alter this appointment please login via our customer login page or contact us on $pracphone";
       $from = "[email protected]";
       $headers = "From:" . $from;
       mail($to,$subject,$message,$headers);
       echo "Mail Sent.";

The appointment time's print out fine but I do not get the results for the appointment numbers... can someone point me in the right direction with where I am going wrong?

4
  • Not sure if it is the cause of your issue (think I need more details for that) but you appear to be getting one row from the appointment table and then looping through that row. So $appno[3] is probably the practice id rather than the 3rd appointment Commented Mar 6, 2013 at 12:36
  • +1 for the dot in the end and for the []. I think PHP has to thrown errors for those two? Commented Mar 6, 2013 at 12:36
  • A period at the end of the key works, it's still a string! Try it here: codepad.org/Z9sLVBBw But for mysql columns this is true. Commented Mar 6, 2013 at 12:39
  • yes sorry guys you are right the field is not Appointment_No. it is Appointment_No I have changed this now and I'm getting something back: Appointment No: Appointment Time: 3 14:00:00 8 14:15:00 3 14:30:00 14:45:00 the appointment numbers are incorrect for the times shown but 383 is the actual appointment no. of the final inserted appointment @ 14:45:00 Commented Mar 6, 2013 at 12:44

3 Answers 3

1

$appno = $row3['Appointment_No.'];

Will reinitialize the $appno variable every time. So it will never contain 4 values, use $appno[] for that.

Also, what is $row3['Appointment_No.']? I assume it's an auto_increment field, but as was pointed out in the comments, that period . cannot be there. Maybe a typo?

Sign up to request clarification or add additional context in comments.

Comments

0

Use $appno[] instead of $appno

Comments

0

as I see you are using double quotes (") and the do not like arrays =D. Put your array variables inside curly brackets like this:

{$appno[0]}

Have to work =)

2 Comments

This isn't true. You only need the braces if the subscript is not a literal.
True sorry about that. Should have tested it first!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.