I have spent many days on this problem but I couldn't fix it, and am looking for help. Lets say I have this php-sql:
$sql2= mysql_query("SELECT * FROM jos_comprofiler WHERE id = ".$userid."");
$row2 = mysql_fetch_array($sql2) ;
$bdate= $row2['cb_birthday']; // 2012-03-01 year/month/day
and this function:
function _weeks($date) {
global $bdate ;
$month = substr($date, 0, 2) ;
$day = substr($date, 3, 2);
$year = substr($date, 6, 4) ;
$bmonth = substr($bdate, 5, 2) ;
$bday = substr($bdate, 8, 2);
$byear = substr($bdate, 0, 4) ;
$birthday = gmmktime(0, 0, 0, $bmonth, $bday, $byear);
$eventdate = gmmktime(0, 0, 0, $month, $day, $year);
$weeknumber = (int)(($eventdate - $birthday) / (7 * 24 * 60 * 60)) + 1 ;
return $weeknumber ;
}
and i have 10 submit buttoms to submit dates
if (isset($_POST['submit0'])){
if ($userid !=0 ){
$date0 = $_POST['date0'];
$func_date= _weeks($date0);
mysql_query(" UPDATE data SET w_dd = '".$func_date."' WHERE id_user= '".$userid."' ");
$sql= mysql_query("SELECT id_user FROM data WHERE id_user='".$userid."' ");
$result= mysql_num_rows($sql);
mysql_query(" UPDATE data SET dd = '".$date0."' WHERE id_user= '".$userid."' ");
}
if (isset($_POST['submit1'])){
if ($userid !=0 ){
$date1 = $_POST['date1'];
$func_date= _weeks($date1);
mysql_query(" UPDATE data SET w_dd = '".$func_date."' WHERE id_user= '".$userid."' ");
$sql= mysql_query("SELECT id_user FROM data WHERE id_user='".$userid."' ");
$result= mysql_num_rows($sql);
mysql_query(" UPDATE data SET dd = '".$date1."' WHERE id_user= '".$userid."' ");
}
...and so on till submit9 button.
The problem is $bdate in the function , it doesn't work $bdate like that, but if I try to make a specific date like below, it works like a charm the $func_date.
function _weeks($date){
$bdate = "2012-03-01";
I even put the $bdate inside function but that didn't work either.
How can I make this work? Thanks!
$bdateto the function as an argument as well.globalis evil in almost all cases.