Hey, I'm making my first user registration database, and am getting this error on both documents... I've checked the syntax, don't see anything. I'm using fetch to upload this stuff, is it a problem if it's not uploaded in Ascii?
<?php
//includes the database classes
require_once('../classes/database.php');
if(!get_magic_quotes_gpc()){
foreach($POST as $key=>$value){
$temp = addslashes($value);
$POST[$key] = $temp;
}
}
$db = new Database('localhost','name','pass','table');
$sql = 'SELECT username FROM Users WHERE username = "'.$_POST['username'].'"';
$result = $db->query($sql);
$numrows = $result->num_rows;
//if username already exists
if ($numrows > 0) {
$duplicate = 'Duplicate username. Please choose another.';
echo 'duplicate=y&message='.urlencode($duplicate);
}
else { //insert the data into the users data table
$sql = 'INSERT INTO Users (user, pwd, email, zipcode, country) VALUES ("'.$POST['username'].'","'.sha1($POST['pwd']).'","'.$POST['email'].'","'.$POST['zipcode'].'","'.$POST['country'].'"';
$result = $db->query($sql);
if ($result) {
$created = 'Account created for '.$POST['username'];
echo 'duplicate=n&message='.urlencode($created);
}
}
?>
<?php
class Database {
var $host;
var $user;
var $pwd;
var $dbName;
var $flash;
var $dbLink;
var $result;
var $resultObj;
function Database($host, $user, $pwd, $dbName, $flash=1){
$this->host = $host
$this->user = $user;
$this->pwd = $pwd;
$this->dbName = $dbName;
$this->flash = $flash;
$this->connect();
}
// Connect to the MYSQL server and select databse
function connect() {
$this->dbLink = @mysql_pconnect($this->host, $this->user, $this->pwd);
if (!$this->dbLink){
$error = 'Couldn\'t connect to mySQL Server';
echo $this->flash ? 'error='.urlencode($error) : $error;
exit();
}
if (!mysql_select_db($this->dbName, $this->dbLink)) {
$error = 'Couldn\'t open Database: '. $this->dbName;
echo $this->flash ? 'error='.urlencode($error) : $error;
exit();
}
return $this->dbLink;
}
//execute a SQL query
function query($query) {
$this->result = mysql_query($query, $this->dbLink);
if (!$this->result) {
$error = 'MySQL Error: ' . mysql_error();
echo $this->flash ? 'error='.urlencode($error) : $error;
exit();
}
//store result in new object to emulate mysqli 00 interface
$this->resultOBJ = new MyResult($this->result);
return $this->resultObj;
}
function close(){
//closes the mysql connection
mysql_close($this->dbLink);
}
}
class MyResult {
var $theResult;
var $num_rows;
function MyResult(&$r) {
$this->theResult = $r;
// get number of records found
$this->num_rows = mysql_num_rows($r);
}
//fetch associative array of result (works on one row at a time)
function fetch_assoc(){
$newRow = mysql_fetch_assoc($this->theResult);
return $newRow;
}
}
?>