Jump to content

[SOLVED] Which one is correct?


robert_gsfame

Recommended Posts

where the require is (abstractly speaking) doesn't matter. what matters is that the code inside the include is in the correct spot. so, if what is inside blah.php should be between the head tags, then put it there

Link to comment
Share on other sites

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");

 

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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?

 

 

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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