Portion of client's PHP script not working - please help
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Portion of client's PHP script not working - please help
Hello,
I have a client whose web site offers a page where customers can make spa reservations. The PHP script was created by someone else who is no longer working on the site. The client has sent her problem to me but I am the designer not the programmer, so I'm not sure where the problem lies.
She said the section where the customer states their requested appointment day and time (1st choice and 2nd choice) comes up blank on their end.
Can someone please take a look at this pasted PHP script and see if you can detect a problem with those lines? Thank you in advance to anyone who's able to offer some assistance.
The code doesn't tell anything about where it gets its values beyond using the deprecated $_REQUEST global variable, assuming it comes from a POST or even GET request made by a html form, the php code itself doesn't seem to be the problem, more likely the html form (or whatever they're using to send the values) is where the problem lies, maybe it was redesigned or control attributes were changed.
However, the code you posted only leads to assumptions about what might be wrong and where it might be failing so, based on that code, there's not much that one can say to you.
A point of note, the following doesn't seem to have any reason to exist:
Thanks for your response, Acron. Most of it is Greek to me. I really REALLY don't understand PHP. Are you saying that bit of script can simply be removed without disturbing the rest of the code?
And you don't think the problem lies with this PHP code... the way the code is written, the user should be able to submit their desired reservation day and time? So I should be checking the other html file associated with this file instead, is that right?
I just don't know what I'm looking for. I want to tell this client to go find herself a coder to deal with all the little things she brings to me, but I thought maybe it was an easy fix if there was a blip in the code.
It certainly looks like those blocks do nothing. You can follow the logic yourself
Code:
if (mail($to, $subject, $body))
{
#no code here
}
else
{
# or here
}
if (mail(trim($_REQUEST['flg5']), $subject, $body))
{
# or here
}
else
{
# or here either ...
}
reformatted for ease of reading: As you can see nothing happens in the 'to do' blocks..
this could in fact not the production code... certainly I'd hope not...
IMHO, either start learning PHP, might be a handy skill to have and you could get more money by doing all the work, or as you say, tell her to get a programmer...
Thanks for your response, Acron. Most of it is Greek to me. I really REALLY don't understand PHP. Are you saying that bit of script can simply be removed without disturbing the rest of the code?
Indeed, even more when the same "test" process is already covered by a previous IF control structure:
PHP Code:
<?php $to = "emailhere@yahoo.com";
# body construction lines here....
if (mail($to, $subject, $body)) { echo("Request Submitted. You will be contacted by one of our staff for appointment confirmation."); } else { echo("Request Failed. Please try again."); }
That IF does indeed something so the other one shouldn't be there, that's why I think that either that script wasn't intended for production or that someone messed it up
Quote:
Originally Posted by picklepie1
And you don't think the problem lies with this PHP code... the way the code is written, the user should be able to submit their desired reservation day and time? So I should be checking the other html file associated with this file instead, is that right?
The body construction is "ok", could be done better? sure it could, but the point is that there's nothing in the code that explains why 1st and 2nd choices comes blank.
One can assume things as I said earlier but nothing more, so checking other files related to this script will be better.
Quote:
Originally Posted by picklepie1
I just don't know what I'm looking for. I want to tell this client to go find herself a coder to deal with all the little things she brings to me, but I thought maybe it was an easy fix if there was a blip in the code.
To be honest, the script seems pretty old (unless the use of $_REQUEST is done for compatibility issues) and doesn't have the best practices, it kinda looks like written in a hurry or for someone not very savvy with the language so I agree with chrism01 and with you, it will be better that your client find a coder used to the language or if you want, learn php and take the project in your hands.
Whatever you decide, it might be a simple solution in this case, just a matter of checking other related files to send those emails if you want to try that first
$i=0;
while (isset($_REQUEST['opt'.$i])) {
$body = $body."Option: ".$_REQUEST['opt'.$i]."\n";
$i++;
}
Stab in the dark here, but the code above looks a bit suspect but I can only guess. Are there fields in the html form whether they be textbox, checkbox or whatever called opt1, opt2 etc. and if so is there one called opt0 ? If they're isn't then that part of $body string won't get built.
I think I've read it wrong, probably ignore this
Last edited by aspire1; 04-30-2009 at 03:01 AM.
Reason: Misread
$i=0;
while (isset($_REQUEST['opt'.$i])) {
$body = $body."Option: ".$_REQUEST['opt'.$i]."\n";
$i++;
}
Stab in the dark here, but the code above looks a bit suspect but I can only guess. Are there fields in the html form whether they be textbox, checkbox or whatever called opt1, opt2 etc. and if so is there one called opt0 ? If they're isn't then that part of $body string won't get built.
I think I've read it wrong, probably ignore this
Indeed, if there is no optX, those statements in the while structure won't be executed, however, that will just avoid adding "Option: something" to the already defined body, meaning that it won't have any effect in 1st and 2nd choices being empty or not
Thanks to everyone for your comments. Yes, I agree that eventually learning PHP will only help me and market my skills to a expanded audience. At this point, the client needs it fixed so I am just going to let her know she needs to direct the problem to a coder.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.