Jump to content

formmail and mysql help


alohatofu

Recommended Posts

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

Link to comment
Share on other sites

<?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)
?>

Link to comment
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.