0

Im my form to send emails I have a button called "Save".When I click the button I want to send the email as well as insert data into my database(values of sender,receiver).I can send th email but i dont know how to insert the data into the database at the sametime.Can anyone help?

2
Contributors
9
Replies
10
Views
7 Years
Discussion Span
Last Post by kireol
0

Im my form to send emails I have a button called "Save".When I click the button I want to send the email as well as insert data into my database(values of sender,receiver).I can send th email but i dont know how to insert the data into the database at the sametime.Can anyone help?

depending on which database you use, you would do a simple sql insert.

the example below is for MySQL

<?php
$con = mysql_connect("localhost","database username","database password");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("my_db", $con);

mysql_query("INSERT INTO Persons (FirstName, LastName, Age)
VALUES ('Peter', 'Griffin', '35')");

mysql_query("INSERT INTO Persons (FirstName, LastName, Age)
VALUES ('Glenn', 'Quagmire', '33')");

mysql_close($con);
?>
0

No Iwant to execute the code which inserts data into the database when I click the "Send" button.How can I do it?

0

No Iwant to execute the code which inserts data into the database when I click the "Send" button.How can I do it?

You will need to be clearer on what you are doing, because I answered a valid response based off of your question.

When you click the send button, the usual way is you call another script via get or post. alternatively you can call an ajax so the page doesnt "reload". Since you didn't state which you are doing, I'll assume the first case.

If that's the case, where you are doing your emailing, you would do a sql insert just like what I already posted, but with your data

0

This is where my emailing is done.
<Form enctype="multipart/form-data"
action="http://abc.net/sendmail.php
method="post" name="frm1"
onsubmit="javascript:return myValidate();" >
.
.(some code)
.
<input type="submit" name="Submit" value="Send" />
Can you tell me where should I execute my insert code into database

0

This is where my emailing is done.
<Form enctype="multipart/form-data"
action="http://abc.net/sendmail.php
method="post" name="frm1"
onsubmit="javascript:return myValidate();" >
.
.(some code)
.
<input type="submit" name="Submit" value="Send" />
Can you tell me where should I execute my insert code into database

Like i said, you need to insert the code in my first response.

It would go in sendmail.php

0

Is there a way to insert data into the database when the "Send" button is clicked?If so can you tell me how?Please show me the place where I have to put the INSERT INTO statement

0

Is there a way to insert data into the database when the "Send" button is clicked?If so can you tell me how?Please show me the place where I have to put the INSERT INTO statement

Like I said, the code (which I previously posted) goes in sendmail.php (like I previously posted).

0

But my sendmail.php is hosted in the web therefore i think i cant insert data to my database from there.Any idea how to do this?

0

I'd be surprised to hear that you have access to the HTML but not the PHP.

but if that's the case, your only option would be to make an ajax call to another php script that does the insert, then let the rest work like it already does.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.