Jump to content

learning php


j05hr

Recommended Posts

i'm really confused as to why this doesn't work

 

Parse error: syntax error, unexpected T_VARIABLE in C:\wamp\www\widget.corp\includes\connection.php on line 4

 

content.php:

<?php require_once("includes/connection.php"); ?>
<?php require_once("includes/functions.php"); ?>
<?php include("includes/header.php"); ?>
<table id="structure">
<tr>
	<td id="navigation">
		<ul class=>"subjects">
	<?php

	$subject_set = mysql_query("SELECT * FROM subjects", $connection);
	if(!$subject_set) {
		die("Database query failed: " . mysql_error());
	}

	while ($subject = mysql_fetch_array($subject_set)) {
		echo "<li>{$subject["menu_name"]}</li>";
		$page_set = mysql_query("SELECT * FROM pages WHERE subject_id = {$subject["id"]}", $connection);
		if(!$result) {
			die("Database query failed: " . mysql_error());
		}

		echo "<ul class=\ \"pages\">";
		while ($page = mysql_fetch_array($page_set)) {
			echo "<li>{$page["menu_name"]}</li>";
		}
		echo "</ul>";

	}

	?>
		</ul>
	</td>
	<td id="page">
		<h2>Content Area</h2>

	</td>
</tr>
</table>
<?php include("includes/footer.php"); ?>

 

connection.php

<?php
require("constants.php")
// 1. create a database connection
$connection = mysql_connect(DB_SERVER, DB_USER, DB_PASS);
if (!$connection) {
die("Database connection failed: " . mysql_error());
}

// 2. Select a database to use
$db_select = mysql_select_db("DB_NAME",$connection);
if (!$db_select) {
	die("Database selection failed: " . mysql_error());
}
?>

 

constants.php:

<?php

// Database Constants
define("DB_SERVER", "localhost")
define("DB_USER", "root")
define("DB_PASS", "telephone")
define("DB_NAME", "localhost")

Link to comment
Share on other sites

  • Replies 115
  • Created
  • Last Reply

Top Posters In This Topic

You need semi-colons at the end of every line in contants.php

<?php
// Database Constants
define("DB_SERVER", "localhost");
define("DB_USER", "root");
define("DB_PASS", "telephone");
define("DB_NAME", "localhost");
?>

 

Also, just a styling note -- don't go in/out of php on every line. This:

<?php require_once("includes/connection.php"); ?>
<?php require_once("includes/functions.php"); ?>
<?php include("includes/header.php"); ?>

should be written as

<?php
require_once("includes/connection.php");
require_once("includes/functions.php");
include("includes/header.php");
?>

 

Ken

 

 

Link to comment
Share on other sites

sorry did not see the replies...the corrections i would of made are already done. i have removed my edits due to that.

 

cheers anyway do you know by default if my username would be root? as i never had to enter it before but now its come up and in the video it's root so i assumed the fault user is root?

Link to comment
Share on other sites

sorry did not see the replies...the corrections i would of made are already done. i have removed my edits due to that.

 

cheers anyway do you know by default if my username would be root? as i never had to enter it before but now its come up and in the video it's root so i assumed the fault user is root?

 

for the database -> yes usually in my experience it has been root if you are running on your localhost. if you are running it on a live web server it could by anything from usernametologin_name to just name.

 

You can always double check with your hosting provider to determine that. They should be able to tell you what it is. They would not be able to tell you what the password is if I remember right from experience.

Link to comment
Share on other sites

With that he means that if you had purchased some web space off a company and they provided your PHP / MySQL .. In that case you could contact them to get the login name, but with what you have installed I can't see no reason why it wouldn't be root at all... ?

 

Does it not work?

 

Adam

Link to comment
Share on other sites

these are the three pages i'm using and i can't see any differences between my code and what i'm copying it from

 

content.php

<?php 
require_once("includes/connection.php"); 
require_once("includes/functions.php"); 
include("includes/header.php"); 
?>
<table id="structure">
<tr>
	<td id="navigation">
		<ul class=>"subjects">
	<?php

	$subject_set = mysql_query("SELECT * FROM subjects", $connection);
	if(!$subject_set) {
		die("Database query failed: " . mysql_error());
	}

	while ($subject = mysql_fetch_array($subject_set)) {
		echo "<li>{$subject["menu_name"]}</li>";
		$page_set = mysql_query("SELECT * FROM pages WHERE subject_id = {$subject["id"]}", $connection);
		if(!$result) {
			die("Database query failed: " . mysql_error());
		}

		echo "<ul class=\ \"pages\">";
		while ($page = mysql_fetch_array($page_set)) {
			echo "<li>{$page["menu_name"]}</li>";
		}
		echo "</ul>";

	}

	?>
		</ul>
	</td>
	<td id="page">
		<h2>Content Area</h2>

	</td>
</tr>
</table>
<?php include("includes/footer.php"); ?>


 

connection.php

<?php
require("constants.php")

// 1. create a database connection
$connection = mysql_connect(DB_SERVER,DB_USER,DB_PASS));
if(!$connection) {
die("Database connection failed: " .mysql_error());
}

// 2. Select a database to use
$db_select = mysql_select_db("DB_NAME",$connection);
if (!$db_select) {
	die("Database selection failed: " . mysql_error());
}
?>

 

constants.php

<?php

// Database Constants
define("DB_SERVER", "localhost");
define("DB_USER", "root");
define("DB_PASS", "orbeau");
define("DB_NAME", "widget_corp");

?>

Link to comment
Share on other sites

if you are really serious about continuing php you should get a IDE that does syntax highlighting i use phpDesigner it has a build in thing that uses a php.exe to evaluate your code and will report back on all your errors live

so you don't miss out random ;'s

 

Scott.

Link to comment
Share on other sites

thanks scott that was really helpful

 

i got a new error message away from php i think it's to do with mysql but it confuses me as to why it wouldn't work because i made a table called subjects.

 

the error message:

"subjects">

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\wamp\www\widget.corp\content.php on line 17

 

<?php 
require_once("includes/connection.php"); 
require_once("includes/functions.php"); 
include("includes/header.php"); 
?>
<table id="structure">
<tr>
	<td id="navigation">
		<ul class=>"subjects">
	<?php

	$subject_set = mysql_query("SELECT * FROM subjects", $connection);
	if(!$subject_set) {
		die("Database query failed: " . mysql_error());
	}

	while ($row = mysql_fetch_array($result)) {
		echo "<li>{$row["menu_name"]}</li>";
		$result = mysql_query("SELECT * FROM pages". $connection);
		if (!$result) {
			die("Database query failed: " .mysql_error());
		}

		echo "<ul class=\ \"pages\">";
		while ($page = mysql_fetch_array($page_set)) {
			echo "<li>{$page["menu_name"]}</li>";
		}
		echo "</ul>";

	}

	?>
		</ul>
	</td>
	<td id="page">
		<h2>Content Area</h2>

	</td>
</tr>
</table>
<?php include("includes/footer.php"); ?>


 

Link to comment
Share on other sites

I asked my provider if i had web hosting with php to which he replied.

 

Yes, PHP is supported on your plan and you do not have to do anything as I have installed the PHP valueapp for you.

 

So does this mean i can just load the php file into my ftp? And if so where does the data go when someone submits a form?

Link to comment
Share on other sites

Are the the lynda.com tutorials? i got stuck on them, i copied his code etc exact and didnt work to :(

 

yeah it's the lynda.com tutorials, it's very good but he goes through it so fast and someone like me trying to learn it as a beginner is very confusing but got there in the end

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.