Jump to content

[SOLVED] Which one is correct?


robert_gsfame

Recommended Posts

require_once['bla.php'] ----> it's a connection to mysql database

 

bla.php

$host="localhost";

$username="xxxx";

$password="xxxx";

$db_name="xxxx";

 

mysql_connect("$host", "$username", "$password")or die("cannot connect to server");

mysql_select_db("$db_name")or die("cannot select DB");

 

 

<head></head> and <body></body> tags only have meaning in a browser where they are rendered, same for all the other HTML tags and CSS and Javascript. They don't actually have any meaning in a php file.

 

Php outputs content (HTML/SCC/Javascript) to a browser. You put php code in a .php file wherever it is needed to perform its' intended purpose. If you need to require_once a setting file or a file that contains function/class definition(s), you do that near the start of the code so that the settings/functions/classes are available in the remainder for the code. If you need to require_once a file that contains content that goes in the head of a web page, you do that inside of the <head></head> tags...

Is it correct if i put this way

 

<?php session_start();?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title></title>

<meta name="description">

<meta name = "keywords">

<style type = "text/css">

</style>

<script src="Scripts/AC_RunActiveContent.js" type="text/javascript"></script>

<?php require_once['config.php'];?>

</head>

 

 

i created this using dreamweaver, and when i put this way, highlighted <?> mark appeared on my properties

 

is there something wrong with the code, can explain it to me about the meaning of that error?

 

 

 

i don't use dreamweaver...so i can't answer that question...

 

is there anything "wrong" with the code...absolutely not, that code will run fine.

 

is the code "correct"...well, that is tougher to say as you are the only one that knows what the final output should be. if the outcome is what you expect, then i would say it's fine

 

does it follow "normal standards"...i would say no, and the norm is to put the inclusion of a config file at the top of your script:

<?php
  session_start();
  require_once('config.php');
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<meta name="description">
<meta name = "keywords">
<style type = "text/css">
</style>
<script src="Scripts/AC_RunActiveContent.js" type="text/javascript"></script>
</head>

p.s. - i also noticed that you were using [] instead of () in your require_once

Archived

This topic is now archived and is closed to further replies.

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