Page 1 of 1

Inserting submitted information.

Posted: Fri Sep 06, 2002 5:06 am
by GrauWolf
I breifly browsed through the forums here and didn't find anything that exactly fitted my question, so.. here I am. THe code below is the second page of a form that inserts the inputted data into the specified table. When I press the Submit button on the first page. This one comes up, but doesn't submit or display anything. As most can see from my code, I'm definitely a newb. Heh. Any help would be greatly appreciated. Thanks.

Code: Select all

<?php

$dbconn = mysql_connect("infowolf", "root", "");
$result = mysql_select_db("products", $dbconn);
if ( $result == false )
{
	echo mysql_error();
	echo "<head><title>There was a problem connecting.</title></head>";
} else {
	echo "<head><title>Connected to ProductIndex on infowolf.no-ip.com</title></head>";
}

if ($submitted) {
	$sql = "INSERT INTO ProductIndex VALUES('$e_date', '$auction_id', '$relist', '$stock_id', '$shelf_id', '$emp_id', '$pname', '$pdesc', '$pnotes', '$c_price', '$taxable', '$weight', '$listed', '$photo', '$datesold', '$highbid', '$sentinvoice', '$datesent', '$buyer')";
	$result = mysql_query( $sql ) or die (mysql_error());
	echo "Thank you. The information you entered is as shown below.\n";

	$sql ="SELECT * FROM ProductIndex WHERE auction_id=$auction_id";
	$result = mysql_query( $sql ) or die (mysql_error());
	$myrow = mysql_fetch_array( $result );
}

?>

<html>
<body bgcolor="#FFFFFF" link="#000080" vlink="#000080" LEFTMARGIN="0" TOPMARGIN="0" MARGINWIDTH="0" MARGINHEIGHT="0" FONT="FF5500">
 
<center><table CELLSPACING=0 CELLPADDING=0 WIDTH="650" >
<tr>
<td WIDTH="650">
<table CELLSPACING=0 CELLPADDING=0 WIDTH="650" HEIGHT="75" >
<tr>
<td VALIGN=TOP WIDTH="650" HEIGHT="75"><img SRC="topbar.gif" height=75 width=650></td>
</tr>
</table>

<table CELLSPACING=0 CELLPADDING=0 WIDTH="650" HEIGHT="22" >
<tr>
<td VALIGN=TOP WIDTH="650" HEIGHT="22" BACKGROUND="menubg.gif">  <b><font color="#000000">Functions:</font>

<font color="#000000"><a href="">Home</a></font>  |  <font color="#000000"><a href="pentry.html">Product
Entry</a></font>  |  <font color="#000000"><a href="">Services</a></font>
|  <font color="#000000"><a href="">Search</a></font>  | 
<font color="#000000"><a href="">Contact
Me</a></font>  |  <font color="#000000"><a href="">Help?</a></font></b></td>
</tr>
</table>

<table CELLSPACING=0 CELLPADDING=0 WIDTH="650" HEIGHT="15" >
<tr>
<td VALIGN=TOP WIDTH="650" HEIGHT="15"><img SRC="bar.gif" height=15 width=650></td>
</tr>
</table>

<table CELLSPACING=0 CELLPADDING=0 WIDTH="650" >
<tr>
<td VALIGN=TOP WIDTH="650" BACKGROUND="mainbg.gif">
<table BORDER=0 WIDTH="648" >
<tr>
<td width=150>  Date Entered:</td>

<td width=498><? echo $myrowї"e_date"] ?></td>
</tr>

<tr>
<td width=150>  Auction ID:</td>

<td width=498><? echo $myrowї"auction_id"] ?></td>
</tr>

<tr>
<td width=150>  Relisted?:</td>

<td width=498><? echo $myrowї"relist"] ?></td>
</tr>

<tr>
<td width=150>  Stock & Shelf ID:</td>

<td width=498><? echo $myrowї"stock_id"] ?>    <? echo $myrowї"shelf_id"] ?></td>
</tr>

<tr>
<td width=150>  Employee ID:</td>

<td width=498><? echo $myrowї"emp_id"] ?></td>
</tr>

<tr>
<td width=150>  Product Name:</td>

<td width=498><TEXTAREA NAME=pname ROWS=2 COLS=40 VALUE="<? echo $myrowї"pname"] ?>"></TEXTAREA></td>
</tr>

<tr>
<td width=150>  Product Description:</td>

<td width=498><TEXTAREA NAME=pdesc ROWS=4 COLS=40 VALUE="<? echo $myrowї"pdesc"] ?>"></TEXTAREA></td>
</tr>

<tr>
<td width=150>  Product Notes:</td>

<td width=498><TEXTAREA NAME=pnotes ROWS=4 COLS=40 VALUE="<? echo $myrowї"pnotes"] ?>"></TEXTAREA></td>
</tr>

<tr>
<td width=150>  Current Price:</td>

<td width=498><? echo $myrowї"c_price"] ?></td>
</tr>

<tr>
<td width=150>  Taxable?:</td>

<td width=498><? echo $myrowї"taxable"] ?></td>
</tr>

<tr>
<td width=150>  Weight(lbs):</td>

<td width=498><? echo $myrowї"weight"] ?></td>
</tr>

<tr>
<td width=150>  Listed?:</td>

<td width=498><? echo $myrowї"listed"] ?></td>
</tr>

<tr>
<td width=150>  Photo:</td>

<td width=498><A HREF="<? echo $myrowї"photo"] ?>"><? echo $myrowї"photo"] ?></td>
</tr>

<tr>
<td width=150>  Date Sold:</td>

<td width=498><? echo $myrowї"datesold"] ?></td>
</tr>

<tr>
<td width=150>  High Bid:</td>

<td width=498><? echo $myrowї"highbid"] ?></td>
</tr>

<tr>
<td width=150>  Sent Invoice?:
<br>  Date Sent:</td>

<td width=498><? echo $myrowї"sentinvoice"] ?>  - if yes,
<br><? echo $myrowї"datesent"] ?></td>
</tr>

<tr>
<td width=150>  Name of Buyer:</td>

<td width=498><? echo $myrowї"buyer"] ?></td>
</tr>

<tr>
<td width=150><P> <P> <P> <P> </td>

<td width=498><P> <P> <P> <P> </td>
</tr>


</table>
</td>
</tr>
</table>

<table CELLSPACING=0 CELLPADDING=0 WIDTH="650" HEIGHT="15" >
<tr>
<td VALIGN=TOP WIDTH="650" HEIGHT="15"><img SRC="bar.gif" height=15 width=650></td>
</tr>
</table>
</td>
</tr>
</table></center>

</body>
</html>

Posted: Fri Sep 06, 2002 5:19 am
by twigletmac

Posted: Fri Sep 06, 2002 7:21 am
by GrauWolf
No I hadn't seen that, but I read it thank you. Should my code end up looking like this, then?...

Code: Select all

$sql = "INSERT INTO ProductIndex VALUES('$_POSTї'e_date']', '$_POSTї'auction_id']', '$_POSTї'relist']', '$_POSTї'stock_id']', ......)";

Posted: Fri Sep 06, 2002 7:58 am
by twigletmac
You'd have to do:

Code: Select all

$sql = "INSERT INTO ProductIndex VALUES('{$_POSTї'e_date']}', '{$_POSTї'auction_id']}', '{$_POSTї'relist']}', '{$_POSTї'stock_id']}', ......)";
or

Code: Select all

$sql = "INSERT INTO ProductIndex VALUES('".$_POSTї'e_date']."', '".$_POSTї'auction_id']."', '".$_POSTї'relist']."', '".$_POSTї'stock_id']."', ......)";
The

Code: Select all

if ($submitted) {
line will have to be changed too. One solution is to have a hidden field in your form which could, for example, have a name of action and a value of submit. Then you can do:

Code: Select all

if (isset($_POSTї'action']) && $_POSTї'action'] == 'submit') {
It is also not neccessary to query the database to then display this information on the page.

You can change this:

Code: Select all

$sql ="SELECT * FROM ProductIndex WHERE auction_id=$auction_id"; 
   $result = mysql_query( $sql ) or die (mysql_error()); 
   $myrow = mysql_fetch_array( $result );
to something like this:

Code: Select all

foreach ($_POST as $key => $value) {
    $$key = htmlspecialchars(stripslashes($value));
}
then you can access the variables as you were originally.

Mac