Jump to content

PHP exit() with CSS


Lostvoices

Recommended Posts

hi guys..

 

im not sure if im in the right section but.

 

i have this script below and it exits BUT i would like it to exit After it applies the CSS to my Error.

 

i want it to display nothing except the error if there is an error.. the php is being included on the index.php page which links to the css.

 

this works IF i put the include after the CSS link but wondering if theres a better way.

 

 

PHP

<?php


$host = 'localhost';
$user = 'user';
$pass = 'password';
$db = 'upload';
$link = @mysqli_connect( $host, $user, $pass, $db);

if(!$link){?> 
<div id='conn_error'> <?php
echo 'There was an Error Connecting to the Server';
?>
</div><?php 

}

?>

 

Css

#conn_error{
background: red;
font-size: 24px;
font-family: arial;
color: white;
width: 500px;
text-align: center;
border: solid 2px black;
position: absolute;
top: 150px;
left: 30%;
padding: 2px;

}

 

Link to comment
https://forums.phpfreaks.com/topic/210314-php-exit-with-css/
Share on other sites

that looks fine but that file is being included at the TOP of the index file. so if i don't include it after the <link rel='stylesheet.... > tag my css doesnt load for the error.

 

i was wondering if it's ok to put the includes there or is there a way to bring the css into the php. i know i could you inline style but i really don't like that.

 

Link to comment
https://forums.phpfreaks.com/topic/210314-php-exit-with-css/#findComment-1097463
Share on other sites

Try this:

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset=utf-8 />
    <title>What ever you want your title to be!</title>
    <link rel="stylesheet" href="path/to/stylesheet" type="text/css" />
  </head>
  <body>
  <?php
    $error = '<div id="conn_error">Error connecting to the database!</div>';
    // Try making connection to the database
    $link  = mysql_connect($host, $user, $pass);
    
    if ($link === FALSE) {
      echo $error;
    }
    else {
      // Connection succeeded; select the database or do what ever
      mysql_select_db('db_name', $link);
    }
  ?>
  </body>
</html>

 

Link to comment
https://forums.phpfreaks.com/topic/210314-php-exit-with-css/#findComment-1097480
Share on other sites

Thanks guys :)

 

this worked

<!DOCUMENT html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<title>Bananas Hate Apples</title>
<link rel='stylesheet' type='text/css' href= 'css/main.css'>
<?php include 'db_fns.php'; ?>
</head>

<body>
<?php include 'registration_form.html'; ?>

</body>
</html>

Link to comment
https://forums.phpfreaks.com/topic/210314-php-exit-with-css/#findComment-1097488
Share on other sites

Archived

This topic is now archived and is closed to further replies.

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