/    Sign up×
Community /Pin to ProfileBookmark

inserting form inputs into my table

hi everybody,

hope all of u r doing fine..

well, i don’t know what’s the problem in my code! i just followed every step in inserting information from user that shown in most books that teaches PHP .. maybe the problem because of my PHP version (which is 4.0) ..
pla if anyone noticed that there’s mistakes (either syntax or semantics) in the following code, Please let me know..

First Page:

[code=php]

<form method = “post” onsubmit=”return validForm(this)” action = “dedo3.php” >

<tr>
<td> </td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td> <h3> Order Form </h3> </td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td align = “left” valign = “top”> To <font style = “color:red; size:9pt:”> * </font> :</td>
<td> <input type = “text” name = “to” size = “30”/> </td>
</tr>
<tr>
<td align = “left” valign = “top”> From <font style = “color:red”> * </font> : </td>
<td> <input type = “text” name = “from” size = “30”/> </td>
</tr>
<tr>
<td align = “left” valign = “top”> Customer Name <font style = “color:red”> * </font> : </td>
<td> <input type = “text” name = “customer” size = “30”/> </td>
</tr>
<tr>
<td align = “left” valign = “top”> Address: </td>
<td> <textarea name = “address” cols=”30″ rows=”5″/> </textarea> </td>
</tr>
<tr>
<td align = “left” valign = “top”> Phone <font style = “color:red”> * </font> :</td>
<td> <input type = “text” name = “phone” size = “20”/> </td>
</tr>
<tr>
<td align = “left” valign = “top”> Fax: </td>
<td> <input type = “text” name = “fax” size = “20”/> </td
</tr>
<tr>
<td align = “left” valign = “top”> Contact: </td>
<td> <input type = “text” name = “contact” size = “30”/> </td>
</tr>
<tr>
<td align = “left” valign = “top”> Ship To <font style = “color:red”> * </font> :</td>
<td> <textarea name = “ship” cols=”30″ rows=”5″/> </textarea> </td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td colspan = “2”> <hr width=”95%” size=”1″>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td align = “left” valign = “top”> Product ID <font style = “color:red”> * </font> :</td>

<!– ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ PHP Select ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ –>

<td>
<select name=”id” cols=”50″ selected = “Select an ID” >
<option value=”Select an ID”> Select an ID </option>
<?php
$link = @mysql_connect(“localhost”, “”, “”);
@mysql_select_db(“plastic”, $link);
$result = mysql_query(“SELECT * FROM products”);
$select = “”;
while( $arow = mysql_fetch_object( $result ) )
{
$select .= “<option value= “$arow->p_id ” > $arow->p_id </option>n”;
}
print $select;
mysql_close($link);
?>
</select>

</td>
</tr>
<tr>
<td align = “left” valign = “top”> Quantity: </td>
<td> <input type = “text” name = “quantity” size = “12”/> </td>
</tr>
<tr>
<td align = “left” valign = “top”> Other Instructions: </td>
<td> <textarea name = “instruction” cols=”30″ rows=”5″/> </textarea> </td>
</tr>
<tr>
<td colspan = “2”> <hr width=”95%” size=”1″>
</tr>
<tr>
<td colspan = “2” align = “right”> <input type = “submit” value = “Send Order” /> </td>
</tr>

</form>

[/code]

that calls the following one:

[code=php]

<html>

<head>
</head>

<body>

<?php

extract($_POST);
/* $to = $_REQUEST[‘to’]; */
/* $from = $_REQUEST[‘from’]; */
/* $customer = $_REQUEST[‘customer’]; */
/* $address = $_REQUEST[‘address’]; */
/* $phone = $_REQUEST[‘phone’]; */
/* $fax = $_REQUEST[‘fax’]; */
/* $contact = $_REQUEST[‘contact’]; */
/* $ship = $_REQUEST[‘ship’]; */
/* $p_id = $_REQUEST[‘p_id’]; */
/* $quantity = $_REQUEST[‘quantity’]; */
/* $instruction = $_REQUEST[‘instruction’]; */

$link = @mysql_connect(“localhost”, “”, “”);
@mysql_select_db(“plastic”);
$query = “INSERT INTO `pl` (`prid`, `to`, `from`, `customer`, `address`, `phone`, `fax`, `contact`, `ship`, `p_id`, `quantity`, `instruction`) VALUES(‘$to’, ‘$from’, ‘$customer’, ‘$address’, ‘$phone’, ‘$fax’, ‘$contact’, ‘$ship’, ‘$p_id’, ‘$quantity’, ‘$instruction’)”;

if ( ! mysql_query( $query ) )
{
print “Sorry! we couldn’t send your order.n Please try Later” ;
}
else
print “Your order has been sent.nthank you for using our service. We hope you enjoy it”;

mysql_close($link);

?>

</body>

</html>

[/code]

reGards,
dello

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@delloauthorMay 21.2004 — parden me, i haven't checked it again...

thank u shrine, much appreciated

i have a question, how does the form know it should be taken by php code written previously without typing anything into its action ?
Copy linkTweet thisAlerts:
@ShrineDesignsMay 22.2004 — you can test the $_POST to see if it exists:&lt;?php
if($_POST)
{
//parse the post data
}
else
{
//display a form or error message
}
?&gt;
×

Success!

Help @dello spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...