Jump to content

Recommended Posts

How do I get an insert form to update the date everytime someone submits a new entry. I realize this is probably incredbly simple...here's my 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;
}

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
 $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
 $insertSQL = sprintf("INSERT INTO Lyrics (ID, `DATE`, BAND, QUOTE, SUBMITTED_BY, EMAIL) VALUES (%s, %s, %s, %s, %s, %s)",
                      GetSQLValueString($_POST['ID'], "int"),
                      GetSQLValueString($_POST['DATE'], "date"),
                      GetSQLValueString($_POST['BAND'], "text"),
                      GetSQLValueString($_POST['QUOTE'], "text"),
                      GetSQLValueString($_POST['SUBMITTED_BY'], "text"),
                      GetSQLValueString($_POST['EMAIL'], "text"));

 mysql_select_db($database_lyricalquotes, $lyricalquotes);
 $Result1 = mysql_query($insertSQL, $lyricalquotes) or die(mysql_error());

 $insertGoTo = "lyrics.php";
 if (isset($_SERVER['QUERY_STRING'])) {
   $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
   $insertGoTo .= $_SERVER['QUERY_STRING'];
 }
 header(sprintf("Location: %s", $insertGoTo));
}

mysql_select_db($database_lyricalquotes, $lyricalquotes);
$query_submitlyrics = "SELECT * FROM Lyrics ORDER BY ID DESC";
$submitlyrics = mysql_query($query_submitlyrics, $lyricalquotes) or die(mysql_error());
$row_submitlyrics = mysql_fetch_assoc($submitlyrics);
$totalRows_submitlyrics = mysql_num_rows($submitlyrics);

 

and then my form:

 

<form method="post" name="form1" action="<?php echo $editFormAction; ?>">
       <table align="center">
         <tr valign="baseline">
           <td nowrap align="right">Band:</td>
           <td><input type="text" name="BAND" value="" size="32"></td>
         </tr>
         <tr valign="baseline">
           <td nowrap align="right" valign="top">Quote:</td>
           <td>
             <textarea name="QUOTE" cols="50" rows="5"></textarea>
           </td>
         </tr>
         <tr valign="baseline">
           <td nowrap align="right">Submitted By:</td>
           <td><input type="text" name="SUBMITTED_BY" value="" size="32"></td>
         </tr>
         <tr valign="baseline">
           <td nowrap align="right">Email:</td>
           <td><input type="text" name="EMAIL" value="" size="32"></td>
         </tr>
         <tr valign="baseline">
           <td nowrap align="right"> </td>
           <td><input type="submit" value="Insert record"></td>
         </tr>
       </table>
       <input type="hidden" name="ID" value="">
       <input name="DATE" type="hidden" value="">
       <input type="hidden" name="MM_insert" value="form1">
     </form>

 

Any help would be greatly appreciated!!!

 

Thanks in advance,

Shaun McKinnon

(to check out what it's doing currently, go to Lyrical Quotes )

Link to comment
https://forums.phpfreaks.com/topic/1619-date-function/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.