Jump to content

echo $_GET['missing'] shows one word only


Evrim

Recommended Posts

Hello

 

I have a php page that checks the values of a html form. If some elements of the form are missing or have incorrect format, it will display messages to the user.

 

1. My checkform.php page contains a code like:

 

$missing1 = "The following fields are missing: ";

if ($key=='gender' && empty($val)) {
$missing1 .= " Gender;  " ;  
echo $missing1;}	



if ($key=='address' && empty($val)) {
$missing1 .=  "Home address;  " ;  
echo $missing1; }

// More checks of the same type 

$togourl ="../errors.php?missing1=$missing1";
header("Location: $togourl");

 

2. In my errors.php I have:

 

<tr>
<td>
<?php
echo $_GET['missing1']; 
?>
</td>
</tr> 

 

 

1. The problem is that I only see one word in my errors.php, which is "The". When I remove the statement header("Location: $togourl") from my code, I see the missing1 var is correct (by checking echo in the code), but when displaying in second page I have a problem. Could you help me? Everything else (html) shows fine in the table of the second page.

 

2. What method you suggest so I store the missing fields in array and pass it on to errors.php and show it in several lines threre?

 

 

Many many thanks

Evrim

 

 

Link to comment
https://forums.phpfreaks.com/topic/163258-echo-_getmissing-shows-one-word-only/
Share on other sites

I would suggest creating an array of the errors and pass them as a single variable through the URL something like:

 

$error_array = array();

if ($key=='gender' && empty($val)) {
$error_array[] = "Gender" ; 
}   

if ($key=='address' && empty($val)) {
$error_array[] =  "Home address" ; 
}

$togourl ="../errors.php?missing1=".serialize($error_array);
header("Location: $togourl");

 

And in the errors.php

 

$error_array = unserialize($_GET["missing1"]); 
// Then do a loop to print out the items in the array

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.