• PHP/MySQL help :3
    52 replies, posted
lol, if only you knew how wrong you are little child
[QUOTE=Maccabee;21253811]Just 4-5 people who have something against me.[/QUOTE] Try a most of PCHS.
I guess everyone loves mcabeeeeee then:love:. I'm having a fucking annoying problem. I've figured a way how to do it, [CODE]select count(*) from tblpatient where patient_id = '14' AND patient_sname = 'testone' AND patient_dob = '2010-04-28'[/CODE] In the tblpatient table, i've got a a user whose ID is 14, their surname is testone and their dob is 2010-04-28. If I run that query in the phpmyadmin sql executer, it brings back "1" because there's only 1 patient with that information. However, using this code; [php]$sql=mysql_query("select count(*) from tblpatient where patient_id = '14' AND patient_sname = 'testone' AND patient_dob = '2010-04-28'"); if ($sql = '1') { echo "yes, it works! " . $sql . " what"; } elseif ($sql = '0'){ echo "list = zero"; } else { echo "nope, it didnt work because";}[/php] $sql ALWAYS = 1 even when I change patient_id = '15' in the mysql_query (and because there isn't a patient with id 15, whose surname is testone and dob is 2010-04-28... there count(*) should return 0. But it doesn't. Any ideas?
You should do: [php] $queryResults = mysql_fetch_array(mysql_query("select count(*) from tblpatient where patient_id = '14' AND patient_sname = 'testone' AND patient_dob = '2010-04-28'")); // then test if($queryResults[0] == 1){ echo "yep"; } [/php]
For fuck sake. I can't thank you enough. It works magically. You're awesome. I've came up with this, what do you think? [php]<?php $patient_id = $_POST[ 'patient_id' ]; $patient_sname = $_POST[ 'patient_sname' ]; $patient_dob = $_POST[ 'patient_dob' ]; $doctor_id = $_POST[ 'doctor_id' ]; $appointment_date = $_POST[ 'appointment_date' ]; $appointment_time = $_POST[ 'appointment_time' ]; $queryResults = mysql_fetch_array(mysql_query("select count(*) from tblpatient where patient_id = '$patient_id' AND patient_sname = '$patient_sname' AND patient_dob = '$patient_dob'")); if($queryResults[0] == 1){ $query = "insert into tblappointments values ( NULL, '$patient_id', '$doctor_id', '$appointment_date', '$appointment_time', 'yes')"; $results = mysql_query( $query ) or printf( "Query error: %s", mysql_error() ); echo "Congratulations, you appointment has been successfully inserted. You will get a confirmation email once we check the date/time you requested is free. "; } else { echo "Please check the data you entered. Appointment not submitted."; } ?> <form action="<?php $PHP_SELF; ?>" method="POST" enctype="multipart/form-data" name="myform"><shitformystuff> </form>[/php] [editline]10:18PM[/editline] Also: In the above form, you've got to select a doctor_id (because it's a foreign key in the tblappointments table). I'm using a dropdown box to show all the ID's of the doctors. Is there a way I could not show ID's and just show names instead? BUT still enter the doctor_id? (instead the name..) If that makes sense!
You need to use [php] echo "<option value=".$Doctor_Id.">".$Doctor_Name."</option>"; [/php] In your Select tags.
how would I incorporate that into this? [php]<option value="<? echo $row_list['doctor_id']; ?>" <? if($row_list['doctor_id']==$select){ echo "selected"; } ?>><? echo $row_list['doctor_id']; ?></option>[/php] I can't get my head around it!
[php] <option value="<? echo $row_list['doctor_id']; ?>"><? echo $row_list['doctor_id']; ?></option> [/php] Something like this?
[QUOTE=Zaldos;21273416][php] <option value="<? echo $row_list['doctor_id']; ?>"><? echo $row_list['doctor_id']; ?></option> [/php]Something like this?[/QUOTE] I think you meant this [php] <option value="<? echo $row_list['doctor_id']; ?>"><? echo $row_list['doctor_name']; ?></option> [/php] and you were fucking spot on. Thanks man!
Ye. Need to sleep. That's why.
[QUOTE=Zaldos;21274050]Ye. Need to sleep. That's why.[/QUOTE] I understand mate. Thanks a lot. You've made it look a lot better. I've got a 11 hour shift in 7 hours but this is more important atm, 'nuff no sleep tonight. I've got one more question and then I've gotta sort out the email part of it, which is pretty straight forward. -snip-
I've figured out a way how to check that they appointment they want is either free or not. This is what I've got so far: [php]<?php $queryResults = mysql_fetch_array(mysql_query("select count(*) from tblpatient where patient_id = '$patient_id' AND patient_sname = '$patient_sname' AND patient_dob = '$patient_dob'")); $querytest=mysql_query("SELECT count(*) as testcount FROM tblappointments WHERE doctor_id='$doctor_id' and appointment_date='$appointment_date' and appointment_time='$appointment_time'") or die ('Problem checking appointment availability query.'); $testrow=mysql_fetch_assoc($querytest); if ($testrow['testcount'] >= 1){ echo "Appointment is not available"; } elseif ($testrow['testcount'] =0 && $queryResults[0] == 1) { $query = "insert into tblappointments values ( NULL, '$patient_id', '$doctor_id', '$appointment_date', '$appointment_time', 'no')"; $results = mysql_query( $query ) echo "<h3>Congratulations you appointment has been successfully inserted You will get a confirmation email once we check the date time you requested is free.</h3>"; } elseif ($testrow['testcount'] ==0 && $queryResults[0] ==0) { echo "<h3>Error: Appointment is available but the details you supplied were not valid. Please check them. Appointment not submitted.</h3>"; } elseif ($testrow['testcount'] ==1 && $queryResults[0] ==1) { echo "<h3>Error: The appointment date and time you requested is already taken. Please try a different date/time"; } else { echo "Error.. no idea why!"; } ?> [/php] I've checked the squiggly brackets, semi-colons, everything.. but i'm still getting [B][B]Parse error[/B]: syntax error, unexpected T_ECHO in [B]blah blah[/B] on line [B]147[/B] [/B]Line147 is the "echo "<h3>Congratulations you appointment has been successfully inserted You will get a confirmation email once we check the date time you requested is free.</h3>";" part in the first ELSE/IF block Any ideas? [editline]12:12AM[/editline] oh, i've fixed it! I think I was missing a semi colon on line 12 above, after $results = mysql_query( $query ) Sorry!
I think I can speak for all of us. We're not here to debug your code for you. You can ask us general questions but don't keep posting stuff asking for us to debug it. It's what trial and error is for [and also Google].
I always say this: If you have a weird bug, you're fine. If you have a syntax error, you haven't learnt nearly enough
You're missing a ; on line 12 at the end of mysql_query().
[quote=kingzl3y;21296558] oh, i've fixed it! I think i was missing a semi colon on line 12 above, after $results = mysql_query( $query ) sorry![/quote] [quote=md1337;21307987]you're missing a ; on line 12 at the end of mysql_query().[/quote]
Thanks. I understand what you're saying. I wasn't going to post the last question, but had spent about 2 hours fucking around with it and then I just thought "2 sets of eyes are better than one". But I know syntax errors are for me to fix not for you to search for. I'm glad I thought it and wasn't more of a nuisance. I'm pretty sure you'll be glad to hear that I've almost finished it. I'm on to the last thing I want to implement, confirmation email. A patient requests an appointment, this is then verified by the admin who updates the 'confirmed' column from 'no' to 'yes' to say that it has been confirmed. How would I get the email address from the tblpatients table, link that to the patient_id in the tblappointments table? I know how to send mail in php, so that's not a problem. It's just getting the relevant email address from the table i'm stuck on Thanks, sorry and thanks!
Come one you can figure this out.
[QUOTE=Zaldos;21312707]Come one you can figure this out.[/QUOTE] you were so right. I was looking at some hardcore shit [php] while ($row = mysql_fetch_array($result)){ $patient_number = $row['patient_id']; }[/php] and then [php]while ($rows = mysql_fetch_array($resultsss)){ $email = "<a href='mailto:" . $rows['patient_email'] . "'>" . $rows['patient_email'] ."</a>"; }[/php].. after having a think about how fucking wrong it was.. [php]$result=mysql_query("select tblappointments.* , tblpatient.* from tblappointments, tblpatient where tblappointments.appointment_id='$appointment_id' AND tblpatient.patient_id=tblappointments.patient_id"[/php] [php]<? echo $row['patient_email']; ?>[/php] what a dick. Sorry for wasting your time. Thanks though.
How many queries do you have on a page. You may want to think about efficiency.
I like to do as much computation as possible on the database server :v:
Hmmm.. I'm about done. Reservations, appoinemnts, patients, testing, validation, authentication, php mail, mysql database. I've done pretty well considering I only started it a week ago today. And it's mostly down to you lot, thanks so much. Really do appreciate it. I'll give you the address sooner or later, just don't want anyone to break it (have tested for sql injections or prevented it either) and I'm not up for doing it all again :( On a slightly unrelated note. [quote] This MySQL server has been running for 11 days, 10 hours, 48 minutes and 17 seconds. It started up on Apr 02, 2010 at 11:19 AM.[/quote][quote] Server traffic: These tables show the network traffic statistics of this MySQL server since its startup[B].[/B][/quote].. [quote] Query statistics: Since its startup,:frogsiren:[B] 20,636,649 queries have been sent to the server.[/B]:frogsiren:[/quote] that can't be good, right?
:wtc:
Sorry, you need to Log In to post a reply to this thread.