Re: Posting Form Data to a Database??
| From: | Brian | Date: | Tue, 06 Aug 2002 18:14:59 +0000 |
| Subject: | Re: Posting Form Data to a Database?? | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-21017@lists.php.net to get a copy of this message | ||
After some fooling around I created my own:
<HTML>
<HEAD><TITLE>Ads</TITLE>
</HEAD>
<BODY>
<?php
if ($submit)
{
//please change the server name username and password according to your
mssql server setting
$mssql_server="sqlservername";
$mssql_username="sa";
$mssql_password="test";
$mssql_database="test";
//connect to database using above settings
@MSSQL_CONNECT($mssql_server,$mssql_username,$mssql_password);
@MSsql_select_db("test");
$ads_id=time();
$result=MSSQL_QUERY("INSERT INTO ads (id,FirstName,LastName,Office) ".
" VALUES
('$ads_id','$FirstName','$LastName','$Office')");
if ($result == TRUE)
{
print "We have received your Questionaire successfully. Thank you";
print "<p>Database ID: <b>$ads_id</b>";
}
else
{
print "<h1>DATABASE ERROR</h1><p>Your submission was not successfully
submitted to the database. <br>Please notify the webmaster by email of this
error.";
}
MSSQL_CLOSE();
}
else
{
// else show the form to submit new data:
?>
<table width="100%" border="0" cellspacing="0"
cellpadding="0">
<tr>
<td>Questionaire</td>
</tr>
</table>
<table width="100%" border="0" cellspacing="0"
cellpadding="0">
<tr>
<td>
<form method="post" action="<?php echo $PHP_SELF; ?>"
enctype="multipart/form-data" name="s">
<table width="100%" border="0" cellspacing="1"
cellpadding="1">
<tr>
<td>First Name:</td>
<td>
<input type="text" name="FirstName" size="40">
<!-- this is to check is not over sized -->
</td>
</tr>
<tr>
<td>Last Name:</td>
<td>
<input type="text" name="LastName" size="40">
</td>
</tr>
<tr>
<td>Office: </td>
<td>
<input type="text" name="Office" size="5">
</td>
</tr>
<tr>
<td> </td>
<td>
<input type="submit" name="submit" value="submit">
</td>
</tr>
</table>
</form>
</td>
</tr>
</table>
<?php
}
?>
</BODY>
</HTML>
Now my next task is to add some functionality to auto email the webmaster
about the error with the data that was suppose to be inserted into the
database
"Brian" <brian@nextmill.net> wrote in message
news:20020806161425.27032.qmail@pb1.pair.com...
> Anyone have some sort of basic PHP script they might have written to help
me
> get a basic html form data posted as a new record into an sql database? I
> am looking for something that might do the following:
>
> Variables at top of script
> SQL server:
> Database :
> sql username :
> sql password :
> Table :
>
> And then it interprets whatever fields are submitted by an html form and
> drops those fields into as a new entry into that table, so if that table
has
> say 4 fields, Name, Address, Phone, Email, then the form created by anyone
> would need to have the exact same field names to match correctly, and when
> they do, your ASP page would interpret the 4 fields and insert them as a
new
> record!
>
> I think it would be very simple, and then it would be adaptable to any
> situation since if I get a new table with 10 fields, as long as I make an
> html page with those exact field names and modify the asp engine page to
> have the new table name as a variable, then it should post correctly.
>
>
>