Well, this is like my billionth thread in this forum alone. [img_thumb]http://i39.tinypic.com/ncif4x.gif[/img_thumb].
Basically I've got to create a doctors appointment booking system in mysql/php - i've spent the last few days/nights on it and it's coming along really well. I'm pretty much new to php and to mysql, was shitting myself but I'm actually getting the hang of it. So much stuff available on the interweb.
Is it ok if I use this as like a mega thread? Instead of opening a new thread each time I have a problem? that'd be silly.
I have a table in my database called "tblpatients" i want to have a drop down box which gets each "patient" from the table, in the form of "patient_id" and then when the user has selected it, they can delete that "patient"/row from the table.
I've done [I]what i think[/I] is a good enough drop down box but I'm sure i've done it in the wrong method - get instead of post.
[PHP]<?php require_once('config.php'); ?>
<form id="form1" name="form1" method="get" action="<? echo $PHP_SELF; ?> ">
Patient:
<select name="select">
<option value="">--- Select ---</option>
<?
// Get records from database
$list=mysql_query("select * from tblpatient order by patient_id asc");
// Show records by while loop.
while($row_list=mysql_fetch_assoc($list)){
?>
<option value="<? echo $row_list['patient_id']; ?>" <? if($row_list['patient_id']==$select){ echo "selected"; } ?>><? echo $row_list['patient_fname']; ?></option>
<?
// End while loop.
}
?>
</select>
<input type="submit" name="Submit" value="Select" />
</form>
[/PHP]Does that look ok? It works and everything but I've probably done some serious mistake somewhere and it'll shag my sister when I least expect it.
How would I from there, display a sentence like " are you sure you want to delete - patient #(and the patient_id)" and the a yes/no box - yes would get the value from the drop down box(patient_id) and then run a delete statement to delete whatever is in the drop down box?
Do you get what I mean?
If anyone is able to point me in the right direction or put anything that might just help that would be fantastic. I can't thank you enough.:tiphat:
[QUOTE=andersonmat;21210301]Looks okay:
[URL]http://www.shiningstar.net/articles/articles/javascript/confirmsubmit.asp[/URL][/QUOTE]
I've done it totally different, instead of a drop down box, i've done it in a table format and just added an extra column and put a hyperlink in there which runs a delete query based on patient_id. But I've used the link you said, works perfectly. Thank you!
Another question; php headers.
I use sessions to control logins.
I've got this bit of code at the top of all my pages
[PHP]<?php
session_start();
if(!session_is_registered(myusername)){
header("location:index.php");
}
?>[/PHP]
It works perfectly. If you aren't logged in, it redirects you to index.php.
However, since I've started to play around with editing/delete rows, whenever I update/delete a record/row/patient i'd like it to redirect to the page where it just lists all the patients. So I've used
[PHP]// Re-direct this page to updatepatient.php.
header("location:updatepatient.php");
exit;
}[/PHP]
Now, whenever I edit/delete I get the nasty message of "Warning: headers have already been sent"
Is there anyway around this? Without the code which checks you're logged in at the top of the page, anyone is able to view/edit the page :(
I've been looking into javascript redirects but, would that work?
Do you have anything echoed on the page before the header? If so, remove it.
That or you can change how PHP does it. If you keep getting that error, you can have PHP process the entire page before sending it.
[php]
ob_start();
[/php]
I'd recommend the former before messing with output buffering.
[QUOTE=andersonmat;21212614]That or you can change how PHP does it. If you keep getting that error, you can have PHP process the entire page before sending it.
[php]
ob_start();
[/php]I'd recommend the former before messing with output buffering.[/QUOTE]
Strange, a minute ago it wasn't working but now with this:
[PHP]echo '<script type="text/javascript">
<!--
window.location = "updatepatient.php"
//-->
</script>';
exit;[/PHP]It works perfectly.
I did look at ob_flush, but I thought it's a bit too complicated for what I wanted to do.
The javascript one isN'T as "fluid" as the php redirect, you can see there's a gap of like 1/4 second where there's a black page before it redirects, but it works perfectly, thanks!
Well, it's going really well now. Coming to the harder parts now though.
At the moment I've got one problem. Not really a problem but I don't know what to do with it.
In my appointments table, i've got a column called "confirmed" which the admin ticks to say that a user enter appointment has been confirmed. I've used datatype tinyint(1) (0 or 1/yes or no/true or false etc).
How would I show this in the form of a check box? I.e. How would I convert that 0/1 into a value the checkbox understands?
I've worked this out so far:
[PHP] echo "<td>" . "<input name=\"is_confirmed\" type=\"checkbox\" value=\"" . $row['confirmed'] . "\"/>" . "</td>";[/PHP]
and it DOES put either a 0 or 1 in the "value" field, but it doesn't represent it (i.e. become checked if value = 1)
Any ideas?
Love you guis
checked="true" iirc
Tip: you should really open php statements <?php with not <?
[QUOTE=Maccabee;21228939]Tip: you should really close php statements with php?> not ?>[/QUOTE]
Wait what?
Don't do this.
This is how you should open / close php tags:
[php]<?php
// Code goes here
?>[/php]
You can also use <? ?> but that isn't recommended.
[QUOTE=Maccabee;21228939]Tip: you should really close php statements with php?> not ?>[/QUOTE]
another quality post from macfagbee
Yo, I've never ever ever [I]ever[/I] seen a php tag being closed by php?>, I'll think I'll stick with ?> thanks anyway though.
To be honest with you, this is actually going better than I thought.
I might give one of you the a go of it, test it and stuff, maybe some criticism would be nice. It's not perfect, it's possibly really dirty code. This is the first time I've really used php/mysql and I'm really enjoying it.
One more question though.
I've got a user section of the site, and an admin section (/admin). Admin controls everything, whereas the user section has information such as info on the surgery, and an option for them to book an appointment.
I don't want the user to log in, because I don't think I've planned for that and just thinking about it would be really complicated. (i.e. using their session which they've logged in with to show only their details.)
But instead I want something like the user has to enter their patient ID, their date of birth and surname a date and time they would like their appointment.
Is there a way I could do this? I.e. check the patient_id, patient_dob and patient_surname to make sure they are all correct (and for the same patient) and if it is, using the date/time they've given submit the form? (inserting the info into the appointments table where the admin is able to check whether the date/time they wanted is available). I know how to insert data, it's just doing the initial check of their information.
Any help would be fan-fucking-tastic, you're all total darlings for even replying previously
PHP teaches you bad programming techniques in my opinion, anyways.
Just do a query for the info,
[php]SELECT * FROM sometable
WHERE patient_id = '$patient_id' AND
.....[/php]
And then check if it returns anything.
and
[php]time()[/php] to get the current time.
Wow, sorry my bad. I meant open. Open with <?php you're opening with <?. That's what happens when I post on my itouch as soon as I wake up.
I don't know about you, but my brain is in good working order when I just get up.
It's ok, I've been writing php for years so probably would have noticed that it was backwards by now. Just a mistake.
[QUOTE=Maccabee;21236914]It's ok, I've been writing php for years so probably would have noticed that it was backwards by now. Just a mistake.[/QUOTE]
Riiiiiiiiiiiiiiiiiiiiiight.
[QUOTE=Maccabee;21236914]It's ok, I've been writing php for years so probably would have noticed that it was backwards by now. Just a mistake.[/QUOTE]
There is 365 days in a year, not 10.
[QUOTE=Wipmuck;21240891]There is 365 days in a year, not 10.[/QUOTE]
I learned php 2-3 years ago.
[QUOTE=Maccabee;21244087]I learned php 2-3 years ago.[/QUOTE]
No you didn't.
[QUOTE=Maccabee;21244087]I learned php 2-3 years ago.[/QUOTE]
Oh and 'learnt'.
[QUOTE=Maccabee;21236914]It's ok, I've been writing php for years so probably would have noticed that it was backwards by now. Just a mistake.[/QUOTE]
And you wonder why people hate you(even to the extent that you PM them asking why)...
[editline]04:06PM[/editline]
[img]http://imgkk.com/i/8g9h.jpg[/img]
I guess not a lot of people like Maccabee? Can you actually end a statement with php?>?
Anyway,
[QUOTE=Sirkorv;21232135]Just do a query for the info,
[php]SELECT * FROM sometable
WHERE patient_id = '$patient_id' AND
.....[/php]And then check if it returns anything.
and
[php]time()[/php] to get the current time.[/QUOTE]
Yeah, I get that bit but then how would you use that to insert data? I can't seem to get my head around it.
Select * from tblpatients where patient_id = $patient_id and patient_dob = $patient_dob and patient_sname = $patient_sname
but then how would I insert?
Cheers!
[editline]07:49PM[/editline]
[PHP]
IF (EXISTS (SELECT * from tblpatient
where tblpatient.patient_id = $patient_id and tblpatient_dob = $patient_dob and tblpatient.patient_sname = $patient_sname))
insert into tblappointments ( null, $patient_id, $doctor_id, $appointment_date, appointment_time, 'no')[/PHP]
I've just knocked up this, is that on the right lines?
Or am I well off?
(also in the insert statement, tblappointment has a primary key, appointment_id which is auto_incremented by 1 each time, so I'd leave it null, because it would automatically increase it by 1?)
Well when I insert an entry with an Id I normally miss it out and do this:
[php]
INSERT INTO TableName(Username, Email) VALUES ('$Username', '$Email')
[/php]
And it will do it itself.
Ah. I thought as much, thanks for clarifying. I like the way mysql works. It's pretty easy.
Saying that, I haven't got a fucking clue how to do the select/insert statement.. driving me insane :x
[QUOTE=kingzl3y;21250348]I guess not a lot of people like Maccabee? Can you actually end a statement with php?>?
[/QUOTE]
Just 4-5 people who have something against me. And no you can't.
[QUOTE=Dusty_;21249065]And you wonder why people hate you(even to the extent that you PM them asking why)...[/QUOTE]
He PM'ed you too?
[QUOTE=turb_;21256531]He PM'ed you too?[/QUOTE]
He's a loser. v:v:v
[QUOTE=turb_;21256531]He PM'ed you too?[/QUOTE]
No I didn't. I think you are him.
Sorry, you need to Log In to post a reply to this thread.