alohatofu Posted April 4, 2008 Share Posted April 4, 2008 Hello, I have a formmail to send a message to a user called "form.php" within that form.php, I also have a SQL insert statement to insert into my database with the value $_POST[message] my objective is when a user go to form.php and fill out the form, it will send the form to me and also insert the message into a field in my database. everything seems to be working fine but my problem is when a user go to form.php, it automatically execute my INSERT INTO command right away. (user has not fill out the message yet) $sql="INSERT INTO surv_itemcomment (itemId, memberId, postDate, body) VALUES ('$itemId','$memberId','$date','$_POST[message]')"; how can I accomplish this? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/99551-formmail-and-mysql-help/ Share on other sites More sharing options...
dennismonsewicz Posted April 4, 2008 Share Posted April 4, 2008 can you supply for of your code? Quote Link to comment https://forums.phpfreaks.com/topic/99551-formmail-and-mysql-help/#findComment-509270 Share on other sites More sharing options...
alohatofu Posted April 4, 2008 Author Share Posted April 4, 2008 <?php $eric = $_REQUEST['eric']; //eric number $users = $_REQUEST['cuoos']; //number of customers out of service $mailsubj = $_REQUEST['clli']; //clli code $emailfrom = $_REQUEST['email']; //email address of user $pagesender = $_REQUEST['pagesender']; //email address of sender $statusDate = $_REQUEST['statusDate']; //creation date of event $now = time(); //time now in seconds $timestart = strtotime($statusDate); //convert start time to seconds $secsago = $now - $timestart; //in seconds $hoursago = (($secsago/60)/60); //result in hours with decimals echo $timestart; ?> <div align="left"> <tr> <td align="left" valign="top"> <p> </p><br><br><br><br> <form method="POST" action="http://webapps/mailer/submitform" name="mail_form"> <input type="hidden" name="mailto" value="myoh@dayiz.com"> <input type="hidden" name="order" value="out,users,message"> <input type="hidden" name="doublespace" value="no"> <input type="hidden" name="emailfrom" size="30" value="<?php echo $pagesender; ?>"> <input type="hidden" name="mailcc" value="<?php echo $emailfrom; ?>;<?php echo $pagesender; ?>" <input type="hidden" value="OUTAGE <?php echo $mailsubj; ?> - ERIC <?php echo $eric; ?>" name="mailsubj" name="mailsubj" size="20"><br> <input type="hidden" value="<?php echo $users; ?>" name="users" size="4"> <textarea name="message" wrap=physical cols=23 rows=4></textarea> <script> displaylimit("document.mail_form.message","",80) </script> <br> <input type="submit" value="Send" onclick="javascript:document.forms[0].mailcc.value=document.forms[0].emailfrom.value"> <input type="reset" value="Clear"> <input type="hidden" name="redirecturl" value="sendpageconfirm.php"> </form> </td> </tr> </table> </div> // INSERT TO DATABASE SECTION <?php $itemId = $_REQUEST['itemid']; // ITEM ID $memberId = $_REQUEST['userid']; // User ID $body = $_POST['message']; // GET MESSAGE $date = date("Y-m-d G:i:s", strtotime("now + 5 hours")); // DATE TIME $con = mysql_connect("localhost","user","password"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("testtask", $con); $sql="INSERT INTO surv_itemcomment (itemId, memberId, postDate, body) VALUES ('$itemId','$memberId','$date','$_POST[message]')"; { if (!mysql_query($sql,$con)) die('Error: ' . mysql_error()); } echo ""; mysql_close($con) ?> Quote Link to comment https://forums.phpfreaks.com/topic/99551-formmail-and-mysql-help/#findComment-509273 Share on other sites More sharing options...
dennismonsewicz Posted April 4, 2008 Share Posted April 4, 2008 Well first I wouldn't use $_REQUEST cause it contains post, get, and cookie data. Quote Link to comment https://forums.phpfreaks.com/topic/99551-formmail-and-mysql-help/#findComment-509290 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.