PHP and mySQL
| From: | City Colleges of Chicago - Mannheim | Date: | Mon, 13 May 2002 10:18:56 +0000 |
| Subject: | PHP and mySQL | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-97330@lists.php.net to get a copy of this message | ||
I am a student working on a practicum problem. I have a mySQL database that
contains the books, their title, and how many are in stock. When a person
orders one of the books, I want the stock to be adjusted by how many,
quantity, that they chose when the submit button is clicked. The scripts
are written in PHP.
Here is part of my code:
<P>The book you are ordering:
<?
echo " $booktitle ";
?>
<P>Additional Message:<br>
<textarea name="message" cols=30 rows=3></textarea>
</p>
<INPUT type="submit" value="Send your order.">
<input type=hidden name="booktitle" value="<? print $booktitle; ?>">
</FORM>
<?php
$user = "adminer";
$pass = "hoosiers";
$db = "Book Store1";
$local = "jolinux";
$link = mysql_connect( "$local", $user, $pass );
if (! $link )
die ( "Couldn't open the database" );
mysql_select_db( $db, $link )
or die ( "Couldn't open the $db: ".mysql_error() );
if ($submit){
if( $booktitle, 'quantity' ){
$sql = "UPDATE Book2 SET stock ='$stock-quantity' WHERE booktitle=$booktitle
AND quantity=quantity";
}
// $result = mysql_query($mysql);
}else if(!$submit){
echo "Your order has not been placed.<p>";
}
?>
</BODY>
</HTML>