Jump to content

php form database


kiki

Recommended Posts

hello im kind of new at this kind of php but i need to help set up a database for this form i made.

 

so anyways i made a regular php form and had it send all the information to an email. but my question is that is there a way for it to send the information submitted on the form to a database as well so you can go check on the database. but not have to type in the information yourself into the database but have the information from the form automatically be submitted to a database?

 

how would you do this? is there a tutorial somewhere that can help?

 

thanks,

Link to comment
Share on other sites

<?php
if (!isset($_POST["submit"])) {
?>
<form action="<? echo($_SERVER['PHP_SELF']); ?>" method="POST">
  <input type="text" name="information" value="information" />
  <input type="submit" name="submit" value="Submit" />
</form>
<?php
}
else {
  $_handle=mysql_connect("host","username","password");
  $_db=mysql_select_db("database",$_handle);
  mysql_query("INSTERT INTO tablename (information) VALUES ('".$_POST["text"]."')");
  mysql_close($_handle);
}
?>

 

A very very very basic way to do it. You need to edit the things for it to work.

Link to comment
Share on other sites

<?php
$name = trim($_POST['name']);
$contact = trim($_POST['contact']);
$address = trim($_POST['address']);
$city = trim($_POST['city']);
$state = trim($_POST['state']);
$zip = trim($_POST['zip']);
$telephone = trim($_POST['telephone']);
$fax = trim($_POST['fax']);
$email = trim($_POST['email']);
$donated = trim($_POST['donated']);
$expiration = trim($_POST['expiration']);
$comments = trim($_POST['comments']);

echo "Procurement";




echo" <br />";
echo" <br />";
echo" <br />";
echo "Name: ". $name . " <br />";
echo "contact: ". $contact . " <br />";
echo "address: ". $address . " <br />";
echo "city: ". $city . " <br />";
echo "state: ". $state . " <br />";
echo "zip: ". $zip . " <br />";
echo "telephone: ". $telephone . " <br />";
echo "$fax: ". $fax . " <br />";
echo "email: ". $email . " <br />";
echo "donated: ". $donated . " <br />";
echo "expiration: ". $expiration . " <br />";
echo "comments: ". $comments . " <br />";


$recipient = "helpline@yahoo.com";
$subject   = "Procurement";
$message   = " 


$name

$contact

$address 

$city

$state

$zip 

$telephone 

$fax

$email

$donated 

$expiration 

$comments


";

mail($recipient, $subject, $message);
?>

 

say if that is my simple php. i just add the

 

else {
  $_handle=mysql_connect("host","username","password");
  $_db=mysql_select_db("database",$_handle);
  mysql_query("INSTERT INTO tablename (information) VALUES ('".$_POST["text"]."')");
  mysql_close($_handle);
}
?>

 

i just add that code? and i have to make a mysql database with all the items i have listed right? but after im done how and i suppose to go look back at the database to check on something? like is there a page i can go to where there is a list of all the submitted things and i can just scroll/search and look for past submissions? or is that not what i need to do with mysql?

Link to comment
Share on other sites

<?php
if (!isset($_POST["submit"])) {
?>
<form action="<? echo($_SERVER['PHP_SELF']); ?>" method="POST">
  <input type="text" name="information" value="information" />
  <input type="submit" name="submit" value="Submit" />
</form>
<?php
}
else {
  $_handle=mysql_connect("host","username","password");
  $_db=mysql_select_db("database",$_handle);
  mysql_query("INSTERT INTO tablename (information) VALUES ('".$_POST["text"]."')");
  mysql_close($_handle);
}
?>

 

A very very very basic way to do it. You need to edit the things for it to work.

 

Why are you assigning $_db to the return value of mysql_select_db()?  It just returns a BOOL, not a resource or anything.  You can skip that variable assignment.

Link to comment
Share on other sites

im sorry but i tried the things you guys suggested but it doesnt seem to work? im not sure if im putting the things in the right area. maybe i should just post everything?

 

so here is my form:

 

<form action="thankyou_procurement.php" method="post"> 
<table width="95%" border="0" cellspacing="1" class="tablestyle" cellpadding="1" align="center">

<tr><td>Donor Name:<BR>
(Firm/Individual)</td>
<td><input type="text" name="name" size="27">
</td>
</tr>

<tr><td>Contact Person:<BR>
(If different than above)</td>
<td><input type="text" name="contact" size="27">
</td>
</tr>

<tr> 
<td>Address: </td>
<td> 
<input type="text" name="address" size="27">
</td>
</tr>

<tr> 
<td>City: </td>
<td> 
<input type="text" name="city" size="27">
</td>
</tr>

<tr> 
<td>State: </td>
<td> 
<input type="text" name="state" size="27">
</td>
</tr>

<tr> 
<td>Zip: </td>
<td> 
<input type="text" name="zip" size="27">
</td>
</tr>

<tr> 
<td>Telephone: </td>
<td> 
<input type="text" name="phone" size="27">
</td>
</tr>

<tr> 
<td>Fax: </td>
<td> 
<input type="text" name="fax" size="27">
</td>
</tr>

<tr> 
<td>E-mail: </td>
<td> 
<input type="text" name="email" size="27">
</td>
</tr>

<tr> 
<td>Donated item: </td>
<td> 
<input type="text" name="donated" size="27">
</td>
</tr>

<tr> 
<td>Expiration Date: </td>
<td> 
<input type="text" name="expiration" size="27">
</td>
</tr>

<tr>
<td>Detailed Description:<BR>
(Include size, color, brand, model number, any restrictions, ect.) </td>
<td>
<textarea name="comments" cols=20 rows="3"></textarea>
</td>
</tr>

<tr><td colspan="2"><input type="submit" value="Submit" class="button"></td></tr>
</table></form> 

 

here is my external commands:

 

<?php
$name = trim($_POST['name']);
$contact = trim($_POST['contact']);
$address = trim($_POST['address']);
$city = trim($_POST['city']);
$state = trim($_POST['state']);
$zip = trim($_POST['zip']);
$telephone = trim($_POST['telephone']);
$fax = trim($_POST['fax']);
$email = trim($_POST['email']);
$donated = trim($_POST['donated']);
$expiration = trim($_POST['expiration']);
$comments = trim($_POST['comments']);


$recipient = "auctions@yahoo.com";
$subject   = "Procurement";
$message   = " 


$name

$contact

$address 

$city

$state

$zip 

$telephone 

$fax

$email

$donated 

$expiration 

$comments


";

mail($recipient, $subject, $message);
?>

 

now i already made a mysql database and made table for all the values from my form. im not sure where to put the things you guys suggested? can someone show me exactly where i need to put them please? sorry but im trying to make a database for some helpline and its not really in my range in knowledge but it needs to be done... :(

 

they want me to make the form that sends info to their email which i did. but they want to be able to check back on the database incase their customers call back so they can go check. im doing the right thing right? you would use mysql and php for this am i correct? and how would they be able to access the database to check after i code all this?

 

thx

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.