Web Hosting Vodahost    

Home Take The Royal Tour! Order Now Features Prices
Go Back   Web Hosting > VodaHost Web Hosting Support > mySQL & PHP

Notices

mySQL & PHP Discussions, information and help with mySQL and PHP.

Reply
 
LinkBack Thread Tools
  #1  
Old 08-23-2006, 11:35 AM
econstas's Avatar
Second Lieutenant
 
Join Date: Jul 2006
Location: Durham, NC
Posts: 101
Send a message via AIM to econstas Send a message via MSN to econstas
Default Php coding help

All,
I would like to know where I could find a good tutorial for php. I learning this language..and I run into problems.

Probably easy:
$choice1= $HTTP_POST_VARS['choice1'];
$choice2= $HTTP_POST_VARS['choice2'];
$choice3= $HTTP_POST_VARS['choice3'];

$ch1=strlen($choice1);
$ch2=strlen($choice2);
$ch3=strlen($choice3);

if ($ch1 == 0 || $ch2 == 0 || $ch3 == 0)
{
echo "One of your fields is missing. Please use the Back Button to return to the form. Thank you!\n";
exit;
}



Basically I have created a form: http://www.holleyjohnson.net/Holidaymusic.html

I am working on the choices / time options for this form.. I would like to make it easier for down the road incase I need to add more choice options. I don't want to continously add if statements, becausethis code can get very long.

Ideas?

Thanks
Stratis
Website: www.holleyjohnson.net
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #2  
Old 08-23-2006, 02:47 PM
Andy128's Avatar
Major General
 
Join Date: Dec 2005
Location: Michigan
Posts: 2,282
Default Re: Php coding help

The problem I can see with this is that your customer will become frustrated with being given an error statement but no specific remedy. As you say- your list can be very long. If one statement is to cover 8 fields- then potentially- they could be given a generic error statement several times with out knowing exactly how to fix it.

I prefer echo error statements because they are easier than creating an entire page dedicated to one error. Additionally- I make them specific to each field.

Just a thought

Andy
__________________
My diamond in the rough - www.123gpp.com

* Click here for some BV tutorials (Php mailto Form, I-Frames, Picture display and much, much more!)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #3  
Old 08-23-2006, 07:50 PM
navaldesign's Avatar
General & Forum Moderator
 
Join Date: Oct 2005
Location: Italy
Posts: 9,288
Default Re: Php coding help

The echo statement only provides a blank page with the error message. Not very nice. What i think is needed here is:
1. A loop, that will look at array keys, to see which fields are related to the name "choice". This can easily be done by only considering the first 7 letters of the $key, and attributing an incrementing index to the variable. The second part inside the loop, will be the validation.
2. A second loop, for the second group of choices, of similar type.

Consequently, if a validation error is found, the error gets a number, equal to the index itself.
If you put the validation script in the beggining of the same page as the form, and the form calls itself as action, with a double if() statement, the first to see if the fields had already been filled in or not, and the second to check if there are any errors or not, and if there are, print ALL the errors in a pre-deternined text box, your work could be done with a very elegant and short code but you need to know some php to accomplish this.
__________________
Navaldesign
Logger Lite: Low Cost, Customizable, multifeatured Login script
Instant Download Cart: a Powerfull, Customized, in site, DB driven, e-products Cart
DBTechnosystems.com Forms, Databases, Shopping Carts, Instant Download Carts, Loggin Systems and more....
Advanced BlueVoda Form Processor : No coding form processor! Just install and use! Now with built in CAPTCHA!

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #4  
Old 08-24-2006, 03:02 AM
Andy128's Avatar
Major General
 
Join Date: Dec 2005
Location: Michigan
Posts: 2,282
Default Re: Php coding help

Yeah- what he said.
__________________
My diamond in the rough - www.123gpp.com

* Click here for some BV tutorials (Php mailto Form, I-Frames, Picture display and much, much more!)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #5  
Old 08-24-2006, 09:14 AM
econstas's Avatar
Second Lieutenant
 
Join Date: Jul 2006
Location: Durham, NC
Posts: 101
Send a message via AIM to econstas Send a message via MSN to econstas
Default Re: Php coding help

Yeah, I come from a PERL background. Do you know of any good places to learn some PHP? Tutorials / books ??

I was thinking of doing something similar on the option with loops to figure out If they are filled and not. If not, a value is given. Then at the end any values created will be printed onto the screen so the customer would know the problems. If all filled then onto the next step ...
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #6  
Old 08-24-2006, 09:51 AM
navaldesign's Avatar
General & Forum Moderator
 
Join Date: Oct 2005
Location: Italy
Posts: 9,288
Default Re: Php coding help

Quote:
Originally Posted by Andy128
Yeah- what he said.
Hi Andy, this is what i mean:


Particular conditions require particular soloutions. The validating part of script could be based in loops so if in the future he adds more options, it will automatically take them into account.
__________________
Navaldesign
Logger Lite: Low Cost, Customizable, multifeatured Login script
Instant Download Cart: a Powerfull, Customized, in site, DB driven, e-products Cart
DBTechnosystems.com Forms, Databases, Shopping Carts, Instant Download Carts, Loggin Systems and more....
Advanced BlueVoda Form Processor : No coding form processor! Just install and use! Now with built in CAPTCHA!

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #7  
Old 08-24-2006, 11:03 AM
econstas's Avatar
Second Lieutenant
 
Join Date: Jul 2006
Location: Durham, NC
Posts: 101
Send a message via AIM to econstas Send a message via MSN to econstas
Default Re: Php coding help

Wow, I haven't seen flow charts since my programming days in school.. :) Its been awhile.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #8  
Old 08-24-2006, 04:26 PM
Andy128's Avatar
Major General
 
Join Date: Dec 2005
Location: Michigan
Posts: 2,282
Default Re: Php coding help

Navaldesign-
I am but a pup in the php field- I have lots to learn. Thanks for showing me another thing to learn.

Quote:
Yeah- what he said
I was just being funny in that -it was way over my head.

I must disagree with the echo statement method though. Instead of a balnk page one could put the php script inside an html box and place it in the middle of a regular web page matching the theme of ones website. It doesn't have to be a blank page. I prefer this to having to make up several error pages. One draw back is that you cannot have a header re-direct as was recently discussed on this forum. Because the echo statement is output to the browser- if you then have a header redirect it gives an error. In that instance I have to use -
Quote:
echo'<meta http-equiv="refresh" content="0; URL =location:http://whateverpage.com"/>';
which is not as clean as the header redirect.

again Navaldesign- thaks a bunch for all you help with php that you have given.

Andy
__________________
My diamond in the rough - www.123gpp.com

* Click here for some BV tutorials (Php mailto Form, I-Frames, Picture display and much, much more!)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #9  
Old 08-25-2006, 12:11 PM
econstas's Avatar
Second Lieutenant
 
Join Date: Jul 2006
Location: Durham, NC
Posts: 101
Send a message via AIM to econstas Send a message via MSN to econstas
Default Re: Php coding help

I was able to incorporate some loops into the script. I like to look a script and break it down. Now, its basically piece by piece.. :(




$choice[1]= $HTTP_POST_VARS['choice1'];
$choice[2]= $HTTP_POST_VARS['choice2'];
$choice[3]= $HTTP_POST_VARS['choice3'];
$max=3;



for ( $counter = 1; $counter <= $max; $counter += 1){

if (strlen($ch[$counter]) == 0){
echo "test $ch[$counter] = false\n";
}else {
echo "test $ch[$counter] = true\n";
}
}


I got this part to work.. its very basic.. but it works for the time. I will have to look more into the code. I am thinking of adding something like:
every false statement create another array .e.

$false[$f]=" Field $choice[$choice] needs to be filled\n";
$f+=1;

Then set another for loop after all the work is done and run the loop that will print out all false statements. Thinking on the code itself.


Thanks again,
Stratis
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #10  
Old 08-25-2006, 04:09 PM
navaldesign's Avatar
General & Forum Moderator
 
Join Date: Oct 2005
Location: Italy
Posts: 9,288
Default Re: Php coding help

As said above, create another loop that will grab not only ALL the choices but all required fields as well. Th e key to this is that :
1. You get a -R f.e. in your field names: choice1-R where -R stands for required.
2. The script will look for the last two characters in the $key variable, so if a field is required, it will perform the validation, if not, it won't.
3. The same loop will create an array with all the required fields for which it has not found a value, as well as relevant error messages, so, according to the flow chart posted above, it will submit to itself, so it can then, when reloaded, grab again the variables, as well as the error messages, and display them in an appropriate textbox, or empty the fields and print the field titles in another colour.
__________________
Navaldesign
Logger Lite: Low Cost, Customizable, multifeatured Login script
Instant Download Cart: a Powerfull, Customized, in site, DB driven, e-products Cart
DBTechnosystems.com Forms, Databases, Shopping Carts, Instant Download Carts, Loggin Systems and more....
Advanced BlueVoda Form Processor : No coding form processor! Just install and use! Now with built in CAPTCHA!

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #11  
Old 08-26-2006, 01:47 AM
davidundalicia's Avatar
General & Forum Moderator
 
Join Date: Mar 2006
Location: Mallorca, Spain
Posts: 5,207
Default Re: Php coding help

Navaldesign:
I would love to see your coding for that elegant solution above !!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #12  
Old 08-26-2006, 08:48 AM
navaldesign's Avatar
General & Forum Moderator
 
Join Date: Oct 2005
Location: Italy
Posts: 9,288
Default Re: Php coding help

I will prepare an example form in the next days.
__________________
Navaldesign
Logger Lite: Low Cost, Customizable, multifeatured Login script
Instant Download Cart: a Powerfull, Customized, in site, DB driven, e-products Cart
DBTechnosystems.com Forms, Databases, Shopping Carts, Instant Download Carts, Loggin Systems and more....
Advanced BlueVoda Form Processor : No coding form processor! Just install and use! Now with built in CAPTCHA!

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #13  
Old 09-04-2006, 01:22 AM
davidundalicia's Avatar
General & Forum Moderator
 
Join Date: Mar 2006
Location: Mallorca, Spain
Posts: 5,207
Default Re: Php coding help

Looking forward to seeing it naval...................
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #14  
Old 09-04-2006, 10:17 AM
econstas's Avatar
Second Lieutenant
 
Join Date: Jul 2006
Location: Durham, NC
Posts: 101
Send a message via AIM to econstas Send a message via MSN to econstas
Default Re: Php coding help

I ended up getting the situation fixed.

Basic good goes like:

$name = $HTTP_POST_VARS['name'];
$email = $HTTP_POST_VARS['email'];
$cellphone = $HTTP_POST_VARS['cellphone'];
$venue_yes = $HTTP_POST_VARS['venueyes'];

# Array to have all sites checked.

$myarray[1]= $groupname;
$myarray[2]= $name;
$myarray[3]= $participant;
$myarray[4]= $cellphone;
# This array is set up to have individual Error Messages. I can cator each error to a different kind of message.

$charray[1]= "No Group Name";
$charray[2]= "No Contact Name";
$charray[3]= "How many are performing?";
$charray[4]= "No Contact Phone Number";


$max=4;
for ( $counter = 1; $counter <= $max; $counter += 1){

if ($myarray[$counter] == ""){
$e_array[$a]=$charray[$counter];
$a +=1;
}}

if ($e_array){
$esize=count($e_array);

print "<FONT=14>One of your coices for performing fields is missing. Please use the Back Button to return to the form. Thank you!</FONT><br>";

PRINT "----------------------------------------------------------<BR>";
for($ecount=1; $ecount<=$esize; $ecount +=1){
if ($e_array[$ecount]){
print "FAILED: $e_array[$ecount]<br>\n";
}
# else{ "PASSED##: $e_array[$ecount]<br>\n";}

}
exit;}

Then I had the script email me the results..

I would still like to see the idea that was mentioned earlier.

Thanks,
Stratis
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #15  
Old 09-07-2006, 11:41 AM
navaldesign's Avatar
General & Forum Moderator
 
Join Date: Oct 2005
Location: Italy
Posts: 9,288
Default Re: Php coding help

Hi Straris,

you might want to take a look at http://www.vodahost.com/vodatalk/for...form-help.html

regarding the use of loops for sending repeated fields as in your case.
__________________
Navaldesign
Logger Lite: Low Cost, Customizable, multifeatured Login script
Instant Download Cart: a Powerfull, Customized, in site, DB driven, e-products Cart
DBTechnosystems.com Forms, Databases, Shopping Carts, Instant Download Carts, Loggin Systems and more....
Advanced BlueVoda Form Processor : No coding form processor! Just install and use! Now with built in CAPTCHA!

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT +1. The time now is 01:51 PM.


Powered by vBulletin® Version 3.7.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC7
2005-2009 VodaHost Web Hosting Your Perfect Web Host - All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42