Hi there,
I'm building a DB-driven site, and i have one page (settings.php) that
is included on each viewable page. In settings.php i have a few
functions, so i do not have to type them all, or modify them all if
anything changes..
For the same reason i want to create a function to connect to a mySQL
DB.
What i have is:
############### ############### ############### ##
function doConnect(){
$db = mysql_connect(" host", "user", "pass");
mysql_select_db ("data",$db) ;
};
function doDisConnect(){
mysql_close($db );
};
############### ############### ############### ##
And then i want to run them from a page where settings.php is
included:
_______________ _______________ _______________ __
doConnect();
$get_user = mysql_query("SE LECT id, customerID, hits FROM
customerID WHERE customerID='$us er'",$db);
if ($data = mysql_fetch_arr ay($get_user)) {
$sql = "UPDATE customerID SET hits = hits + 1 WHERE
customerID ='$user'";
}else{
$sql = "INSERT INTO customerID (customerID, hits) VALUES
('$user', 1)";
};
$addhit = mysql_query($sq l);
doDisConnect();
_______________ _______________ _______________ __
this function is a counter, but that isn't really important. Why can't
i get this to work? Or should i do it totally different?
I'd like to find out now, before i have used it in a lot of pages...
Thanks in advance. Greetings knoakske
I'm building a DB-driven site, and i have one page (settings.php) that
is included on each viewable page. In settings.php i have a few
functions, so i do not have to type them all, or modify them all if
anything changes..
For the same reason i want to create a function to connect to a mySQL
DB.
What i have is:
############### ############### ############### ##
function doConnect(){
$db = mysql_connect(" host", "user", "pass");
mysql_select_db ("data",$db) ;
};
function doDisConnect(){
mysql_close($db );
};
############### ############### ############### ##
And then i want to run them from a page where settings.php is
included:
_______________ _______________ _______________ __
doConnect();
$get_user = mysql_query("SE LECT id, customerID, hits FROM
customerID WHERE customerID='$us er'",$db);
if ($data = mysql_fetch_arr ay($get_user)) {
$sql = "UPDATE customerID SET hits = hits + 1 WHERE
customerID ='$user'";
}else{
$sql = "INSERT INTO customerID (customerID, hits) VALUES
('$user', 1)";
};
$addhit = mysql_query($sq l);
doDisConnect();
_______________ _______________ _______________ __
this function is a counter, but that isn't really important. Why can't
i get this to work? Or should i do it totally different?
I'd like to find out now, before i have used it in a lot of pages...
Thanks in advance. Greetings knoakske
Comment