Jump to content

custom mysql_error pages and query string problem


sford999

Recommended Posts

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
[code]$result = mysql_query($sql) or die(sql_error());[/code]

and this is sql_error()
[code]<?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();
}

?>[/code]

Also I`m using this for the query strings

[code]<?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();
}

?>[/code]

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
Link to comment
Share on other sites

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

[code]
<?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;
}
?>
[/code]

OR

[code]
<?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();

}

?>
[/code]


BUT
only use the IF statement if you have 2 options

MOre than 2 options, use Switch
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.