PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old October 31st, 2012, 06:12 PM
Ihatephp Ihatephp is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2012
Posts: 55 Ihatephp User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 10 h 32 m 31 sec
Reputation Power: 1
Unhappy Could anyone tell what's wrong with this script, please?

I'm trying to create a form system where 3 pages will ask you your name, age, address, and all the missing input will be listed on the confirmation page after the 3rd page.

Please someone help me... been trying for a couple of hours and I'm new to PHP.

----- This is the script for the confirmation page----------------


<?php
// unset the formStarted session variable
unset($_SESSION['formStarted']);

// go through the elements in the $_SESSION
foreach ($_SESSION as $key => $value) {
// skip the missing element
if ($key == "missing"){continue;}
// skip the submit buttons
// use identity operator with strpos to prevent false negatives
if (strpos($key, 'Submit') === 0) {
continue;
}
echo "<li>$key: $value</li>";
}
// clear the $_SESSION array and destroy session
$_SESSION = array();
session_destroy();
?>
</ul>


<?php


if(isset($_SESSION['missing'])){
$missingList = implode(", ", "$_SESSION['missing']");
echo "<p>The following required field(s) are missing: $missingList. <br />Please fill them out below.</p>";
}

?>



---------And the script below is from previous page. (there are 2 other pages to ask name and age before this page. )-----------


session_start();
if (!isset($_SESSION['formStarted'])) {
header('Location: multiple01.php');
exit;
}
// each page needs a different name for the submit button
if (array_key_exists('Submit3', $_POST)) {
include('shared.php');
nukeMagicQuotes();
// set required fields
// must be an array, even if only one item is required
// if no fields are required, an empty array is needed
// otherwise, in_array() later in the script will generate an error
$required = array('address');
// create empty array for any missing fields
//$missing = array();

// process the $_POST variables and save them in the $_SESSION array
foreach ($_POST as $key => $value) {
// assign to temporary variable and strip whitespace if not an array
$temp = is_array($value) ? $value : trim($value);
// if empty and required, add to $missing array
if (empty($temp) && in_array($key, $required)) {
array_push($_SESSION['missing'], $key);
}
// otherwise, assign to a variable of the same name as $key
else {
$_SESSION[$key] = $temp;
}
}
// if no required fields are missing, redirect to next page
//if (!$missing) {
header('Location: multiple04.php');
exit;
//}
}
?>
<!DOCTYPE html>

<head>

<title>Multiple form 3</title>
</head>

<body>

<form id="form1" name="form1" method="post" action="">
<p>
<label for="address">Address:</label>
<input type="text" name="address" id="address" /> (required)
</p>
<p>
<input type="submit" name="Submit3" value="Send details" />
</p>
</form>
</body>

Reply With Quote
  #2  
Old October 31st, 2012, 06:25 PM
ManiacDan's Avatar
ManiacDan ManiacDan is offline
Likely to be eaten by a grue.
Dev Shed God 10th Plane (9500 - 9999 posts)
 
Join Date: Oct 2006
Location: Pennsylvania, USA
Posts: 9,801 ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)  Folding Points: 127430 Folding Title: Super Ultimate Folder - Level 1Folding Points: 127430 Folding Title: Super Ultimate Folder - Level 1Folding Points: 127430 Folding Title: Super Ultimate Folder - Level 1Folding Points: 127430 Folding Title: Super Ultimate Folder - Level 1Folding Points: 127430 Folding Title: Super Ultimate Folder - Level 1Folding Points: 127430 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 2 Months 3 Weeks 16 h 59 m 20 sec
Reputation Power: 6112
Please read the new user guide directly below this message.

If you're developing without error_reporting turned on, turn it on. Either make the change to error_reporting in php.ini or put this at the top of every page:

error_reporting(E_ALL);

That will tell you what's wrong.

Your function nukeMagicQuotes() isn't defined. Even if it were, it's entirely unnecessary if you're developing on a modern system.

The rest of your code is badly formatted and uncolored, so it's difficult to tell what's going on. Please wrap your code in [ PHP ] and [ /PHP ] tags (remove the spaces) which will allow us to better read your code.
__________________
HEY! YOU! Read the New User Guide and Forum Rules

"They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

"The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.

Reply With Quote
  #3  
Old October 31st, 2012, 08:04 PM
requinix's Avatar
requinix requinix is offline
Still alive
Click here for more information.
 
Join Date: Mar 2007
Location: Washington, USA
Posts: 12,690 requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)  Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 5 Months 1 Week 4 Days 3 h 43 m 47 sec
Reputation Power: 8969
Send a message via AIM to requinix Send a message via MSN to requinix Send a message via Yahoo to requinix Send a message via Google Talk to requinix
Quote:
Originally Posted by ManiacDan
[ PHP ] and [ /PHP ] tags (remove the spaces)

Oh, like this?

[PHP] and [/PHP]

Comments on this post
ManiacDan agrees: Too lazy

Reply With Quote
  #4  
Old November 1st, 2012, 12:38 AM
Ihatephp Ihatephp is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2012
Posts: 55 Ihatephp User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 10 h 32 m 31 sec
Reputation Power: 1
Thanks

Did you mean like this??



PHP Code:
<?php
// unset the formStarted session variable
unset($_SESSION['formStarted']);

// go through the elements in the $_SESSION
foreach ($_SESSION as $key => $value) {
// skip the missing element
if ($key == "missing"){continue;}
// skip the submit buttons
// use identity operator with strpos to prevent false negatives
if (strpos($key'Submit') === 0) {
continue;
}
echo 
"<li>$key$value</li>";
}
// clear the $_SESSION array and destroy session
$_SESSION = array();
session_destroy();
?>

</ul>

PHP Code:
<?php


if(isset($_SESSION['missing'])){
$missingList implode(", ""$_SESSION['missing']");
echo 
"<p>The following required field(s) are missing: $missingList. <br />Please fill them out below.</p>";
}

?>



---------And the script below is from previous page. (there are 2 other pages to ask name and age before this page. )-----------

PHP Code:
<?php
session_start
();
if (!isset(
$_SESSION['formStarted'])) {
header('Location: multiple01.php');
exit;
}
// each page needs a different name for the submit button
if (array_key_exists('Submit3'$_POST)) {
include(
'shared.php');
nukeMagicQuotes();
// set required fields
// must be an array, even if only one item is required
// if no fields are required, an empty array is needed
// otherwise, in_array() later in the script will generate an error
$required = array('address');
// create empty array for any missing fields
//$missing = array();

// process the $_POST variables and save them in the $_SESSION array
foreach ($_POST as $key => $value) {
// assign to temporary variable and strip whitespace if not an array
$temp is_array($value) ? $value trim($value);
// if empty and required, add to $missing array
if (empty($temp) && in_array($key$required)) {
array_push($_SESSION['missing'], $key);
}
// otherwise, assign to a variable of the same name as $key
else {
$_SESSION[$key] = $temp;
}
}
// if no required fields are missing, redirect to next page
//if (!$missing) {
header('Location: multiple04.php');
exit;
//}
}
?>


<!DOCTYPE html>

<head>

<title>Multiple form 3</title>
</head>

<body>

<form id="form1" name="form1" method="post" action="">
<p>
<label for="address">Address:</label>
<input type="text" name="address" id="address" /> (required)
</p>
<p>
<input type="submit" name="Submit3" value="Send details" />
</p>
</form>
</body>

Reply With Quote
  #5  
Old November 1st, 2012, 08:02 AM
ManiacDan's Avatar
ManiacDan ManiacDan is offline
Likely to be eaten by a grue.
Dev Shed God 10th Plane (9500 - 9999 posts)
 
Join Date: Oct 2006
Location: Pennsylvania, USA
Posts: 9,801 ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)  Folding Points: 127430 Folding Title: Super Ultimate Folder - Level 1Folding Points: 127430 Folding Title: Super Ultimate Folder - Level 1Folding Points: 127430 Folding Title: Super Ultimate Folder - Level 1Folding Points: 127430 Folding Title: Super Ultimate Folder - Level 1Folding Points: 127430 Folding Title: Super Ultimate Folder - Level 1Folding Points: 127430 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 2 Months 3 Weeks 16 h 59 m 20 sec
Reputation Power: 6112
Well...yes, like that, though I was hoping your code would be indented and formatted so it would actually be readable.

Did you do the error_reporting? If this is your real code, I see at least one fatal error in the magic quotes function.

Also...can YOU tell us what's wrong with this script? I just now realized you have no question

Reply With Quote
  #6  
Old November 7th, 2012, 12:06 AM
Ihatephp Ihatephp is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2012
Posts: 55 Ihatephp User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 10 h 32 m 31 sec
Reputation Power: 1
Sorry for the late reply

Thanks ManiacDan.

yeah I just realized that.. My problem was the page named 'multiple04.php' doesn't show the script at all.

So I wanted to ask someone about why the page isn't showing anything.
Since I assumed there are some problems on the fourth and the third page, I just posted 2 scripts on the fourth page and 1 big chunk of script on the third page


And am I supposed to use 'error_reporting(E_ALL);' right after the '<?php'?


Actually, my Dreamweaver is telling me that there is error on the 2nd line of the 2nd chunk of the script, where it says '$missingList = implode(", ", "$_SESSION['missing']"); '.

Can you tell what's wrong with this line or things above??

sorry for the hard-to-read code..

Thank you.

Reply With Quote
  #7  
Old November 7th, 2012, 12:19 AM
Catacaustic's Avatar
Catacaustic Catacaustic is offline
Code Monkey V. 0.9
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Mar 2005
Location: A Land Down Under
Posts: 1,884 Catacaustic User rank is General 12nd Grade (Above 100000 Reputation Level)Catacaustic User rank is General 12nd Grade (Above 100000 Reputation Level)Catacaustic User rank is General 12nd Grade (Above 100000 Reputation Level)Catacaustic User rank is General 12nd Grade (Above 100000 Reputation Level)Catacaustic User rank is General 12nd Grade (Above 100000 Reputation Level)Catacaustic User rank is General 12nd Grade (Above 100000 Reputation Level)Catacaustic User rank is General 12nd Grade (Above 100000 Reputation Level)Catacaustic User rank is General 12nd Grade (Above 100000 Reputation Level)Catacaustic User rank is General 12nd Grade (Above 100000 Reputation Level)Catacaustic User rank is General 12nd Grade (Above 100000 Reputation Level)Catacaustic User rank is General 12nd Grade (Above 100000 Reputation Level)Catacaustic User rank is General 12nd Grade (Above 100000 Reputation Level)Catacaustic User rank is General 12nd Grade (Above 100000 Reputation Level)Catacaustic User rank is General 12nd Grade (Above 100000 Reputation Level)Catacaustic User rank is General 12nd Grade (Above 100000 Reputation Level)Catacaustic User rank is General 12nd Grade (Above 100000 Reputation Level) 
Time spent in forums: 2 Weeks 4 Days 14 h 1 m 42 sec
Reputation Power: 1798
If that's the line that the error is occuring on, it's quit easy. You don't want to have quotes around $_SESSION[]. If you have it wrapped in quotes it is seen as a string, and you can't pass a string to explode(). If you're going to be sure, you should check that the value is an array with is_array($_SESSION['missing']) before you try ot use explode() on it.
PHP Code:
 $missingList implode(", "$_SESSION['missing']); 

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPHP Development > Could anyone tell what's wrong with this script, please?

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap