Board index   FAQ   Search  
Register  Login
Board index php forum :: HTML CSS

My PHP needs some style !!

Questions and tutorials related to Cascading Style Sheets *all versions*

Moderators: macek, egami, gesf

My PHP needs some style !!

Postby AimSkyward » Sat Aug 03, 2013 4:37 am

Hi folks,

Hopefully this should be quite straightforward.
I am using a php script to write some html form data to MySQL in the event that a submit button is pressed:
Code: Select all
if (isset($_POST['Submit']))

Initially I check the connection to MySQL and get an echo back to inform the user of any errors/success:
Code: Select all
$con=mysqli_connect("localhost","u_name","password");
if(mysqli_connect_errno()){
echo "Failed to connect to MySQL: ".mysqli_connect_error();}
else{
echo "Connection to MySQL via 'instlab' established.";}

At the moment the feedback text just prints at the top of the html user interface (form), however, I would like to position it within a predefined area on the page if possible.
I tried linking a .css script file that I use as my html stylesheet using:
Code: Select all
<link rel="stylesheet" href="Style.css">
but this does not seem to work. I think I understand that php is not seen by the browser which would maybe be a reason this is not working.
Any advice would be appreciated :) .
AimSkyward
New php-forum User
New php-forum User
 
Posts: 6
Joined: Mon Jul 22, 2013 10:42 am

Re: My PHP needs some style !!

Postby landi » Tue Aug 05, 2014 9:07 am

Hi,

1) You probably want type="text/css" in your css link e.g.
Code: Select all
<link rel="stylesheet" href="Style.css" type="text/css">


However, this is unlikely to be your problem. You don't show where the php is being executed in relation to your html. If it is executed BEFORE any html is output, then the echo message will appear above the <html> tag and may look like it is at the 'top' of the screen. You can use 'view source' (firefox: cntl-U) to see where your output is in relation to your html.

No amount of css is going to change that!

I suggest:
1) For fatal errors (like you db connection), use die() to terminate output as there is not much point carrying on after printing the message. I like to add a unique error number to help user's report the problem. You could even write your own my_fatal() function to format the msg if you want

2) For non-fatal msg e.g. 'connection established', I suggest you concatenate the messages into a variable and then print it inside a suitable html container e.g.

Code: Select all
<?php
$gsAlert = ''; // Init
$con=mysqli_connect("localhost","u_name","password");
if(mysqli_connect_errno()){
  // Fatal error
  die ("Error 19201 - Failed to connect to MySQL: ".mysqli_connect_error());
} else {
  // Add to alert msg. Note trailing space for nice formatting.
  $gsAlert .= "Connection to MySQL via 'instlab' established. ";
}
?>
<html> ...
<body> ...
  <div id="alert">
    <?php print $gsAlert; // print alert msgs ?>
  </div>
...
</body> ...
landi
New php-forum User
New php-forum User
 
Posts: 235
Joined: Thu Mar 15, 2012 3:59 pm

Re: My PHP needs some style !!

Postby landi » Tue Aug 05, 2014 9:11 am

Wow, I didn't see your post is 2 days old PLUS 1 YEAR. You've probably either solved this problem or retired and taken up fishing. Oh well...
landi
New php-forum User
New php-forum User
 
Posts: 235
Joined: Thu Mar 15, 2012 3:59 pm


Return to CSS

Who is online

Users browsing this forum: No registered users and 2 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron