Jump to content


Photo

custom mysql_error pages and query string problem


  • Please log in to reply
1 reply to this topic

#1 sford999

sford999
  • Members
  • PipPipPip
  • Advanced Member
  • 119 posts

Posted 24 September 2006 - 10:45 PM

Hi,

I`m trying to make a custom mysql_error function, but its just showing the page footer instead of the header and error, and its only emailing me the file that the error occured on, no other information.

This is an example of the queries
$result = mysql_query($sql) or die(sql_error());

and this is sql_error()
<?php

function sql_error($error = '')
{
	make_header($head_title = 'There has been a system error');
	
	echo "<table width=\"100%\" border=\"0\">
  <tr>
    <td class=\"thddr3\">There has been an error. This is the error message:</td>
  </tr>
  <tr>
    <td class=\"thddr3\"><strong>". mysql_error() ."</strong></td>
  </tr>
  <tr>
    <td class=\"thddr2\">An email has been sent to the sites administrator with the full details of the error.</td>
  </tr>
</table>";
	$to      = 'name@domain.com';
	$subject = 'MySQL error email notification';
	$message = 'There has been an MySQL Error.\n The error is '. mysql_error().'\n Referrer ='.$_SERVER['HTTP_REFERER'].' \n Browser = '.$_SERVER['HTTP_USER_AGENT'].' \n IP Address = '.$_SERVER['REMOTE_ADDR'].' \n The page = '.$_SERVER['PHP_SELF'];
	$headers = 'From: name@domain.com' . "\r\n" .'Reply-To: name@domain.com' . "\r\n" .'X-Mailer: PHP/' . phpversion();
	mail($to, $subject, $message, $headers);
	
	make_footer();
}

?>

Also I`m using this for the query strings

<?php

if(isset($_GET['p'])) 
{ 
	$p = $_GET['p']; 
} 
if(isset($_POST['p'])) 
{ 
	$p = $_POST['p']; 
}
if($p == "") 
{ 
	$p = "index"; 
}

if($p == "page1")
{
	make_header($head_title = 'page1');
	include("inc/page1.php");
	make_footer();
}

elseif($p == "page2")
{
	make_header($head_title = 'page2');
	include("inc/page2.php");
	make_footer();
}
else 
{
	make_header($head_title = 'page1');
	include("inc/page1.php");
	make_footer();
}

?>

But if someone enters say index.php?p=4538583 then the page shows up blank, with the above code, shouldn`t it show "page1" instead of it being blank?

Any help on the above would be appreciated.

Thanks

#2 onlyican

onlyican
  • Members
  • PipPipPip
  • Advanced Member
  • 921 posts
  • LocationHants - UK

Posted 25 September 2006 - 01:06 AM

Regarding the first issue
Check the source code, see what you can see
And for the second issue

Use Switch, not if

Something like this

<?php
$p = isset($_GET["p"]) ? $_GET["p"] : $_POST["p"];

switch($p){
	case "page2":
		make_header("page2");
		include("inc/page2");
		make_footer();
		break;
	default:
		make_header("page1");
		include("inc/page1.php");
		make_footer();
		break;
}
?>

OR

<?php
$p = isset($_GET["p"]) ? $_GET["p"] : $_POST["p"];

if($p == "page2"){
	make_header("page2");
	include("inc/page2");
	make_footer();
}else{
	
	make_header("page1");
	include("inc/page1.php");
	make_footer();
	
}

?>


BUT
only use the IF statement if you have 2 options

MOre than 2 options, use Switch
Tell me the problem, I will try tell you the solution




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users