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
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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.