homepage Welcome to WebmasterWorld Guest from 54.161.143.22
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
need help passing variable and load new page with them php
gibsongk55




msg:4313956
 5:42 am on May 18, 2011 (gmt 0)

Hi,

First of all I don't know a lot of php just enough to get myself in trouble as I have now.

I have a php form where I have 7 error messages on fail.

I have the following in my form page:

session_start();

$_SESSION['errmsg'];

----------------------------

error messages under separate if statements.

$errmsg = 1;
header ("location: msg.php?errmsg");

$errmsg = 2;
header ("location: msg.php?errmsg");

$errmsg = 3;
header ("location: msg.php?errmsg");

$errmsg = 4;
header ("location: msg.php?errmsg");

$errmsg = 5;
header ("location: msg.php?errmsg");

$errmsg = 6;
header ("location: msg.php?errmsg");

$errmsg = 7;
header ("location: msg.php?errmsg");

(i didnt fill in the actual messages yet just testing)

Then in my msg.php file i have:

session_start();

$_SESSION['errmsg'];


if($_SESSION[errmsg']==1){
$errmessage = "message 1";
}
if($_SESSION[errmsg']==2){
$errmessage = "message 2";
}
if($_SESSION[errmsg']==3){
$errmessage = "message 3";
}
if($_SESSION[errmsg']==4){
$errmessage = "message 4";
}
if($_SESSION[errmsg']==5){
$errmessage = "message 5";
}
if($_SESSION[errmsg']==6){
$errmessage = "message 6";
}
if($_SESSION[errmsg']==7){
$errmessage = "message 7";
}

<html>

<span class="content"><h3>Message:</h3></span>
<p class="content"><h2>$errmessage</h2></p>

Currently I am getting an error in msg.php:

Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting ']'

on the following line: $errmessage = "message 2";

Thank you for any help.

Gibs

 

Matthew1980




msg:4313979
 7:30 am on May 18, 2011 (gmt 0)

Hi there Gibsongk55,

Welcome to the forums!

Your error is just a typo on all of the if clauses:-

if($_SESSION[errmsg']==1){ <<-- this line on each clause
$errmessage = "message 1";
}

Should be:-

if($_SESSION['errmsg']==1){ <- the extra ' is really needed there
$errmessage = "message 1";
}

Realistically you need to check to see if the variable isset() and !empty() before putting a conditional clause around it.

Hope that makes sense.

Cheers,
MRb

gibsongk55




msg:4313992
 8:08 am on May 18, 2011 (gmt 0)

Hi Matthew,

Thanks for the help. I can't believe i missed that. Well that worked but now I have a problem showing the error message on the php page its passed to.

when the msg.php page loads it shows nothing, no error message.

I tried this:

<p class="content"><h2><?php echo $errmessage;?></h2></p>

Nothing shows up at all.

Thanks,

Gibs

gibsongk55




msg:4314002
 8:39 am on May 18, 2011 (gmt 0)

Thanks for the help i finally got it figured out.

Under my error messages "if" statements in the php form I had to change the line to the following:

$errmsg = 1;
header ("location: msg.php?errmsg");

new line:

$_SESSION['errmsg'] = 1;

header ("location: msg.php?errmsg");


Thanks again for the help.


Gibs

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved