7 Replies - 7378 Views - Last Post: 31 March 2011 - 04:23 AM Rate Topic: -----

#1 Addio569  Icon User is offline

  • D.I.C Regular

Reputation: 3
  • View blog
  • Posts: 316
  • Joined: 26-November 08

Div's within PHP code?

Posted 31 March 2011 - 02:48 AM

I'm trying to get my div's to work within my PHP script but its erroring out, if I leave the divs out the html shows fine, but I want it uniform accross the whole of my site

this is my code:

       else 
        {
         echo"<html>
        <head>
        <link href='styles.css' rel='stylesheet' type='text/css' />
        </head>
        <body>
        <div id="main">
        <div id="header">
        </div>
        <div id="contentWrapper">
        <div id="leftBox">
        <div id="leftBoxContent">
        <div id="lightBox">
        </div>
        </div>
        </div>
        <div id="rightBox">
	</div>
        <div id="content">
        <p>Wrong Username or Bad Password.</p>
        <p><a href='./index.php'>Click Here</a> to try again.</p>
        </div>
       <br class="clearFloat" />
       </div>
       <div id="footer"></div>
       </div>
       </body>
       </html>";
        }
?>


its the else statement of my login check, like I said it works without the divs, but I must be doing something wrong...

thanks

Is This A Good Question/Topic? 0
  • +

Replies To: Div's within PHP code?

#2 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3512
  • View blog
  • Posts: 10,136
  • Joined: 08-June 10

Re: Div's within PHP code?

Posted 31 March 2011 - 02:55 AM

you have a quotation mark mismatch. were you to have error display enabled, you’d have got messages telling you that.

the best fix is to separate PHP and HTML by using templates. a quick’n’dirty fix would use the Heredoc syntax of strings.
Was This Post Helpful? 1
  • +
  • -

#3 Addio569  Icon User is offline

  • D.I.C Regular

Reputation: 3
  • View blog
  • Posts: 316
  • Joined: 26-November 08

Re: Div's within PHP code?

Posted 31 March 2011 - 03:10 AM

View PostDormilich, on 31 March 2011 - 02:55 AM, said:

you have a quotation mark mismatch. were you to have error display enabled, you’d have got messages telling you that.

the best fix is to separate PHP and HTML by using templates. a quick’n’dirty fix would use the Heredoc syntax of strings.


qoutation mismatch? a missing qoutation?

this is the whole code:

<?php
$host="localhost"; // Host name
$username="blank"; // Mysql username
$password="blank"; // Mysql password
$db_name="blank"; // Database name
$tbl_name="members"; // Table name

// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");

// username and password sent from form
$myusername=$_POST['myusername'];
$mypassword=$_POST['mypassword'];

// To protect MySQL injection (more detail about MySQL injection)
$myusername = stripslashes($myusername);
$mypassword = stripslashes($mypassword);
$myusername = mysql_real_escape_string($myusername);
$mypassword = mysql_real_escape_string($mypassword);

$sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'";
$result=mysql_query($sql);

// Mysql_num_row is counting table row
$count=mysql_num_rows($result);
// If result matched $myusername and $mypassword, table row must be 1 row


if($count){
            session_start();
           session_regenerate_id();
            $_SESSION['SESS_USERNAME'] = $myusername;
            $_SESSION['SESS_PASSWORD'] = $mypassword;
            session_write_close();
           header("location: login_success.php");
}
     
       else 
        {
         echo"<html>
        <head>
        <link href='styles.css' rel='stylesheet' type='text/css'/>
        </head>
        <body>
        <div id="main">
        <div id="header">
        </div>
        <div id="contentWrapper">
        <div id="leftBox">
        <div id="leftBoxContent">
        <div id="lightBox">
         </div>
        </div>
       </div>
       <div id="rightBox">
	</div>
       <div id="content">
        <p>Wrong Username or Bad Password.</p>
        <p><a href='./index.php'>Click Here</a> to try again.</p>
    </div>
    <br class="clearFloat"/>
  </div>
  <div id="footer"></div>
</div>
        </body>
        </html>";
        }
?>


how would I implement the quick dirty fix? I don't quite understand the Heredoc method..

This post has been edited by Addio569: 31 March 2011 - 03:12 AM

Was This Post Helpful? 0
  • +
  • -

#4 chinchang  Icon User is offline

  • Indie Game Developer
  • member icon

Reputation: 192
  • View blog
  • Posts: 725
  • Joined: 22-December 08

Re: Div's within PHP code?

Posted 31 March 2011 - 03:51 AM

Check out your echo statement starting on line 41. Does it seem to echo what you want ??

HINT : Match the "s in your echo statement.
Was This Post Helpful? 0
  • +
  • -

#5 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3512
  • View blog
  • Posts: 10,136
  • Joined: 08-June 10

Re: Div's within PHP code?

Posted 31 March 2011 - 03:58 AM

you’re not missing a quotation, quite the contrary.
Was This Post Helpful? 0
  • +
  • -

#6 Addio569  Icon User is offline

  • D.I.C Regular

Reputation: 3
  • View blog
  • Posts: 316
  • Joined: 26-November 08

Re: Div's within PHP code?

Posted 31 March 2011 - 04:13 AM

View PostDormilich, on 31 March 2011 - 03:58 AM, said:

you’re not missing a quotation, quite the contrary.


ok so this is what I did, after some searching...

       else 
        {
         echo"<html>
        <head>
        <link href='styles.css' rel='stylesheet' type='text/css'/>
        </head>
        <body>
        <div id='main'>
        <div id='header'>
        </div>
        <div id='contentWrapper'>
        <div id='leftBox'>
        <div id='leftBoxContent'>
        <div id='lightBox'>
         </div>
        </div>
       </div>
       <div id='rightBox'>
	</div>
       <div id='content'>
        <p>Wrong Username or Bad Password.</p>
        <p><a href='./index.php'>Click Here</a> to try again.</p>
    </div>
    <br class='clearFloat'/>
  </div>
  <div id='footer'></div>
</div>
        </body>
        </html>";
        }
?>


single quotes within double quotes, that works. but I would like to learn the proper way, but I'm not quite understanding it. I read that this would be a way:

<?php function echo_menu() { ?>
  <div id="menu">
    <a href="/home">Home</a>
  </div>
<?php }



is this right?

I don't understand why theres a open bracket before the ?> and then again a closed bracket before the <? at the end??

also while on the subject of PHP, when I log in more times than not I will have to login again, like the script lost its way while processing, just a minor niggle but if someone could take a look at it for me I'd be very grateful, you've all been so helpful, and I've learned a lot, and my wedding website is now coming to an end thanks to you guys and this forum!

)here is my code, I won't post it all here as its quite a lot, so I've pasted binned it, unless for educational reasons I have to post it:)

http://pastebin.com/r3us5dFZ

thanks again
Was This Post Helpful? 0
  • +
  • -

#7 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3512
  • View blog
  • Posts: 10,136
  • Joined: 08-June 10

Re: Div's within PHP code?

Posted 31 March 2011 - 04:18 AM

View PostAddio569, on 31 March 2011 - 01:13 PM, said:

<?php function echo_menu() { ?>
  <div id="menu">
    <a href="/home">Home</a>
  </div>
<?php }



is this right?

from the point of syntax—yes, from the point of design—no.


View PostAddio569, on 31 March 2011 - 01:13 PM, said:

I don't understand why theres a open bracket before the ?> and then again a closed bracket before the <? at the end??

because it is bad design. do yourself a favour and forget about that "solution".
Was This Post Helpful? 1
  • +
  • -

#8 Addio569  Icon User is offline

  • D.I.C Regular

Reputation: 3
  • View blog
  • Posts: 316
  • Joined: 26-November 08

Re: Div's within PHP code?

Posted 31 March 2011 - 04:23 AM

View PostDormilich, on 31 March 2011 - 04:18 AM, said:

View PostAddio569, on 31 March 2011 - 01:13 PM, said:

<?php function echo_menu() { ?>
  <div id="menu">
    <a href="/home">Home</a>
  </div>
<?php }



is this right?

from the point of syntax—yes, from the point of design—no.


View PostAddio569, on 31 March 2011 - 01:13 PM, said:

I don't understand why theres a open bracket before the ?> and then again a closed bracket before the <? at the end??

because it is bad design. do yourself a favour and forget about that "solution".


ah ok, will do!

ended up doing this:

else 
{
  include("loginhtml.html");
} 
?>


which outputs loginhtml.html:

 <html>
        <head>
        <link href="styles.css" rel="stylesheet" type="text/css"/>
        </head>
        <body>
        <div id="main">
        <div id="header">
        </div>
        <div id="contentWrapper">
        <div id="leftBox">
        <div id="leftBoxContent">
        <div id="lightBox">
         </div>
        </div>
       </div>
       <div id="rightBox">
	</div>
       <div id="content">
        <p>Wrong Username or Bad Password.</p>
        <p><a href='./index.php'>Click Here</a> to try again.</p>
    </div>
    <br class="clearFloat"/>
  </div>
  <div id="footer"></div>
</div>
        </body>
        </html>

This post has been edited by Addio569: 31 March 2011 - 04:49 AM

Was This Post Helpful? 1
  • +
  • -

Page 1 of 1