Hi, This following is the preview page of my page and I want to insert the data from this page to MySQL. How can that be done? I mean what would be the syntax to insert data into MySQL table ? I know no PHP and the below code is also made with the help of Internet so please be a bit more detailed. <style type="text/css"> <!-- .K { font-size: 14px; font-weight: normal; font-family: Tahoma, Geneva, sans-serif; } .bar { font:"Free 3 of 9 Extended"; font-size:14px; } .K2 { font-size: 14px; font-family: tahoma, Geneva, sans-serif; } .ff { font-family: "Courier New", Courier, monospace; } --> </style> <table align="left"> <tr> <td> <table width="97%" align="center" background="ss.jpg"> <tr> <td> </td> <td class="ff">CONTENTS: <span class="K2"><?php echo " :" .$_POST["item"]. " "; ?></span></td> </tr> </table> <table> <tr> <td> </td> </tr> </table> <table width="800" align="center"> <tr> <td class="K"><strong><U>SEND TO :</U></strong></td> <td class="K2"> </td> <td class="K" align="right"><strong>FROM :</strong></td> <td class="K2"> </td> </tr> <tr> <td width="12%" height="131" class="K"> </td> <td align="justify" width="34%" class="K2"><table width="250"> <tr> <td class="K2" style="text-transform:uppercase"><strong> <?php echo nl2br(" " .$_POST["to"]. " "); ?></strong></td> </tr> </table> </td> <td width="14%" class="K" align="center"><p>::</p> <p>::</p> <p>::</p> <p>::</p></td> <td align="justify" width="40%" class="K2"> </td> </tr> <tr> <td height="16" class="K">------------------</td> <td class="K2">--------------------------------------------------</td> <td class="K">---------------------</td> <td class="K">--------------------------------------------------------</td> </tr> </table> <table width="72%" align="center"> <tr> <td align="center"><span style="font:Verdana, Geneva, sans-serif; font-size: 10px;"> :: Package Information :: </span></td> </tr> </table> <table width="72%" align="center" > <tr align="left"> <td width="11%" style="font:Verdana, Geneva, sans-serif; font-size: 10px;" height="20">*Content:</td> <td width="28%" class="K2"><?php echo " " .$_POST["cat"]. " "; ?></td> <td width="8%" style="font:Verdana, Geneva, sans-serif; font-size: 10px;">*Weight:</td> <td width="31%" style="font:Verdana, Geneva, sans-serif; font-size: 10px;" class="K2"><?php echo " ".$_POST["wgt"]." "; ?> grams</td> <td width="9%" style="font:Verdana, Geneva, sans-serif; font-size: 10px;" class="K"><p>*Price:</td> <td width="13%" style="font:Verdana, Geneva, sans-serif; font-size: 10px;" class="K2"><?php echo " ".$_POST["usd"]." "; ?> USD</td> </tr> </table> <hr color="#CCCCCC" /> <table width="100%"> <tr> <td width="57%" height="67"><p>Item ID:</p> <font face="IDAutomationHC39M" color="#000000" size="+2"> <?php echo " " .$_POST["contents"]. " "; ?> </font> </td> <td width="43%"><p>Tracking Code:</p> <p> </p></td> </tr> </table> <?php echo "<input type='hidden' name='to' value='".$_POST["to"]."' />"; echo "<input type='hidden' name='from' value='".$_POST["from"]."' />"; echo "<input type='hidden' name='content' value='".$_POST["cat"]."' />"; echo "<input type='hidden' name='wgt' value='".$_POST["wgt"]."' />"; echo "<input type='hidden' name='usd' value='".$_POST["usd"]."' />"; echo "<input type='hidden' name='usd' value='".$_POST["contents"]."' />"; ?></td> </tr> </table> PHP:
It's not currently with exactly names with columns in your table and you have to edit it, but it should be like this. In this case, `to` and `from` should have these `` beacuse it can be part of MYSQL statement
Can you give me complete syntax like where to add the above line after connecting to DB? <?php // contact to database $connect = mysql_connect("127.0.0.1", "root", "") or die ("Error , check your server connection."); mysql_select_db("sarao"); PHP:
first you have to put <form> start before input hidden fields and then place button. IF you click it, it does action written in <form> <form> looks like this <form method="post" action="doit.php"> <input type="hidden" name="id" value="0" /> <input type="submit" name="submit" value="submit" /Â > </form> in this case it calls doit.php which is proccessing form.
Ok I figured it out. Thank you. One thing I need again is to retrieve the data from the said tables and display them on the page with the way I want. I mean on the preview page, I displayed the information in the tables using the snipped <?php echo " :" .$_POST["item"]. " "; ?> PHP: CAn you please tell, how can I use the anippet like above to retrieve the data from MySQL so I can customize the look?
$rows = mysql_query("SELECT * FROM tablename"); while ($row = mysql_fetch_assoc($rows)) { echo "to => ".$row['to'].", from => ".$row['from']." etc...."; } PHP:
Its gives me an error <?php // contact to database $connect = mysql_connect("127.0.0.1", "root", "") or die ("Error , check your server connection."); $rows = mysql_query("SELECT * FROM info"); while ($row = mysql_fetch_assoc($rows)) { echo "to => ".$row['to'].", "from => ".$row['from']."; } ?> PHP: Parse error: parse error, expecting `','' or `';'' in C:\wamp\www\display.php on line 12 Code (markup):
this one <?php // contact to database $connect = mysql_connect("127.0.0.1", "root", "") or die ("Error , check your server connection."); $rows = mysql_query("SELECT * FROM info"); while ($row = mysql_fetch_assoc($rows)) { echo "to => ".$row['to'].", from => ".$row['from']."...."; } ?> PHP:
<?php // contact to database $connect = mysql_connect("127.0.0.1", "root", "") or die ("Error , check your server connection.");$rows = mysql_query("SELECT * FROM info");while ($row = mysql_fetch_assoc($rows)) { echo "to => ".$row['to'].", from => ".$row['from']."; } ?> PHP: Parse error: parse error in C:\wamp\www\display.php on line 10 Code (markup):
okay this <?php // contact to database $connect = mysql_connect("127.0.0.1", "root", "") or die ("Error , check your server connection."); $rows = mysql_query("SELECT * FROM info"); while ($row = mysql_fetch_assoc($rows)) { echo "to => ".$row['to'].", from => ".$row['from']."...."; } ?> PHP:
Then it says: Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in C:\wamp\www\display.php on line 7 Code (markup):