Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

posting php error to new page

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

posting php error to new page

Postby andz1982 » Thu Mar 21, 2013 1:39 am

Hi there,

I have a slight problem: I want to verify a certain item against what is stored in the database and if the item does not exist, to post it on a separate page (the verification part works fine, just that when it opens the new page, it displays the following text:

{$error}

{$errorproductcode}
Please click here to return to the main menu !

The following is the relevant code on the verification page (I use an include to connect to the database):

<?php $query = "SELECT product_name FROM products WHERE product_code = '$prodcode1'";

$code1= mysql_query($query) or die(mysql_error());
if(mysql_num_rows($code1) == 0) {
$error="The following product code is not in our system";
$errorproductcode=$prodcode1;
header ('location: producterror.php?error={$error}&errorproductcode={$errorproductcode}');
}
exit();?>

The following code is from the error page:

<?php
--include link is here--
$error=$_GET['error'];
$errorproductcode=$_GET['errorproductcode'];
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Error Page</title>
</head>

<body>
<?php echo "<p>".$error."</p>" ?>
<?php echo "<p>".$errorproductcode."</p>"; ?>
Please click<a href="index.php"> here </a> to return to the main menu !
</body>
</html>

It is probably some silly mistake that I cannot see at the moment: would really appreciate any help that you could give me.


Thanks and regards,


Andrew
andz1982
New php-forum User
New php-forum User
 
Posts: 7
Joined: Mon Oct 29, 2012 8:00 am

Re: posting php error to new page

Postby seandisanti » Thu Mar 21, 2013 3:51 pm

you're using bracketed variables and single quotes when you do your redirect. personally I'd say build your redirect string first, and use concatenation rather than bracketed variables, just because it makes them stand out even more. also, when posting code here, use [ code=PHP] [ /code] tags without the leading spaces to isolate code (and add syntax highlighting)


Code: Select all

//header ('location: producterror.php?error={$error}&errorproductcode={$errorproductcode}');
$loc 'producterror.php?error=' $error '&errorproductcode=' $errorproductcode;
header($loc);
 
seandisanti
php-forum Fan User
php-forum Fan User
 
Posts: 838
Joined: Mon Oct 01, 2012 12:32 pm

Re: posting php error to new page

Postby seandisanti » Thu Mar 21, 2013 3:53 pm

the issue, just incase you didn't catch it is that the bracketed variables are being treated as literal strings when used with single quotes. this code should make it clear...
Code: Select all

$a 
='String Value';
$b ='will not be displayed';
echo 
"{$a}'{$b}';
 
seandisanti
php-forum Fan User
php-forum Fan User
 
Posts: 838
Joined: Mon Oct 01, 2012 12:32 pm

Re: posting php error to new page

Postby andz1982 » Fri Mar 22, 2013 12:33 am

<cue banging head against the wall>.....

Thanks for pointing it out....regarding the method you showed for the header it wouldn't work for me...though the original version worked with some minor modifications.


Thanks a lot !


Andrew
andz1982
New php-forum User
New php-forum User
 
Posts: 7
Joined: Mon Oct 29, 2012 8:00 am

Re: posting php error to new page

Postby seandisanti » Fri Mar 22, 2013 7:06 am

No problem, I'm glad to help
seandisanti
php-forum Fan User
php-forum Fan User
 
Posts: 838
Joined: Mon Oct 01, 2012 12:32 pm


Return to PHP coding => General

Who is online

Users browsing this forum: Baidu [Spider], Google [Bot] and 3 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron