![]() |
|||||||||||||||||||
|
%s', $sql);
$result = mysql_query($sql, $conn) or die(mysql_error());
}
//---------------------------- END update a record ----------------------
//--------------------------- START add a record ------------------------
if ($_REQUEST["hdnAdd"] == "true") {
//add a new record and its image file
$upload = $_FILES["filAddPicture"];
//the $_FILES superglobal is an array of arrays, that is an
// array of file information for each file being uploaded
//printf('Uploading picture %s from %s with %s bytes of type %s to %s ', $upload["name"], $upload["tmp_name"], $upload["size"], $upload["type"], dirname(__FILE__)."/".IMGFLD); //dirname() returns the directory portion of a pathname move_uploaded_file($upload["tmp_name"], dirname(__FILE__)."/".IMGFLD.$upload["name"]); // or die("Couldn't upload file!"); //make directory can be uploaded to with write permissions eg // # chmod 777 /var/www/users/images $sql = sprintf('INSERT INTO products (catID, name, shortDesc, description, picture, price) VALUES ("%s", "%s", "%s", "%s", "%s", "%.2f");', $_REQUEST["txtAddCatID"], $_REQUEST["txtAddName"], $_REQUEST["txtShortDesc"], $_REQUEST["txtAddDescription"], $upload["name"], $_REQUEST["txtAddPrice"]); // printf(' %s', $sql); $result = mysql_query($sql, $conn) or die(mysql_error()); } //---------------------------- END add a record ------------------------ //-------------------------- START delete a record --------------------- if ($_REQUEST["delete"] != "") { $sql = sprintf('SELECT picture FROM products WHERE productID = "%s";', $_REQUEST["delete"]); $result = mysql_query($sql, $conn) or die(mysql_error()); $row = mysql_fetch_array($result); if ($row["picture"] != "") { unlink(dirname(__FILE__)."/".IMGFLD.$row["picture"]); //delete any picture file for this record } $sql = sprintf('DELETE FROM products WHERE productID = "%s";', $_REQUEST["delete"]); //printf(' %s', $sql); $result = mysql_query($sql, $conn) or die(mysql_error()); } //------------------------------ END delete a record ------------------- //-------------------------- START display pricelist ------------------- printf(' ');
$sql = sprintf('SELECT * FROM cat;');
$result = mysql_query($sql, $conn) or die(mysql_error());
$row = mysql_fetch_array($result);
// ------------------------START display select categories--------------
printf('');
if ($_REQUEST["selCat"] == "") {
// display welcome message if no categries are selected
printf('
'); } if ($_REQUEST["selCat"] == 5) { $sql = sprintf('SELECT * FROM products;'); } else { $sql = sprintf('SELECT * FROM products WHERE catID = "%s";', $_REQUEST["selCat"]); } //set up an sql command $result = mysql_query($sql, $conn) or die(mysql_error()); //run query or display error and stop script $row_count = mysql_num_rows($result); //get the number of rows returned by the query //echo " $row_count"; mysql_close($conn); //close database connection to free up server resources if ($_SESSION["admin"]) { //---------------------------- START display admin pricelist --------- printf(' '); //------------------------------ END add row ------------------------ while ($row = mysql_fetch_array($result)) { //each $row is the next array of fields from the table //when the rows run out, $row is null and the while loop terminates printf(' '); } //-------------------------- END display admin pricelist --------------- } else { //------------------------- START display user pricelist ---------------- while ($row = mysql_fetch_array($result)) { //each $row is the next array of fields from the table //when the rows run out, $row is null and the while loop terminates printf('
'); } //-------------------------- END display user pricelist ------------------ } //----------------------------- END display pricelist -------------------- ?>
|
||||||||||||||||||
|
|||||||||||||||||||