I am just trying to write a php code to connect to a database that I have. Every way I can think of is giving me this error,,,,,
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /home/ecstasys/public_html/chatregister.php on line 2
Parse error: parse error, unexpected T_STRING in /home/ecstasys/public_html/chatregister.php on line 2
I am a idiot when it comes to php and this little warning tells me even less of what I am doing wrong.
Someone please help me out.
here is my files that are supposed to work together and make a connection and make a new database.
common.php:
<?
// common.php
$dbHost = “localhost”;
$dbUser = “ecstasy_Topgun”;
$dbPass = “mypass”;
$dbName = “ecstasy_squad2”;
function fail($errorMsg = “”) {
print “&result=Fail&errorMsg=”” . urlencode($errorMsg);
exit;
}
?>
db.php (downloaded to help me out from advancedphpforflash site)
<?
// db.php
// Chapter 11 - Advanced PHP for Flash
// Class: DB
// MySQL database connection wrapper
class DB
{
// connection parameters
var $host = 'localhost';
var $user = 'ecstasy_Topgun';
var $pass = 'mypass';
var $database = 'ecstasy_squad2';
var $persistent = false;
var $link = NULL;
var $result = false;
// Constructor
// Initializes member variables
function DB($host, $user, $pass, $database='', $persistent = false) {
$this->host = $host;
$this->user = $user;
$this->pass = $pass;
$this->database = $database;
$this->persistent = $persistent;
}
// Method: connect()
// Establishes a connection to the database server. Returns true or false
// depending on whether the operation was successful or not.
function connect() {
// Choose the appropriate connect function
if ($this->persistent) {
$func = 'mysql_pconnect';
} else {
$func = 'mysql_connect';
}
// Connect to the MySQL server and report any errors
$this->link = $func($this->host, $this->user, $this->pass);
if (!$this->link) {
return false;
}
// If a database has been specified then attempt to seelct it
if ($this->database != "") {
if (!@mysql_select_db($this->database, $this->link)) {
return false;
}
}
// Return success to calling function
return true;
}
// Method: close()
// Terminates the connection to the database. Returns true if the
// connection was terminated successfully, and false otherwise.
function close() {
return (@mysql_close($this->link));
}
// Method: error()
// Returns the error message, is any, from the last database operation
// performed.
function error() {
return (mysql_error());
}
// Method: query()
// Standard query function which returns true if the query was successfully
// executed and false otherwise.
function query($sql = '') {
$this->result = @mysql_query($sql, $this->link);
return ($this->result != false);
}
// Method: queryFirst()
// A specialised query function that executes the query and then returns
// the first row from the result set. Used for SELECT queries only.
function queryFirst($sql) {
// Execute query
$this->result = @mysql_query($sql, $this->link);
// If query failed then exit
if (!$this->result) {
return false;
}
// Fetch first row from result set as an associative array
$returnArray = mysql_fetch_array($this->result, MYSQL_ASSOC);
// Return array to calling function
return $returnArray;
}
// Method: affectedRows()
// Invokes the standard mysql_affected_rows() function to find out the
// number of rows affected by the previous query.
function affectedRows() {
return (@mysql_affected_rows($this->link));
}
// Method: numRows()
// Invokes the standard mysql_num_rows() function and returns the number of
// rows returned by the previous SELECT query.
function numRows() {
return (@mysql_num_rows($this->result));
}
// Method: fetchObject()
// Returns the next row from the result set as an object
function fetchObject() {
return (@mysql_fetch_object($this->result, MYSQL_ASSOC));
}
// Method: fetchArray()
// Returns the next row from the result set as a numerically indexed array
function fetchArray() {
return (@mysql_fetch_array($this->result, MYSQL_NUM));
}
// Method: fetchAssoc()
// Returns the next row from the result set as an associative array
function fetchAssoc() {
return (@mysql_fetch_assoc($this->result));
}
// Method: freeResult()
// Uses the standard mysql_free_result() function to free the current
// result set.
function freeResult() {
return (@mysql_free_result($this->result));
}
// Method: insertID()
// Returns the AUTO_INCREMENT column value for the row added by the
// previous query.
function insertID() {
return (@mysql_insert_id($this->link));
}
}
?>
and last my setup.php
<?
// setup.php
require ("common.php");
require ("db.php");
$myDB = new DB($dbHost, $dbUser, $Pass);
$myDB->connect();
print "Attempting to create $dbName database<br>";
// Attempt to create database
if($myDB->query("CREATE DATABASE $dbName")){
print "Database $dbName created<br>";
}else{
print "Warning - Failed to create database $dbName<br>";
}
// Select database
if (!mysql_select_db($dbName)) {
print "Error selecting $dbName database";
exit
}
print "<br>Setting up database structure<br>";
// Create chatUsers table
$query = "CREATE TABLE chatUsers {
userID INTEGER AUTO_INCREMENT PRIMARY KEY,
username VARCHAR(30),
email VARCHAR(255),
password VARCHAR(30))";
if (!$myDB->query($query)) {
print "error creating chatUsers table<br>";
}
// Create chatMessages table
$query = "CREATE TABLE chatMessages (
body TEXT,
posted INTEGER);
if (!$myDB->query($query)) {
print "Error creating chatMessages table<br>";
}
// Create chatUserList table
$query = "CREATE TABLE chatUserList (
userID INTEGER NOT NULL UNIQUE,
lastActivity INTEGER)";
if (!$myDB->query($query)) {
print "Error creating chatUserList table<br>";
}
print "All done";
$myDB->close();
?>
PLEASE HELP!!!!!!!
Thanks in advance.
topgun out>>>