Lostvoices Posted August 10, 2010 Share Posted August 10, 2010 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; } Quote Link to comment Share on other sites More sharing options...
cs.punk Posted August 10, 2010 Share Posted August 10, 2010 How about something simple like this: <?php $error = "<div id='conn_error'>Error connecting to database</div>"; $link = mysqli_connect( $host, $user, $pass, $db); if (!$link) {echo "$error"; } else {// Continue... } ?> Quote Link to comment Share on other sites More sharing options...
Lostvoices Posted August 10, 2010 Author Share Posted August 10, 2010 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. Quote Link to comment Share on other sites More sharing options...
Wolphie Posted August 10, 2010 Share Posted August 10, 2010 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> Quote Link to comment Share on other sites More sharing options...
Lostvoices Posted August 10, 2010 Author Share Posted August 10, 2010 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> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.