gelijk.. hier beide stukjes code:
hier common.php wat de verbinding opstelt:
<?
// common.php
// Define database connection details
$dbHost = "";
$dbUser = "";
$dbPass = "";
$dbName = "";
// Common functions
/*********************************************************
** Function: dbconnect() **
** Desc: Perform database server connection and **
** database selection operations **
*********************************************************/
function dbConnect() {
// Access global variables
global $dbHost;
global $dbUser;
global $dbPass;
global $dbName;
// Attempt to connect to database server
$link = @mysql_connect($dbHost, $dbUser, $dbPass);
// If connection failed...
if (!$link) {
// Inform Flash of error and quit
fail("Couldn't connect to database server");
}
// Attempt to select our database. If failed...
if (!@mysql_select_db($dbName)) {
// Inform Flash of error and quit
fail("Couldn't find database $dbName");
}
return $link;
}
/*********************************************************
** Function: fail() **
** Params: $errorMsg - Custom error information **
** Desc: Report error information back to Flash **
** movie and exit the script. **
*********************************************************/
function fail($errorMsg) {
// URL-Encode error message
$errorMsg = urlencode($errorMsg);
// Output error information and exit
// print "&result=Fail&errormsg=$errorMsg";
exit;
}
/*********************************************************
** Function: auth() **
** Params: $username - Name of user to authenticate **
** $password - Passwd of user to authenticate **
** Desc: Authenticates a given user. Involves a **
** check that the given username and passwd **
** exists in users table. **
*********************************************************/
function auth($username, $password) {
$crypt = md5($password);
$query = "SELECT userID FROM users WHERE username = '$username' AND password = '$crypt'";
// Execute the query
$result = mysql_query($query);
// If we found a match...
if (mysql_num_rows($result) == 1) {
// Extract user ID from the results
$user = mysql_fetch_array($result);
$userID = $user['userID'];
} else {
// Otherwise set username to -1
$userID = -1;
}
// Return user ID
return $userID;
}
function checkEmail($email)
{
// Define regular expression
$regexp = "^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$";
if (eregi($regexp, $email)) {
return true;
}
else
{
return false;
}
}
?>
hier het contentbestand wat common.php aanroept:
<?php
// fetchnews.php
//Include('common.php')
include('common.php'); <<<<<<
//connect to the database
$link = dbConnect();
// Build query to subjects from database
$query = "SELECT * FROM main WHERE subjectID = '$subID'";
// Execute query
$result = @mysql_query($query);
// If query was okay..
if (!$result)
{
//inform flash of error and quit
fail("Subjects kunnen niet worden weergegeven");
}
//find out how many subjects are in the table
$subjectsCount = mysql_num_rows($result);
//for each user returned
for ($count = 0; $count < $subjectsCount; $count++)
{
$subject = mysql_fetch_array($result);
$subjectID = $subject['subjectID'];
$subjectName = $subject['subjectName'];
$title = $subject['title'];
$body = $subject['body'];
$output .= urlencode($body) . "<br>";
}
// output all subjects in one go
// echo $output;
// Close link to MySQL server
mysql_close($link);
?>