You are here: Newbie « PHP Programming Language « IT news, forums, messages
Newbie

Posted by Yaz on 11/01/05 20:11

I apologise for asking such a basic question, I'm a newbie. I've been
programming cobol for a few years, and now I'm teaching myself php.

I'm trying to code an order form, where values are populated into an
HTML table from a MySql database.
Each row in the table has a "buy" button, and the user can fill in a
quantity button to indicate how many items he/she wants to buy.

On pressing the button, I want to call a php function. The php function
when called would need to insert an order to the database.
Sounds simple, but I don't know how to get the HTML/PHP to call a PHP
function to do the insert.

My code (which displays the HTML table looks like this

<html>
<head>
<basefont face="Arial">
</head>
<body>
<?php
$host = "localhost";
$username = "root";
$password = "";
$db_name = "pk0111";
$conn = mysql_connect($db_host, $username, $password);
$connection = mysql_connect($host, $user, $pass) or die ("Unable to
connect!");
mysql_select_db($db_name) or die ("Unable to select database!");
$query = "SELECT * FROM products";
$result = mysql_query($query) or die ("Error in query: $query.
".mysql_error());
if (mysql_num_rows($result) > 0) {
echo "<table cellpadding=10 border=1>";
$rowcount = 0;
while($row = mysql_fetch_row($result)) {
$rowcount ++;
echo "<tr>";
echo "<td>".$row[0]."</td>";
echo "<td>" . $row[1]."</td>";
?>
<TD>
Qty: <input type="text" name=$rowcount size="2">
<input type="button" value="Buy" name = $rowcount
onclick="myfunction()">
</form>
</TD>
</tr>
<?php
}
echo "</table>";
}
else {
// no
// print status message
echo "No rows found!";
}
// free result set memory
mysql_free_result($result);
// close connection
mysql_close($connection);
?>
</body>
</html>

=============================================================
However the line

Qty: <input type="text" name=$rowcount size="2">
<input type="button" value="Buy" name = $rowcount
onclick="myfunction()">

wont call my PHP function myfunction(). I have inserted a function
called myfunction (not shown), but I get an "error on page" message

Any advice is much appreciated, I have already spent several hours
trying !

cheers
P

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация