Rendering issue with PHP... can you help?

Hi All,

I have a registration script, which i’ve included below.

In terms of error handling and validation it’s great. But it doesn’t render properly in IE or Chrome.

Safari and FF look perfectly fine, displaying the errors in a list and the form remains below.

However, the other 2 browsers list the errors correctly, but the form beneath seems to end up all over the place and I cant seem to work out why…

Any ideas?

include "";

function account_exists($column, $value) {
    $accounts = mysql_query('SELECT * FROM businesses WHERE ' . $column . ' = "' . $value . '"');

    $return = (mysql_num_rows($accounts) > 0) ? true : false;


    return $return;

//	Check Email Address courtesy of Dave Child:
function check_email_address($email) {

    if (!ereg("^[^@]{1,64}@[^@]{1,255}$", $email))
        return false;

    $email_array = explode("@", $email);
    $local_array = explode(".", $email_array[0]);

    for ($i = 0; $i < sizeof($local_array); $i++) {
        if (!ereg("^(([A-Za-z0-9!#$%&'*+/=?^_`{|}~-][A-Za-z0-9!#$%&'*+/=?^_`{|}~\\.-]{0,63})|(\\"[^(\\\\|\\")]{0,62}\\"))$", $local_array[$i]))
            return false;

    if (!ereg("^\\[?[0-9\\.]+\\]?$", $email_array[1])) {

        $domain_array = explode(".", $email_array[1]);

        if (sizeof($domain_array) < 2)
            return false;

        for ($i = 0; $i < sizeof($domain_array); $i++) {
            if (!ereg("^(([A-Za-z0-9][A-Za-z0-9-]{0,61}[A-Za-z0-9])|([A-Za-z0-9]+))$", $domain_array[$i]))
                return false;

    return true;

$spam_check = ZGF;

if (isset($_POST['submit'])) {
    $business_name = ($_POST['business_name']);
    $url = ($_POST['url']);
    $category = ( $_POST['category']);
    $email = ( $_POST['email'] );
    $description = ($_POST['description'] );
    $location = ($_POST['location'] );
    $spam_check = $_REQUEST['spam_check'];
    $accept = $_REQUEST['accept'];

    if (empty($business_name)) {
        $errors[] = "You must enter your Business Name<br>";
    } else if (account_exists('business_name', $business_name)) {
        $errors[] = "The Business Name <b>'$business_name'</b> already exists<br>";

    if (empty($category)) {
        $errors[] = "You must enter your category<br>";

    //	Email address checks
    if (empty($email)) {
        $errors[] = "You must enter your Email Address<br>";
    } else if (!check_email_address($email)) {
        $errors[] = "The Email Address appears to be invalid<br>";

    if (empty($description)) {
        $errors[] = "You must enter a Description<br>";
    if (empty($spam_check)) {
        $errors[] = "You must enter an anti-spam answer<br>";
    if ($spam_check != "ZGF") {
        $errors[] = "Your spam entry was invalid<br>";
 if (empty($accept)) {
        $errors[] = "You must accept the terms of use!<br>";

    if (!isset($errors)) {
        @mysql_query("INSERT INTO `businesses`(business_name, url, category,email,description,location,date_registered) VALUES ('$business_name', '$url','$category','$email','$description', '$location', CURDATE())") or die(mysql_error());
        {//send email
            $business_name = stripslashes($_POST['business_name']);
            $url = stripslashes($_POST['url']);
            $email = stripslashes($_REQUEST['email']);
            $category = stripslashes($_REQUEST['category']);
            $description = stripslashes($_REQUEST['description']);
            $location = stripslashes($_REQUEST['location']);
            $email_message = "A business has just registered on Business-Reg. You can find their details below: \
 Business Name: \
 {$business_name} \
 Business URL:\
 {$url} \
  Email Address: \
 {$email} \
  Category: \
 {$category} \
 Description: \
 {$description} \
 Location: \

            mail('', 'Business Reg Submission', $email_message, 'From: ' . $email . "\\r\

        header('location: thanks.php');

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"

<html xmlns="">


        <title>business-reg | Register your business with </title>

        <link rel="stylesheet" type="text/css" href="stylesheets/styles.css" />

        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />



        <div id="container">

            <div id="header">	</div>

            <div id="navigation">

                    <li><a href="index.php">Home </a></li>
                    <li><a href="search.php">Search </a></li>
                    <li><a href="about.php">About Us </a></li>
                    <li><a href="faq.php">FAQ </a></li>
                    <li><a href="contact.php">Contact </a></li>


            <div id="left_content">


                        <td><img src="/images/footer.jpg" alt="lightbulb" title="Testimonial - Chat Button"> </td>
                        <td> <a href="index.php"> Home </a>


                        <td><img src="" alt="lightbulb" title="Testimonial - Chat Button"> </td>
                        <td> <a href="advertise.php"> Advertise With Us </a>


                        <td><img src="" alt="lightbulb" title="Testimonial - Chat Button"> </td>
                        <td> <a href="why.php"> Why PAT Test? </a>


                        <td><img src="" alt="lightbulb" title="Testimonial - Chat Button"> </td>
                        <td> <a href="pricing.php"> Pricing Guide  </a>


                        <td><img src="" alt="lightbulb" title="Testimonial - Chat Button"> </td>
                        <td> <a href="faqs.php"> FAQ's </a>




            <div id="main_content">

                <h3> Hello and Welcome  </h3>

//	Error report goes here if there are errors :)

                if (isset($errors)) {

                    echo "<div id=errors";

                    echo "\	\	\	\	", '<p class="form_text">The following errors occurred while processing your request. Please try again.</p>', "\
                    echo "\	\	\	\	", "\

                    foreach ($errors as $error)
                        echo "", $error, "\

                    echo "\	\	\	\	", "\

                    echo "</div";

                <div id="stylized" class="myform">	
                        <form  action="index.php" method="post">

                            <h1>Business Registration</h1>
                            <p>Please enter the form below to register your business with business-reg</p>

                            <label>Business Name
                                <span class="small">Add your business name</span>
                            <input type="text" name="business_name" id="business_name" value="<?php echo $business_name; ?>" />

                     <label>Web Address
                                <span class="small">Eg:</span>
                            <input type="text" name="url" id="url" value="http://" />
                            <label> Category
                                <span class="small">Please add a category</span>
                            <select name="category" size="1" id="category">
                                <option selected="selected">Please Select</option>  
                                <option value="accomodation">Accomodation</option>
                                <option value="accountancy">Accountancy</option>
                                <option value="accupuncture">Accupuncture</option>
                                <option value="building">Building</option>
                                <option value="computing">Computing</option>
                                <option value="dental care">Dental Care</option>
                                <option value="electrical">Electrical</option>
                                <option value="fabricators">Fabricators</option>
                                <option value="gardening">Gardening</option>
                                <option value="government">Government</option>
                                <option value="health">Health</option>
                                <option value="insurance">Insurance</option>
                                <option value="journalism">Journalism</option>
                                <option value="livery">Livery</option>
                                <option value="mechanic">Mechanic</option>
                                <option value="nursing">Nursing</option>
                                <option value="plumbing">Plumbing</option>
                                <option value="rescue">Rescue</option>
                                <option value="mechanic">Mechanic</option>


                            <label>Business Email
                                <span class="small">Add a valid address</span>
                            <input type="text" name="email" id="email" value="<?php echo $email; ?>" />

                                <span class="small">Please describe your business</span>
                            <textarea cols="22" rows="10" id="description" name="description"><?php echo $description; ?></textarea>

                                <span class="small">The location of your business</span>
                            <select name="location" size="1" id="category">
                                <option selected="selected">Please Select</option>  

                                <option value="bath">Bath</option>
                                <option value="birmingham">Birmingham</option>
                                <option value="bradford">Bradford</option>
                                <option value="brighton and hove">Brighton and Hove</option>
                                <option value="bristol">Bristol</option>
                                <option value="cambridge">Cambridge</option>
                                <option value="canterbury">Canterbury</option>
                                <option value="carlisle">Carlisle</option>
                                <option value="chester">Chester</option>
                                <option value="chichester">Chichester</option>
                                <option value="coventry">Coventry</option>
                                <option value="derby">Derby</option>
                                <option value="durham">Durham</option>
                                <option value="ely">Ely</option>
                                <option value="exeter">Exeter</option>
                                <option value="gloucester">Gloucester</option>
                                <option value="hereford">Hereford</option>
                                <option value="kingston upon hull">Kingston upon Hull</option>
                                <option value="lancaster">Lancaster</option>
                                <option value="leeds">Leeds</option>
                                <option value="leicester">Leicester</option>
                                <option value="lichfield">Lichfield</option>
                                <option value="lincoln">Lincoln</option>
                                <option value="liverpool">Liverpool</option>
                                <option value="city of london">City of London</option>
                                <option value="manchester">Manchester</option>
                                <option value="newcastle upon tyne">Newcastle upon Tyne</option>
                                <option value="norwich">Norwich</option>
                                <option value="nottingham">Nottingham</option>
                                <option value="oxford">Oxford</option>
                                <option value="peterborough">Peterborough</option>
                                <option value="plymouth">Plymouth</option>
                                <option value="portsmouth">Portsmouth</option>
                                <option value="preston">Preston</option>
                                <option value="ripon">Ripon</option>
                                <option value="salford">Salford</option>
                                <option value="salisbury">Salisbury</option>
                                <option value="sheffield">Sheffield</option>
                                <option value="southampton">Southampton</option>
                                <option value="st albans">St Albans </option>
                                <option value="stoke-on-trent">Stoke-on-Trent </option>
                                <option value="sunderland">Sunderland </option>
                                <option value="truro">Truro </option>
                                <option value="wakefield">Wakefield </option>
                                <option value="wells">Wells </option>
                                <option value="westminster">Westminster </option>
                                <option value="winchester">Winchester </option>
                                <option value="wolverhampton">Wolverhampton </option>
                                <option value="worcester">Worcester </option>
                                <option value="york">York </option>

                            <label>Spam Checker
                                <span class="small">Enter the last 3 characters</span>
                                <img src="">
                            <input type="text" name="spam_check" id="spam_check" </input>
                              <button type="submit" name="submit" id="submit"></button>
                                <input type="checkbox" name="accept" id="accept" value="accept" title="accept" </input>
                                <span class="small">I accept that registering will display my business information submitted above to any user of business-reg.</span> 
                                <div class="spacer"></div>





            <div id="footer"> <p> © business-reg 2011 <br />
					 Website Design: <br />




That depends on your database structure.

Do you have a field in the users table which contains the date at which people signed up?

$rs = mysql_query("SELECT username FROM users ORDER BY registration_date DESC LIMIT 5", $link);

$newly_registered = array();
while($row=mysql_fetch_assoc($rs)) {
    $newly_registered[] = $row['username'];
echo "New users: " . implode(', ', $newly_registered);


I worked it out. the php:

//	Error report goes here if there are errors 

if (isset($errors)) {

echo "<div id=errors";

echo "\	\	\	\	", '<p class="form_text">The following errors occurred while processing your request. Please try again.</p>', "\
echo "\	\	\	\	", "\

foreach ($errors as $error)
echo "", $error, "\

echo "\	\	\	\	", "\

echo "</div";

had the closing div’s (>) missing. looked ok in previous blowsers.

Now it’s sorted you can ignore this!! :slight_smile: Thanks to anyone who already started to investigate! :slight_smile:

I was just about to post that :slight_smile:

A tip for future questions: wrap your code in [ code] and [/ code] (without the spaces) or [ php] and [/ php] (again, without the spaces). Makes it lots easier to read!

Thanks, will do.

SIde note really, but if I wanted to display the last say, 5 users to have registered, what’s the easiest way to do it?

I was going to re-use some php/mysql to do this, but not done this bit before…

SELECT foo, bar FROM table ORDER BY date_registered DESC LIMIT 5


Off Topic:

Immerse beat me to it with a much better example

Yep, that works… Cheers.

I’d written this: As a learning curve, what’s wrong with it?

$mysqlquery = mysql_query( "SELECT * FROM businesses order by date_registered limit 5" ) or die( mysql_error());

	  $row =  mysql_fetch_assoc($mysqlquery);

		echo $row['business_name']." </b>"; 
                echo $row['location']." </b>"; 

It won’t run? :wink:

ha - well, it does, but only returns the 1st entry in the table.

The other post solves my problem, but I just needed to know where mine goes wrong so I can learn from it.

Many thanks :0

You have your curly braces in place for a loop, but no loop code actually in place (e.g. for, foreach, while or whatever). :slight_smile:

It won’t, but anyway. :slight_smile:

$sql = 'SELECT * FROM businesses ORDER BY date_registered DESC LIMIT 5;';
$res = mysql_query($sql);

  echo 'Query Failed: ', $sql, PHP_EOL;
  echo 'Error: ', mysql_error(), PHP_EOL;

while($business = mysql_fetch_assoc($res)){
  echo $business['business_name']; #etc

I stand corrected! I apologise whole heartedly. This is valid code, well I never.

$foo = true;

  $foo = false;