MySQL Forums
Forum List  »  PHP

mysql 4.1 and php 4.4
Posted by: ronald koh
Date: January 20, 2006 06:30PM

Hi all, can yall help me on this? i just downloaded mysql ver4.1 and php ver4.4
I had coded my webpage using php and now i want to link the whole php to mysql, using mysql as the database. The thing is it seems i cant do it. I had entered a dummy record into one of the user's table, but whenever i login using that username n password, it just wont allow me to login. Below is my db.php, login.php and function.php. somoone pls help me to see? I dont see any problem as my code is very clean, but somehow i cant connect. Keeps telling me Username/password empty. Thanks.
----------------------------------db.php---------------------------------------
<?php
//setting for database.
$user="root";
$pass="hotsizzle";
$database="offshore";
$host="localhost";


// connect to the database server
if (!($db = mysql_connect($host, $user , $pass))){
die("Can't connect to database server.");
}else{
// select a database
if (!(mysql_select_db("$database",$db))){
die("Can't connect to database.");
}
}


//including variabel.
@include "variabel.php";

mysql_close();
?>
--------------------------------------------------------------------------

--------------------------------------login.php------------------------------------------

<?php
// script by sevens spirits
// site http://sevens.host.sk
// email: sevens@host.sk
session_start();

require_once "function.php";
require_once "db.php";

if (empty($name) || empty($password))
{
include "header.php";
echo "Username/password empty.";
include "footer.php";
exit;
}
// 1rst setting
$res_login = 0;
$res_email = "";
$res_egold = "";
$res_ref = "";
$res_upline="";
$res_balance="";

$conn = doConnect();

$password = md5($password);
$sql = "select * from users where ((name='$name') and (pass='$password'))";
$res = doQuery($sql,$conn);
$row = getRow($res);

if ($row==1)
{
$data = getRecord($res);
session_register("res_uid", "res_login", "res_email", "res_egold", "res_upline","res_balance");
$res_uid = $data[0];
$res_login = 1;
$res_email = $data[3];
$res_egold = $data[4];
$res_up = trim($data[6]);
if (!empty($res_up))
{
// get Upline
$sql = "select uid from users where (name='$res_up')";
$rest = doQuery($sql,$conn);
$datat = getRecord($rest);
$res_upline= $datat[0];
}
//get Balance
$sql = "select * from balance where (uid='$res_uid')";
$res = doQuery($sql,$conn);
$datax = getRecord($res);
$res_balance = $datax[2];

//echo "$res_email, $res_login, $res_egold, $res_upline, $res_balance, $res_up";
header("location: history.php");
}
else
{
$res_login = 0;
$res_email = "";
$res_egold = "";
$res_ref = "";
$res_upline="";
$res_balance="";
session_unregister("res_uid");
session_unregister("res_login");
session_unregister("res_email");
session_unregister("res_egold");
session_unregister("res_upline");
session_unregister("res_balance");
echo "login failed.";
}

?>
-------------------------------------------------------------------------------


------------------------------------------------function.php-------------------------------------

<?php
// script by sevens spirits
// site http://sevens.host.sk
// email: sevens@host.sk

function getPassword() {
$makepass="";
$syllables="er,in,tia,wol,fe,pre,vet,jo,nes,al,len,son,cha,ir,ler,bo,ok,tio"
.",nar,sim,ple,bLa,ten,77,toe,cho,co,lat,spe,ak,er,po,co,lor,pen,cil"
.",li,ght,wh,at,The,77,he,ck,is,mam,bo,no,fi,ve,any,way,pol,iti,cs,ra"
.",dIo,soU,rcE,sEa,Rch,pa,77,per,com,bo,sp,eak,st,fi,rst,gr,oup,boy,ea"
.",gle,tr,ail,bi,ble,brb,77,pri,dee,kay,en,be,se,div,gta,tta,lnk,sev"
.",ann,ron,dea,ens,7s";
$syllable_array=explode(",", $syllables);
srand((double)microtime()*1000000);
for ($count=1;$count<=4;$count++) {
if (rand()%10 == 1) {
$makepass .= sprintf("%0.0f",(rand()%50)+1);
} else {
$makepass .= sprintf("%s",$syllable_array[rand()%62]);
}
}
return($makepass);
}

function doConnect()
{
if (!(@include "db.php"))
@include "../db.php";
$conn = @mysql_connect($host, $user, $pass);
@mysql_select_db($db, $conn);
return $conn;
}

function doQuery($sqlstring, $conn)
{
$res = @mysql_query($sqlstring, $conn);
return $res;
}

function getAffected($conn)
{
$row = @mysql_affected_rows($conn);
return $row;
}

function getRow($res)
{
$row = @mysql_num_rows($res);
return $row;
}

function getRecord($res)
{
$record = @mysql_fetch_row($res);
return $record;
}


function isValidEmail($email)
{
if (empty($email))
{
return 0;
exit;
}

if (!ereg("^.+@.+\\..+$", $email))
{
return 0;
exit;
}

return 1;
}

function isValidUsername($username)
{
if (empty($username))
{
return 0;
exit;
}

if (ereg(" ", $username))
{
return 0;
exit;
}

if (ereg("^[0-9]", $username))
{
return 0;
exit;
}

if (eregi("[^a-z][^0-9]", $username))
{
return 0;
exit;
}

return 1;
}


function getInterest($modal, $pbunga, $n)
{
$bunga = 0;
for($i=1; $i<=$n; $i++)
{
$modal = $modal + $bunga;
$bunga = $modal * $pbunga;
}
return $bunga;
}

function beDecimal($number)
{
return sprintf("%01.2f", $number);
}

function beCurrency($number)
{
$amount_new = number_format($number, 2, '.', ',');
return $amount_new;
}

function getPayment($deposit, $tanggal_deposit, $tanggal_sekarang)
{
include "variabel.php";
$payment = 0;

$selisih_tanggal = dateDiff("d", $tanggal_deposit, $tanggal_sekarang);

if ($selisih_tanggal > 0)
{
if ($selisih_tanggal > $max_day_daily)
{
$selisih_tanggal = $max_day_daily;
}

$payment = $deposit * $interest_daily * $selisih_tanggal;
}

return $payment;
}


function isEndOfMonth($date)
{
$date = Date2Micro($date);
$date_temp1 = getDate($date);
$date_temp2 = getDate($date + 24 * 60 * 60);
if ($date_temp1["mon"] != $date_temp2["mon"])
{
return true;
}
else
{
return false;
}
}

function Micro2Date($mkdate)
{
return Date("Y-m-d H:i:s", $mkdate);
}

function Date2Micro($date)
{
$yea1 = substr($date, 0, 4);
$mon1 = substr($date, 5, 2);
$dat1 = substr($date, 8, 2);
$hou1 = substr($date, 11, 2);
$min1 = substr($date, 14, 2);
$sec1 = substr($date, 17, 2);

$tanggal1 = mktime($hou1, $min1, $sec1, $mon1, $dat1, $yea1);

return $tanggal1;
}

function getCountOfKabisat($date1, $date2)
{
$date1 = getDate(Date2Micro($date1));
$date2 = getDate(Date2Micro($date2));

$year1 = $date1["year"];
$year2 = $date2["year"];

if ($year1 > $year2)
{
$temp = $year1;
$year1 = $year2;
$year2 = $temp;
}

$nkabisat = 0;

for ($i = $year1; $i <= $year2; $i++)
{
if (($i % 4) == 0)
{
$nkabisat ++;
}
}

return $nkabisat;
}

function getEndOfMonth($date)
{
$date = Date2Micro($date);
$date_temp1 = getDate($date);

$date_year = $date_temp1["year"];
$date_month = $date_temp1["mon"];
$date_date = $date_temp1["mday"];
$date_hour = $date_temp1["hours"];
$date_minute = $date_temp1["minutes"];
$date_second = $date_temp1["seconds"];
$date_month ++;

if ($date_month > 12)
{
$date_month = 1;
$date_year ++;
}

$date_temp2 = mktime($date_hour, $date_minute, $date_second, $date_month, 1, $date_year);
$date_result = $date_temp2 - (24 * 60 * 60);

return $date_result;
}

function dateDiff($interval, $date1, $date2)
{
$yea1 = substr($date1, 0, 4);
$mon1 = substr($date1, 5, 2);
$dat1 = substr($date1, 8, 2);

$hou1 = 0;
$min1 = 0;
$sec1 = 0;

$yea2 = substr($date2, 0, 4);
$mon2 = substr($date2, 5, 2);
$dat2 = substr($date2, 8, 2);

$hou2 = 0;
$min2 = 0;
$sec2 = 0;

$tanggal1 = mktime($hou1, $min1, $sec1, $mon1, $dat1, $yea1);
$tanggal2 = mktime($hou2, $min2, $sec2, $mon2, $dat2, $yea2);

$selisih = $tanggal2 - $tanggal1;

switch ($interval)
{
case "Y":
case "y":
$pembagi = 365 * 60 * 60;
break;
case "M":
case "m":
$pembagi = 30.5 * 60 * 60;
break;
case "D":
case "d":
$pembagi = 24 * 60 * 60;
break;
}

$selisihhari = $selisih / $pembagi;

return floor($selisihhari);
}

function dateAdd($interval, $number, $date)
{
$date = Date2Micro($date);
$date_temp = getDate($date);
$date_year = $date_temp["year"];
$date_month = $date_temp["mon"];
$date_date = $date_temp["mday"];
$date_hour = $date_temp["hours"];
$date_minute = $date_temp["minutes"];
$date_second = $date_temp["seconds"];

switch ($interval)
{
case "Y":
case "y":
$new_date_year = $date_year + $number;
if (($new_date_year % 4) != 0)
{
if (($date_month == 2) && ($date_date == 29))
{
$date_date = 28;
}
}
$date = mktime($date_hour, $date_minute, $date_second, $date_month, $date_date, $new_date_year);
break;
case "M":
case "m":
$new_date_month = $date_month + $number;
$date_year += floor($new_date_month / 12);
$new_date_month %= 12;

if (isEndOfMonth($date))
{
switch ($new_date_month)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
$date_date = 31;
break;
case 2:
if (($date_year % 4) == 0)
{
$date_date = 29;
}
else
{
$date_date = 28;
}
break;
default:
$date_date = 30;
break;
}
}

$new_date = mktime($date_hour, $date_minute, $date_second, $new_date_month, $date_date, $date_year);

if (isEndOfMonth($date))
{
$new_date = getEndOfMonth($new_date);
}

$date = $new_date;
break;
case "D":
case "d":
$date += ($number * 24 * 60 * 60);
break;
}
$date = date("Y-m-d", $date);
return $date;
}

function iif($bool, $true, $false)
{
if ($bool == true)
{
return $true;
}
else
{
return $false;
}
}

function formatDate($date)
{
list($year,$month,$day) = split ('-',$date);
$ndate = $month."/".$day."/".$year;
return $ndate;
}

function getEmpty($data)
{
if (empty($data))
$data = 0;
else
$data = beCurrency($data);
return $data;
}
?>
--------------------------------------------------------------------------------

Options: ReplyQuote


Subject
Written By
Posted
mysql 4.1 and php 4.4
January 20, 2006 06:30PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.