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