Forums
This topic is locked
php updateing mysql without forms?
Posted 01 Oct 2004 01:51:10
1
has voted
01 Oct 2004 01:51:10 bill howard posted:
is it possible to have a script update a value stored in a mysql db without using formsthe script is listed below, basically it is a if statement that checks the value of a field and updates it if required i can get this to work using a form and some hidden fields but that seems very awkward, i have indicated below what tyoe of command i would like to be issuing
..........
<?php require_once('../Connections/vemicsConn.php'); ?>
<?php
$colname_userconn = "1";
if (isset($HTTP_COOKIE_VARS['user_name'])) {
$colname_userconn = (get_magic_quotes_gpc()) ? $HTTP_COOKIE_VARS['user_name'] : addslashes($HTTP_COOKIE_VARS['user_name']);
}
mysql_select_db($database_vemicsConn, $vemicsConn);
$query_userconn = sprintf("SELECT * FROM login_info WHERE user_name = '%s'", $colname_userconn);
$userconn = mysql_query($query_userconn, $vemicsConn) or die(mysql_error());
$row_userconn = mysql_fetch_assoc($userconn);
$totalRows_userconn = mysql_num_rows($userconn);
?>
<?php
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = ""
{
$theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;
switch ($theType) {
case "text":
$theValue = ($theValue != "" ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "" ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "" ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "" ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "" ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}?>
<?php
// countdown function
// parameters: (year, month, day, hour, minute)
//--------------------------
// Note:
// Unix timestamp limitations
// Date range is from
// the year 1970 to 2038
//--------------------------
function countdown($year, $month, $day, $hour, $minute)
{
// make a unix timestamp for the given date
$the_countdown_date = mktime($hour, $minute, 0, $month, $day, $year, -1);
// get current unix timestamp
$today = time();
$difference = $the_countdown_date - $today;
if ($difference < 0) $difference = 0;
$days_left = floor($difference/60/60/24);
$hours_left = floor(($difference - $days_left*60*60*24)/60/60);
$minutes_left = floor(($difference - $days_left*60*60*24 - $hours_left*60*60)/60);
// OUTPUT
//g:i ag:i a.$hours_left." hours ".$minutes_left." minutes left"
echo "<p align='center' class='regtext'>Today's date ".date("F j, Y"."<br/>";
echo "<p align='center' class='regtext'>Expiration date ".date("F j, Y",$the_countdown_date)."</p><br/>";
echo "<p align='center' class='regtext'>Countdown ".$days_left." days remain.";
}
?>
<?php function parse_str_ext($toparse) {
$returnarray = array();
$keyvaluepairs = split("&", $toparse);
foreach($keyvaluepairs as $pairval) {
$splitpair = split("=", $pairval);
if(!array_key_exists($splitpair[0], $returnarray)) $returnarray[$splitpair[0]] = array();
$returnarray[$splitpair[0]][] = $splitpair[1];
}
return $returnarray;
}?>
<?php function set_the_end_date() {
if($row_userconn['course_end_date'] == "0000-00-00 00:00:00"{
echo date("l dS of F Y h:i:s A"
//echo "wtf";
//set the end date
}}?>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="sitestyle.css" rel="stylesheet" type="text/css">
</head>
<body>
<p align="center" class="regtext">course splash page</p>
<p align="center" class="regtext">welcome <?php echo $row_userconn['first_name']; ?> <?php echo $row_userconn['last_name']; ?> </p>
<?php
// if then to determine if user has set a start daye
if($row_userconn['course_start_date'] == "0000-00-00 00:00:00"{
//has not started course yet
echo "<p align='center' class='regtext'>this is your first visit your time will start once you click the link below</p>";
//set_the_end_date();
} else {
// display current countdown
echo "<p align='center' class='regtext'>you've started the course:</p>";
$mystr=$row_userconn['course_end_date'];
$myarray = explode(" ", $mystr);
$mydate = $myarray[0];
$mytime = $myarray[1];
$mydate = explode("-", $mydate);
$mytime = explode(":", $mytime);
$year = $mydate[0];
$month= $mydate[1];
$day= $mydate[2];
$hour= $mytime[0];
$minute= $mytime[1];
//sendfunction
countdown($year, $month, $day, $hour, $minute);
}
if($row_userconn['course_end_date'] == "0000-00-00 00:00:00"{
//stuff to set
//echo date(n);
$month = date(n) + 1;
if($month > 12){
$month = 1;
}}
//add digit if necc
if($month < 10){
$month = "0".$month;
}
$year = date(Y);
$day= date(d);
$hour= date(h);
$minute= date(i);
//create the end date
//still need to do some advanced day checking to assure month has the day ie 31 etc
$thefinal = $year."-".$month."-".$day." ".$hour.":".$minute.":00";
echo $thefinal;
// i would like to store this info put it in the db
i would think it would be somthing like $query = "UPDATE login_info SET course_end_date = '$thefinal' WHERE id = '$ud_id'";
?>
<p align="center"><a href=<?php echo $row_userconn['current_course'] ?> target="_self" class="regtext">click
here</a></p>
<p align="center"> </p>
<p align="center"> </p>
</body>
</html>
<?php
mysql_free_result($userconn);
?>