FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


i am having problems with this php code.... can someone help





evablast1
someone help me find the fault




<?php


function new_user($name, $password, $type, $email){
global $DB_CONNECTION;

$number = substr(number_format(time() * rand(),0,'',''),0,10);
$code = substr(number_format(time() * rand(),0,'',''),0,5);

$target = "passports/";
$target = $target . $number.'.jpg';
//Writes the photo to the server
if(move_uploaded_file($_FILES['picture']['tmp_name'], $target))
{
$query = "INSERT INTO `account` (`account_number`, `password`, `code`, `status`, `account_type`, `currency`, `name`,`email`) VALUES ('{$number}', '{$password}', '{$code}', 'INACTIVE', '{$type}', 'GBP', '{$name}', '{$email}')";
$DB_CONNECTION->query($query);
return "Your request has been recieved and is being processed. You will be contacted through the email provided!";
}
else {

return "Sorry, there was a problem processing your request.";
}

}

function login1($account, $password){
global $DB_CONNECTION;

$query = "SELECT `status` FROM `account` WHERE `account_number` = '{$account}' AND `password` = '{$password}'";
$result = $DB_CONNECTION->query($query);
if ($result->num_rows != 1) return array('ERROR'=>'Invalid account number or password!');

$row = $result->fetch_object();
if ($row->status != 'ACTIVE') return array('ERROR'=>'Your account opening request is currently being reviewed.');
return array('SUCCESS'=>'');
}

function login2($account, $password, $code){
global $DB_CONNECTION;

$query = "SELECT * FROM `account` WHERE `account_number` = '{$account}' AND `password` = '{$password}' AND `code` = '{$code}'";
$result = $DB_CONNECTION->query($query);
if ($result->num_rows == 1){
$_SESSION['account'] = $account;
$_SESSION['password'] = $password;
$_SESSION['time'] = time();
$_SESSION['code'] = $code;
return array('SUCCESS'=>'');
}
else return array('ERROR'=>'Invalid Key Code!');
}

function get_user($account){
global $DB_CONNECTION;

$query = "SELECT `name`,`currency` FROM `account` WHERE `account_number`='{$_SESSION['account']}'";
$result = $DB_CONNECTION->query($query);
$result = $result->fetch_object();

$name = $result->name;
$currency = $result->currency;

return array('name'=>$name,'currency'=>$currency,'account'=>$_SESSION['account']);
}

function get_transactions($account){
global $DB_CONNECTION;

$balance = 0;
$query = "SELECT * FROM `transaction` WHERE `account_number`='{$account}' ORDER BY `time` ASC";
$result = $DB_CONNECTION->query($query);
while (list($acc, $reference, $type, $amount, $remarks, $time) = $result->fetch_row()){
$date = Date("d-M-Y",$time);
if ($type == 'credit'){
$credit = number_format($amount, 0);
$debit = '';
$balance = $balance + $amount;
}else{
$credit = '';
$debit = number_format($amount, 0);
$balance = $balance - $amount;
}
$transactions[] = array(
'reference'=>$reference,
'date'=>$date,
'credit'=>$credit,
'debit'=>$debit,
'balance'=>number_format($balance, 2),
'remarks'=>$remarks
);
}
$transactions = @array_reverse($transactions);
return $transactions;
}

function change_password($account, $current, $password1, $password2){
global $DB_CONNECTION;

if ($password1 != $password2) return "Passwords don't match!";

$query = "SELECT `password` FROM `account` where `account_number` = '{$account}'";
$result = $DB_CONNECTION->query($query);
$result = $result->fetch_object();
$password = $result->password;
if ($password != $current) return "Password not correct!";

$query = "UPDATE `account` SET `password` = '{$password1}' WHERE `account_number` = {$account}";
$result = $DB_CONNECTION->query($query);
if ($DB_CONNECTION->affected_rows > 0) return "Your password has been updated and the changes will take effect on your next login.";
}

function singin_admin($username, $password){
global $DB_CONNECTION;

$query = "SELECT * FROM `admin` WHERE `username` = '{$username}' AND `password` = '{$password}'";
$result = $DB_CONNECTION->query($query);
if ($result->num_rows = 1){
$_SESSION['admin'] = $username;
$_SESSION['time'] = time();
return array('SUCCESS'=>'');
}
else return array('ERROR'=>'Invalid username or password!');
}
sonam
Please type what error you get? It is not easy just from script to find what is wrong. Rolling Eyes
Try to insert on the top

Code:
error_reporting(E_ALL);
ini_set("display_errors", "1");


Sonam
jmraker
The code has no syntax errors, so a runtime error message would help pinpoint the problem.

It looks like you're using the mysqli class.

To be safer from sql injection attacks you should consider using prepared statements when the query uses input from the user
http://www.php.net/manual/en/mysqli.prepare.php

The function name "singin_admin" seems to be a misspelling
Related topics
simple php problem, please help...
Can someone help me ? Com domain setup?
Show PHP Code
CAN SOMEONE HELP? I DON'T UN DERSTAND HOW TO UPLOAD WEBSITE!
mySQL Query/PHP code - get the highest value...
my PHP code benchmark script that got some problems
Problem getting started---total newb
php..free account help
CSS for making images go through a php code.
Problems with php + mysql script.
What is a good or bad php code?
I want PHP Code to ......
Help With Simple PHP Code Snipit
removing DirectAdmin part of URL makes php code work
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.