-
Posts
21 -
Joined
-
Last visited
Never
Everything posted by alpha1
-
isit possible to have two different databses connect to one page
alpha1 replied to alpha1's topic in PHP Coding Help
thanks for all your help guys, this is my select code <?php error_reporting(E_ALL); ini_set("display_errors", 0); include "storescripts/connect_to_mysql2.php"; function createoptions($table , $id , $field , $condition_field , $value) { $sql = sprintf("select * from $table WHERE $condition_field=%d ORDER BY $field" , $value); $res = mysql_query($sql) or die(mysql_error()); if (mysql_num_rows($res) > 0) { while ($a = mysql_fetch_assoc($res)) $out[] = "{optionValue: {$a[$id]}, optionDisplay: '$a[$field]'}"; return "[" . implode("," , $out) . "]"; } else return "[{optionValue: -1 , optionDisplay: 'No result'}]"; } if (isset($_GET['Make'])) { echo createoptions("Model" , "Model_id" , "Model" , "Make_id" , $_GET['Make']); } if (isset($_GET['Model'])) { echo createoptions("Year" , "Year_id" , "Year" , "Model_id" , $_GET['Model']); } die(); ?> But as you explained earlier that a connection is automatically closed at the end, what i might do to make it easier is to place everything in the 1st db again and remove the second connection if i don't need it. I’m going to go through my code and look over all of my connections to make the code more efficient also. -
i have added a ajax chained dropdown to my site, however i realised i have to leave the connection open so it can connect to the database to alter the second and third drop down. so i created a new sql to keep it more secure which would only hold this information <?php // Script Error Reporting error_reporting(E_ALL); ini_set('display_errors', '1'); ?> <?php // Run a select query to get my letest 6 items // Connect to the MySQL database include "storescripts/connect_to_mysql.php"; $dynamicCat = ""; $sql = mysql_query("SELECT * FROM categories ORDER BY category_name DESC LIMIT 6"); $categoriesCount = mysql_num_rows($sql); // count the output amount if ($categoriesCount > 0) { while($row = mysql_fetch_array($sql)){ $id = $row["id"]; $category_name = $row["category_name"]; $dynamicCat .= '<table> <a href="category.php?id=' . $id . '">' . $category_name . '</a></td> </tr> </table>'; } } else { $dynamicCat = "We have no products listed in our store yet"; } mysql_close(); ?> <?php // Run a select query to get my letest 6 items // Connect to the MySQL database include "storescripts/connect_to_mysql.php"; $dynamicList = ""; $sql = mysql_query("SELECT * FROM products ORDER BY date_added DESC LIMIT 6"); $productCount = mysql_num_rows($sql); // count the output amount if ($productCount > 0) { while($row = mysql_fetch_array($sql)){ $id = $row["id"]; $product_name = $row["product_name"]; $price = $row["price"]; $date_added = strftime("%b %d, %Y", strtotime($row["date_added"])); $dynamicList .= '<table width="100%" border="0" cellspacing="0" cellpadding="6"> <tr> <td width="17%" valign="top"><a href="product.php?id=' . $id . '"><img style="border:#666 1px solid;" src="inventory_images/' . $id . '.jpg" alt="' . $product_name . '" width="102" height="102" border="1" /></a></td> <td width="83%" valign="top">' . $product_name . '<br /> £' . $price . '<br /> <a href="product.php?id=' . $id . '">View Product Details</a></td> </tr> </table>'; } } else { $dynamicList = "We have no products listed in our store yet"; } mysql_close(); ?> <?php include("storescripts/connect_to_mysql2.php"); function createoptions($table , $id , $field) { $sql = "select * from $table ORDER BY $field"; $res = mysql_query($sql) or die(mysql_error()); while ($a = mysql_fetch_assoc($res)) echo "<option value=\"{$a[$id]}\">$a[$field]</option>"; } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="stylesheet" href="style/style.css" type="text/css" media="screen" /> <script type="text/javascript" src="storescripts/jquery.js"></script> <script type="text/javascript" charset="utf-8"> $(function(){ $("select#Make").change(function(){ $.getJSON("select.php",{Make: $(this).val(), ajax: 'true'}, function(j){ var options = ''; for (var i = 0; i < j.length; i++) { options += '<option value="' + j[i].optionValue + '">' + j[i].optionDisplay + '</option>'; } $("select#Model").html(options); }) }) // Year elemeinek feltöltése $("select#Model").change(function(){ $.getJSON("select.php",{Model: $(this).val(), ajax: 'true'}, function(j){ var options = ''; for (var i = 0; i < j.length; i++) { options += '<option value="' + j[i].optionValue + '">' + j[i].optionDisplay + '</option>'; } $("select#Year").html(options); }) }) }) </script> <title>home</title> </head> <body> <div align="center" id="mainWrapper"> <?php include_once("template_header.php");?> <div id="pageContent"><table width="100%" border="1"> <tr> <td width="24%" valign="top"><p>some crap</p> <p><?php echo $dynamicCat; ?></p> <p> </p> <p> </p> <p> </p></td> <td width="39%" valign="top"><p>newiest crap added to store</p> <p><?php echo $dynamicList; ?><br /> <br /> </p> <!--<table width="100%" border="1" cellpadding="2"> <tr> <td width="38%" valign="top"><a href="product.php?"><img style= "border:#000 1px solid;" src="inventory_images/HID_Kit-EPE_Package_small__39228_zoom.jpg" alt="$dynamicTitle" width="149" height="110" border="1" /></a></td> <td width="62%" valign="top"><p>Product Title</p> <p>Product Price</p> <p>View Product</p></td> </tr> </table> --> <p> </p></td> <td width="37%" valign="top"><p>more crap</p> <p> <select id="Make"> <option value="-1">--Select--</option> <?php createoptions("Make", "Make_id", "Make"); ?> </select> <select id="Model"> </select> <select id="Year"> </select></p></td> </tr> </table> </div> <?php include_once("template_footer.php");?> </div> </body> </html> however now the dropdowns are not working, i have changed the connection details in the select file also to the newconnection file any advice???
-
Is it possible to populate a dropdown box from a MySQL dB
alpha1 replied to alpha1's topic in Javascript Help
thank you, your a legend -
Is it possible to populate a dropdown box from a MySQL dB, if so can someone advise me on how to do it. I know you need to use Ajax make on dropdown box depended on another dropdown box, but i don't have a clue on how to do either problem. What I’m trying to do it make on dropdown box depended on another. e.g. Dropdown box 1 called make Dropdown box 2 called model After selecting ford drop the 1st box the second box would populate from the sql with all the ford models. Can someone send me towards a tutorial or give me some advice on what i need to look up Thank you
-
hi im interested to learn how website such as www.autotrader.co.uk have that drop down menu when when you change make, it gives you a different list in model. i have no experence with javascript or ajax and would love it if you could explain it to me, or direct me to a tutorial. what i want to do is create a database with different car makes, model, varient and year and somehow this to dynamically appear in the dropdown boxs. e.g. in a table if i have inputed the data make - ford model - mondeo varient - 1.6 year -2005 then dynamically an option for ford appears in the makes drop down, when thats clicked dynamically the option mondeo appears in the model drop down etc. isit possible?
-
thank you, you've been very helpful. im going to start working on this and see how it goes
-
no currently all it does is get an order and email me letting me know, i need to put it into my system so i can keep a recprd of it also
-
thank you but how would i update my ordered table after the transaction is complete by paypal, would that be done by my IPN script? this is the ipn script <?php // Check to see there are posted variables coming into the script if ($_SERVER['REQUEST_METHOD'] != "POST") die ("No Post Variables"); // Initialize the $req variable and add CMD key value pair $req = 'cmd=_notify-validate'; // Read the post from PayPal foreach ($_POST as $key => $value) { $value = urlencode(stripslashes($value)); $req .= "&$key=$value"; } // Now Post all of that back to PayPal's server using curl, and validate everything with PayPal // We will use CURL instead of PHP for this for a more universally operable script (fsockopen has issues on some environments) //$url = "https://www.sandbox.paypal.com/cgi-bin/webscr"; $url = "https://www.paypal.com/cgi-bin/webscr"; $curl_result=$curl_err=''; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL,$url); curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $req); curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/x-www-form-urlencoded", "Content-Length: " . strlen($req))); curl_setopt($ch, CURLOPT_HEADER , 0); curl_setopt($ch, CURLOPT_VERBOSE, 1); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ch, CURLOPT_TIMEOUT, 30); $curl_result = @curl_exec($ch); $curl_err = curl_error($ch); curl_close($ch); $req = str_replace("&", "\n", $req); // Make it a nice list in case we want to email it to ourselves for reporting // Check that the result verifies if (strpos($curl_result, "VERIFIED") !== false) { $req .= "\n\nPaypal Verified OK"; } else { $req .= "\n\nData NOT verified from Paypal!"; mail("xx", "IPN interaction not verified", "$req", "From: xx" ); exit(); } /* CHECK THESE 4 THINGS BEFORE PROCESSING THE TRANSACTION, HANDLE THEM AS YOU WISH 1. Make sure that business email returned is your business email 2. Make sure that the transaction's payment status is "completed" 3. Make sure there are no duplicate txn_id 4. Make sure the payment amount matches what you charge for items. (Defeat Price-Jacking) */ // Check Number 1 ------------------------------------------------------------------------------------------------------------ $receiver_email = $_POST['receiver_email']; if ($receiver_email != "xx") { $message = "Investigate why and how receiver email is wrong. Email = " . $_POST['receiver_email'] . "\n\n\n$req"; mail("xx", "Receiver Email is incorrect", $message, "From: xx" ); exit(); // exit script } // Check number 2 ------------------------------------------------------------------------------------------------------------ if ($_POST['payment_status'] != "Completed") { // Handle how you think you should if a payment is not complete yet, a few scenarios can cause a transaction to be incomplete } // Connect to database ------------------------------------------------------------------------------------------------------ require_once 'connect_to_mysql.php'; // Check number 3 ------------------------------------------------------------------------------------------------------------ $this_txn = $_POST['txn_id']; $sql = mysql_query("SELECT id FROM transactions WHERE txn_id='$this_txn' LIMIT 1"); $numRows = mysql_num_rows($sql); if ($numRows > 0) { $message = "Duplicate transaction ID occured so we killed the IPN script. \n\n\n$req"; mail("xx", "Duplicate txn_id in the IPN system", $message, "From:xxx" ); exit(); // exit script } // Check number 4 ------------------------------------------------------------------------------------------------------------ $product_id_string = $_POST['custom']; $product_id_string = rtrim($product_id_string, ","); // remove last comma // Explode the string, make it an array, then query all the prices out, add them up, and make sure they match the payment_gross amount $id_str_array = explode(",", $product_id_string); // Uses Comma(,) as delimiter(break point) $fullAmount = 0; foreach ($id_str_array as $key => $value) { $id_quantity_pair = explode("-", $value); // Uses Hyphen(-) as delimiter to separate product ID from its quantity $product_id = $id_quantity_pair[0]; // Get the product ID $product_quantity = $id_quantity_pair[1]; // Get the quantity $sql = mysql_query("SELECT price FROM products WHERE id='$product_id' LIMIT 1"); while($row = mysql_fetch_array($sql)){ $product_price = $row["price"]; } $product_price = $product_price * $product_quantity; $fullAmount = $fullAmount + $product_price; } $fullAmount = number_format($fullAmount, 2); $grossAmount = $_POST['mc_gross']; if ($fullAmount != $grossAmount) { $message = "Possible Price Jack: " . $_POST['payment_gross'] . " != $fullAmount \n\n\n$req"; mail("xxx", "Price Jack or Bad Programming", $message, "From: xxx" ); exit(); // exit script } // END ALL SECURITY CHECKS NOW IN THE DATABASE IT GOES ------------------------------------ //////////////////////////////////////////////////// // Homework - Examples of assigning local variables from the POST variables $txn_id = $_POST['txn_id']; $payer_email = $_POST['payer_email']; $custom = $_POST['custom']; // Place the transaction into the database $sql = mysql_query("INSERT INTO transactions (product_id_array, payer_email, first_name, last_name, payment_date, mc_gross, payment_currency, txn_id, receiver_email, payment_type, payment_status, txn_type, payer_status, address_street, address_city, address_state, address_zip, address_country, address_status, notify_version, verify_sign, payer_id, mc_currency, mc_fee) VALUES('$custom','$payer_email','$first_name','$last_name','$payment_date','$mc_gross','$payment_currency','$txn_id','$receiver_email','$payment_type','$payment_status','$txn_type','$payer_status','$address_street','$address_city','$address_state','$address_zip','$address_country','$address_status','$notify_version','$verify_sign','$payer_id','$mc_currency','$mc_fee')") or die ("unable to execute the query"); mysql_close(); // Mail yourself the details mail("xx", "NORMAL IPN RESULT YAY MONEY!", $req, "From: xx"); ?>
-
$sqlCommand = "CREATE TABLE products ( id int(11) NOT NULL auto_increment, product_name varchar(255) NOT NULL, price varchar(16) NOT NULL, details text NOT NULL, category varchar(16) NOT NULL, subcategory varchar(16) NOT NULL, m_tag text NOT NULL, date_added date NOT NULL, PRIMARY KEY (id), UNIQUE KEY product_name (product_name) ) ";. this is currently my database, i would like to create a stock level count so im assuming i need a new field called (stock) also on my homepage i would like a list of best selling items so im probably going to need a (total sold) my website has a basket, when you click check out it goes to paypal so you can pay for your transaction. i have a ipn script to verify with payal. but i dont have a clue how to update my stock level after each transaction. can someone please help and point me in the right direction
-
hi, baiscally i have a products that go into the products mysql and get called by php but with each product there are different options, e.g. mens jumper - comes in sizes m,l,xl,xxl mens jeans might only come in s, m, l shoes are in 6,7,8,9,10,11 my question is how do i make a drop down list different for each product, when there all in the same db, if some one can reccomend a tutorial or a concept, i would really appreciate it thank you
-
i figured it out, im such a idiot. I copied the page inventory_list.php and made the changes to that and called it inventory_list2.php. when the form was pharsing it was being sent to inventory_list.php where the mysql query was wrong. you made me realise when you asked me to echo m_tag thanks for you help lol
-
ok i did that and yes it returned the result that i put is the text box, <?php // Parse the form data and add inventory item to the system if (isset($_POST['product_name'])) { $product_name = mysql_real_escape_string($_POST['product_name']); $price = mysql_real_escape_string($_POST['price']); $category = mysql_real_escape_string($_POST['category']); $subcategory = mysql_real_escape_string($_POST['subcategory']); $details = mysql_real_escape_string($_POST['details']); $m_tag = mysql_real_escape_string($_POST['m_tag']); // See if that product name is an identical match to another product in the system $sql = mysql_query("SELECT id FROM products WHERE product_name='$product_name' LIMIT 1"); $productMatch = mysql_num_rows($sql); // count the output amount if ($productMatch > 0) { echo 'Sorry you tried to place a duplicate "Product Name" into the system, <a href="inventory_list.php">click here</a>'; exit(); } /* // Add this product into the database now $sql = mysql_query("INSERT INTO products (product_name, price, details, category, subcategory, m_tag, date_added) VALUES('$product_name','$price','$details','$category','$subcategory','$m_tag',now())") or die (mysql_error()); $pid = mysql_insert_id(); // Place image in the folder $newname = "$pid.jpg"; move_uploaded_file( $_FILES['fileField']['tmp_name'], "../inventory_images/$newname"); header("location: inventory_list.php"); */ echo "m_tag is: $m_tag"; exit(); } ?> so that means there must be a problem with the Add this product into the database now $sql = mysql_query("INSERT INTO products (product_name, price, details, category, subcategory, m_tag, date_added) VALUES('$product_name','$price','$details','$category','$subcategory','$m_tag',now())") or die (mysql_error()); but i can't see it any idea? sorry about before, im new to all this thanks for helping
-
when the parses all the other variables get sent except the m_tag, both "details" and "m_tag" and textbox and both boxes have the exactly the same code, just have a change in name. but for some reason "details gets sent but "m_tag" does not <?php // Parse the form data and add inventory item to the system if (isset($_POST['product_name'])) { $product_name = mysql_real_escape_string($_POST['product_name']); $price = mysql_real_escape_string($_POST['price']); $category = mysql_real_escape_string($_POST['category']); $subcategory = mysql_real_escape_string($_POST['subcategory']); $details = mysql_real_escape_string($_POST['details']); $m_tag = mysql_real_escape_string($_POST['m_tag']); // See if that product name is an identical match to another product in the system $sql = mysql_query("SELECT id FROM products WHERE product_name='$product_name' LIMIT 1"); $productMatch = mysql_num_rows($sql); // count the output amount if ($productMatch > 0) { echo 'Sorry you tried to place a duplicate "Product Name" into the system, <a href="inventory_list.php">click here</a>'; exit(); } // Add this product into the database now $sql = mysql_query("INSERT INTO products (product_name, price, details, category, subcategory, m_tag, date_added) VALUES('$product_name','$price','$details','$category','$subcategory','$m_tag',now())") or die (mysql_error()); $pid = mysql_insert_id(); // Place image in the folder $newname = "$pid.jpg"; move_uploaded_file( $_FILES['fileField']['tmp_name'], "../inventory_images/$newname"); header("location: inventory_list.php"); exit(); a copy of the complete code of my page <?php session_start(); if (!isset($_SESSION["manager"])) { header("location: admin_login.php"); exit(); } // Be sure to check that this manager SESSION value is in fact in the database $managerID = preg_replace('#[^0-9]#i', '', $_SESSION["id"]); // filter everything but numbers and letters $manager = preg_replace('#[^A-Za-z0-9]#i', '', $_SESSION["manager"]); // filter everything but numbers and letters $password = preg_replace('#[^A-Za-z0-9]#i', '', $_SESSION["password"]); // filter everything but numbers and letters // Run mySQL query to be sure that this person is an admin and that their password session var equals the database information // Connect to the MySQL database include "../storescripts/connect_to_mysql.php"; $sql = mysql_query("SELECT * FROM admin WHERE id='$managerID' AND username='$manager' AND password='$password' LIMIT 1"); // query the person // ------- MAKE SURE PERSON EXISTS IN DATABASE --------- $existCount = mysql_num_rows($sql); // count the row nums if ($existCount == 0) { // evaluate the count echo "Your login session data is not on record in the database."; exit(); } ?> <?php // Script Error Reporting error_reporting(E_ALL); ini_set('display_errors', '1'); ?> <?php // Delete Item Question to Admin, and Delete Product if they choose if (isset($_GET['deleteid'])) { echo 'Do you really want to delete product with ID of ' . $_GET['deleteid'] . '? <a href="inventory_list.php?yesdelete=' . $_GET['deleteid'] . '">Yes</a> | <a href="inventory_list.php">No</a>'; exit(); } if (isset($_GET['yesdelete'])) { // remove item from system and delete its picture // delete from database $id_to_delete = $_GET['yesdelete']; $sql = mysql_query("DELETE FROM products WHERE id='$id_to_delete' LIMIT 1") or die (mysql_error()); // unlink the image from server // Remove The Pic ------------------------------------------- $pictodelete = ("../inventory_images/$id_to_delete.jpg"); if (file_exists($pictodelete)) { unlink($pictodelete); } header("location: inventory_list.php"); exit(); } ?> <?php // Parse the form data and add inventory item to the system if (isset($_POST['product_name'])) { $product_name = mysql_real_escape_string($_POST['product_name']); $price = mysql_real_escape_string($_POST['price']); $category = mysql_real_escape_string($_POST['category']); $subcategory = mysql_real_escape_string($_POST['subcategory']); $details = mysql_real_escape_string($_POST['details']); $m_tag = mysql_real_escape_string($_POST['m_tag']); // See if that product name is an identical match to another product in the system $sql = mysql_query("SELECT id FROM products WHERE product_name='$product_name' LIMIT 1"); $productMatch = mysql_num_rows($sql); // count the output amount if ($productMatch > 0) { echo 'Sorry you tried to place a duplicate "Product Name" into the system, <a href="inventory_list.php">click here</a>'; exit(); } // Add this product into the database now $sql = mysql_query("INSERT INTO products (product_name, price, details, category, subcategory, m_tag, date_added) VALUES('$product_name','$price','$details','$category','$subcategory','$m_tag',now())") or die (mysql_error()); $pid = mysql_insert_id(); // Place image in the folder $newname = "$pid.jpg"; move_uploaded_file( $_FILES['fileField']['tmp_name'], "../inventory_images/$newname"); header("location: inventory_list.php"); exit(); } ?> <?php // This block grabs the whole list for viewing $product_list = ""; $sql = mysql_query("SELECT * FROM products ORDER BY date_added DESC"); $productCount = mysql_num_rows($sql); // count the output amount if ($productCount > 0) { while($row = mysql_fetch_array($sql)){ $id = $row["id"]; $product_name = $row["product_name"]; $price = $row["price"]; $date_added = strftime("%b %d, %Y", strtotime($row["date_added"])); $product_list .= "Product ID: $id - <strong>$product_name</strong> - £$price - <em>Added $date_added</em> <a href='inventory_edit.php?pid=$id'>edit</a> • <a href='inventory_list.php?deleteid=$id'>delete</a><br />"; } } else { $product_list = "You have no products listed in your store yet"; } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Inventory List</title> <link rel="stylesheet" href="../style/style.css" type="text/css" media="screen" /> </head> <body> <div align="center" id="mainWrapper"> <?php include_once("../template_header.php");?> <div id="pageContent"><br /> <div align="right" style="margin-right:32px;"><a href="inventory_list.php#inventoryForm">+ Add New Inventory Item</a></div> <div align="left" style="margin-left:24px;"> <h2>Inventory list</h2> <?php echo $product_list; ?> </div> <hr /> <a name="inventoryForm" id="inventoryForm"></a> <h3> ↓ Add New Inventory Item Form ↓ </h3> <form action="inventory_list.php" enctype="multipart/form-data" name="myForm" id="myform" method="post"> <table width="90%" border="0" cellspacing="0" cellpadding="6"> <tr> <td width="20%" align="right">Product Name</td> <td width="80%" align="left"><label> <input name="product_name" type="text" id="product_name" size="64" /> </label></td> </tr> <tr> <td align="right">Product Price</td> <td align="left"><label> £ <input name="price" type="text" id="price" size="12" /> </label></td> </tr> <tr> <td align="right">Category</td> <td align="left"><label> <select name="category" id="category"> <option value="Clothing">Clothing</option> </select> </label></td> </tr> <tr> <td align="right">Subcategory</td> <td align="left"><select name="subcategory" id="subcategory"> <option value=""></option> <option value="Hats">Hats</option> <option value="Pants">Pants</option> <option value="Shirts">Shirts</option> </select></td> </tr> <tr> <td align="right">Product Details</td> <td align="left"><label> <textarea name="details" id="details" cols="64" rows="5"></textarea> </label></td> </tr> <tr> <td align="right">Product Image</td> <td align="left"><label> <input type="file" name="fileField" id="fileField" /> </label></td> </tr> <tr> <td align="right">Meta tag</td> <td align="left"><label> <textarea name="m_tag" id="m_tag" cols="64" rows="5"></textarea> </label></td> </tr> <tr> <td> </td> <td><label> <input type="submit" name="button" id="button" value="Add This Item Now" /> </label></td> </tr> </table> </form> <br /> <br /> </div> <?php include_once("../template_footer.php");?> </div> </body> </html>
-
i don't understand why the code im using for the details text box is not working for the m_tag box when its supposed to do exactly the same thing, in the same database :'(
-
sorry i don't understand, how i would do that, because when i form pharses it reloads the page with the new inventory details listed at the top along with some of its details. can you give me an example of what you mean also when you query the db, do you have to query the rows/ fields in order $sqlCommand = "CREATE TABLE products ( id int(11) NOT NULL auto_increment, product_name varchar(255) NOT NULL, price varchar(16) NOT NULL, details text NOT NULL, category varchar(16) NOT NULL, subcategory varchar(16) NOT NULL, date_added date NOT NULL, m_tag text NOT NULL, PRIMARY KEY (id), UNIQUE KEY product_name (product_name) ) "; so what i mean is do i query the date before the m_tag
-
ok ive changed the query to this // Add this product into the database now $sql = mysql_query("INSERT INTO products (product_name, price, details, category, subcategory, m_tag, date_added) VALUES('$product_name','$price','$details','$category','$subcategory','$m_tag',now())") or die (mysql_error()); $pid = mysql_insert_id(); // Place image in the folder $newname = "$pid.jpg"; move_uploaded_file( $_FILES['fileField']['tmp_name'], "../inventory_images/$newname"); header("location: inventory_list.php"); exit(); but it still does not work :-\ or did i enter it wrong, sorry im a complete newbie and im trying to learn as i go along
-
p.s i changed teh mtag name in the daabase to m_tag also
-
<?php session_start(); if (!isset($_SESSION["manager"])) { header("location: admin_login.php"); exit(); } // Be sure to check that this manager SESSION value is in fact in the database $managerID = preg_replace('#[^0-9]#i', '', $_SESSION["id"]); // filter everything but numbers and letters $manager = preg_replace('#[^A-Za-z0-9]#i', '', $_SESSION["manager"]); // filter everything but numbers and letters $password = preg_replace('#[^A-Za-z0-9]#i', '', $_SESSION["password"]); // filter everything but numbers and letters // Run mySQL query to be sure that this person is an admin and that their password session var equals the database information // Connect to the MySQL database include "../storescripts/connect_to_mysql.php"; $sql = mysql_query("SELECT * FROM admin WHERE id='$managerID' AND username='$manager' AND password='$password' LIMIT 1"); // query the person // ------- MAKE SURE PERSON EXISTS IN DATABASE --------- $existCount = mysql_num_rows($sql); // count the row nums if ($existCount == 0) { // evaluate the count echo "Your login session data is not on record in the database."; exit(); } ?> <?php // Script Error Reporting error_reporting(E_ALL); ini_set('display_errors', '1'); ?> <?php // Delete Item Question to Admin, and Delete Product if they choose if (isset($_GET['deleteid'])) { echo 'Do you really want to delete product with ID of ' . $_GET['deleteid'] . '? <a href="inventory_list.php?yesdelete=' . $_GET['deleteid'] . '">Yes</a> | <a href="inventory_list.php">No</a>'; exit(); } if (isset($_GET['yesdelete'])) { // remove item from system and delete its picture // delete from database $id_to_delete = $_GET['yesdelete']; $sql = mysql_query("DELETE FROM products WHERE id='$id_to_delete' LIMIT 1") or die (mysql_error()); // unlink the image from server // Remove The Pic ------------------------------------------- $pictodelete = ("../inventory_images/$id_to_delete.jpg"); if (file_exists($pictodelete)) { unlink($pictodelete); } header("location: inventory_list.php"); exit(); } ?> <?php // Parse the form data and add inventory item to the system if (isset($_POST['product_name'])) { $product_name = mysql_real_escape_string($_POST['product_name']); $price = mysql_real_escape_string($_POST['price']); $category = mysql_real_escape_string($_POST['category']); $subcategory = mysql_real_escape_string($_POST['subcategory']); $details = mysql_real_escape_string($_POST['details']); $m_tag = mysql_real_escape_string($_POST['m_tag']); // See if that product name is an identical match to another product in the system $sql = mysql_query("SELECT id FROM products WHERE product_name='$product_name' LIMIT 1"); $productMatch = mysql_num_rows($sql); // count the output amount if ($productMatch > 0) { echo 'Sorry you tried to place a duplicate "Product Name" into the system, <a href="inventory_list.php">click here</a>'; exit(); } // Add this product into the database now $sql = mysql_query("INSERT INTO products (product_name, m_tag, price, details, category, subcategory, date_added) VALUES('$product_name','$price','$details','$category','$subcategory',now, '$m_tag'())") or die (mysql_error()); $pid = mysql_insert_id(); // Place image in the folder $newname = "$pid.jpg"; move_uploaded_file( $_FILES['fileField']['tmp_name'], "../inventory_images/$newname"); header("location: inventory_list.php"); exit(); } ?> <?php // This block grabs the whole list for viewing $product_list = ""; $sql = mysql_query("SELECT * FROM products ORDER BY date_added DESC"); $productCount = mysql_num_rows($sql); // count the output amount if ($productCount > 0) { while($row = mysql_fetch_array($sql)){ $id = $row["id"]; $product_name = $row["product_name"]; $price = $row["price"]; $date_added = strftime("%b %d, %Y", strtotime($row["date_added"])); $product_list .= "Product ID: $id - <strong>$product_name</strong> - £$price - <em>Added $date_added</em> <a href='inventory_edit.php?pid=$id'>edit</a> • <a href='inventory_list.php?deleteid=$id'>delete</a><br />"; } } else { $product_list = "You have no products listed in your store yet"; } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Inventory List</title> <link rel="stylesheet" href="../style/style.css" type="text/css" media="screen" /> </head> <body> <div align="center" id="mainWrapper"> <?php include_once("../template_header.php");?> <div id="pageContent"><br /> <div align="right" style="margin-right:32px;"><a href="inventory_list.php#inventoryForm">+ Add New Inventory Item</a></div> <div align="left" style="margin-left:24px;"> <h2>Inventory list</h2> <?php echo $product_list; ?> </div> <hr /> <a name="inventoryForm" id="inventoryForm"></a> <h3> ↓ Add New Inventory Item Form ↓ </h3> <form action="inventory_list.php" enctype="multipart/form-data" name="myForm" id="myform" method="post"> <table width="90%" border="0" cellspacing="0" cellpadding="6"> <tr> <td width="20%" align="right">Product Name</td> <td width="80%" align="left"><label> <input name="product_name" type="text" id="product_name" size="64" /> </label></td> </tr> <tr> <td align="right">Product Price</td> <td align="left"><label> £ <input name="price" type="text" id="price" size="12" /> </label></td> </tr> <tr> <td align="right">Category</td> <td align="left"><label> <select name="category" id="category"> <option value="Clothing">Clothing</option> </select> </label></td> </tr> <tr> <td align="right">Subcategory</td> <td align="left"><select name="subcategory" id="subcategory"> <option value=""></option> <option value="Hats">Hats</option> <option value="Pants">Pants</option> <option value="Shirts">Shirts</option> </select></td> </tr> <tr> <td align="right">Product Details</td> <td align="left"><label> <textarea name="details" id="details" cols="64" rows="5"></textarea> </label></td> </tr> <tr> <td align="right">Product Image</td> <td align="left"><label> <input type="file" name="fileField" id="fileField" /> </label></td> </tr> <tr> <td align="right">Meta tag</td> <td align="left"><label> <textarea name="m_tag" id="m_tag" cols="64" rows="5"></textarea> </label></td> </tr> <tr> <td> </td> <td><label> <input type="submit" name="button" id="button" value="Add This Item Now" /> </label></td> </tr> </table> </form> <br /> <br /> </div> <?php include_once("../template_footer.php");?> </div> </body> </html> ok ive modified the mtag to m_tag because somebody suggested it adn a few other things to this, but its still not working :'( some one please help
-
the rest of my form works fine, they all upload to the database, however my mtag does not. can some one please help me. ive been looking at this code for days but can't figure out why <?php session_start(); if (!isset($_SESSION["manager"])) { header("location: admin_login.php"); exit(); } // Be sure to check that this manager SESSION value is in fact in the database $managerID = preg_replace('#[^0-9]#i', '', $_SESSION["id"]); // filter everything but numbers and letters $manager = preg_replace('#[^A-Za-z0-9]#i', '', $_SESSION["manager"]); // filter everything but numbers and letters $password = preg_replace('#[^A-Za-z0-9]#i', '', $_SESSION["password"]); // filter everything but numbers and letters // Run mySQL query to be sure that this person is an admin and that their password session var equals the database information // Connect to the MySQL database include "../storescripts/connect_to_mysql.php"; $sql = mysql_query("SELECT * FROM admin WHERE id='$managerID' AND username='$manager' AND password='$password' LIMIT 1"); // query the person // ------- MAKE SURE PERSON EXISTS IN DATABASE --------- $existCount = mysql_num_rows($sql); // count the row nums if ($existCount == 0) { // evaluate the count echo "Your login session data is not on record in the database."; exit(); } ?> <?php // Script Error Reporting error_reporting(E_ALL); ini_set('display_errors', '1'); ?> <?php // Delete Item Question to Admin, and Delete Product if they choose if (isset($_GET['deleteid'])) { echo 'Do you really want to delete product with ID of ' . $_GET['deleteid'] . '? <a href="inventory_list.php?yesdelete=' . $_GET['deleteid'] . '">Yes</a> | <a href="inventory_list.php">No</a>'; exit(); } if (isset($_GET['yesdelete'])) { // remove item from system and delete its picture // delete from database $id_to_delete = $_GET['yesdelete']; $sql = mysql_query("DELETE FROM products WHERE id='$id_to_delete' LIMIT 1") or die (mysql_error()); // unlink the image from server // Remove The Pic ------------------------------------------- $pictodelete = ("../inventory_images/$id_to_delete.jpg"); if (file_exists($pictodelete)) { unlink($pictodelete); } header("location: inventory_list.php"); exit(); } ?> <?php // Parse the form data and add inventory item to the system if (isset($_POST['product_name'])) { $product_name = mysql_real_escape_string($_POST['product_name']); $price = mysql_real_escape_string($_POST['price']); $category = mysql_real_escape_string($_POST['category']); $subcategory = mysql_real_escape_string($_POST['subcategory']); $details = mysql_real_escape_string($_POST['details']); $mtag = mysql_real_escape_string($_POST['mtag']); // See if that product name is an identical match to another product in the system $sql = mysql_query("SELECT id FROM products WHERE product_name='$product_name' LIMIT 1"); $productMatch = mysql_num_rows($sql); // count the output amount if ($productMatch > 0) { echo 'Sorry you tried to place a duplicate "Product Name" into the system, <a href="inventory_list.php">click here</a>'; exit(); } // Add this product into the database now $sql = mysql_query("INSERT INTO products (product_name, price, details, category, subcategory, date_added) VALUES('$product_name','$price','$details','$category','$subcategory',now, '$mtag'())") or die (mysql_error()); $pid = mysql_insert_id(); // Place image in the folder $newname = "$pid.jpg"; move_uploaded_file( $_FILES['fileField']['tmp_name'], "../inventory_images/$newname"); header("location: inventory_list.php"); exit(); } ?> <?php // This block grabs the whole list for viewing $product_list = ""; $sql = mysql_query("SELECT * FROM products ORDER BY date_added DESC"); $productCount = mysql_num_rows($sql); // count the output amount if ($productCount > 0) { while($row = mysql_fetch_array($sql)){ $id = $row["id"]; $product_name = $row["product_name"]; $price = $row["price"]; $date_added = strftime("%b %d, %Y", strtotime($row["date_added"])); $product_list .= "Product ID: $id - <strong>$product_name</strong> - £$price - <em>Added $date_added</em> <a href='inventory_edit.php?pid=$id'>edit</a> • <a href='inventory_list.php?deleteid=$id'>delete</a><br />"; } } else { $product_list = "You have no products listed in your store yet"; } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Inventory List</title> <link rel="stylesheet" href="../style/style.css" type="text/css" media="screen" /> </head> <body> <div align="center" id="mainWrapper"> <?php include_once("../template_header.php");?> <div id="pageContent"><br /> <div align="right" style="margin-right:32px;"><a href="inventory_list.php#inventoryForm">+ Add New Inventory Item</a></div> <div align="left" style="margin-left:24px;"> <h2>Inventory list</h2> <?php echo $product_list; ?> </div> <hr /> <a name="inventoryForm" id="inventoryForm"></a> <h3> ↓ Add New Inventory Item Form ↓ </h3> <form action="inventory_list.php" enctype="multipart/form-data" name="myForm" id="myform" method="post"> <table width="90%" border="0" cellspacing="0" cellpadding="6"> <tr> <td width="20%" align="right">Product Name</td> <td width="80%" align="left"><label> <input name="product_name" type="text" id="product_name" size="64" /> </label></td> </tr> <tr> <td align="right">Product Price</td> <td align="left"><label> £ <input name="price" type="text" id="price" size="12" /> </label></td> </tr> <tr> <td align="right">Category</td> <td align="left"><label> <select name="category" id="category"> <option value="Clothing">Clothing</option> </select> </label></td> </tr> <tr> <td align="right">Subcategory</td> <td align="left"><select name="subcategory" id="subcategory"> <option value=""></option> <option value="Hats">Hats</option> <option value="Pants">Pants</option> <option value="Shirts">Shirts</option> </select></td> </tr> <tr> <td align="right">Product Details</td> <td align="left"><label> <textarea name="details" id="details" cols="64" rows="5"></textarea> </label></td> </tr> <tr> <td align="right">Product Image</td> <td align="left"><label> <input type="file" name="fileField" id="fileField" /> </label></td> </tr> <tr> <td align="right">Meta tag</td> <td align="left"><label> <textarea name="mtag" id="mtag" cols="64" rows="5"></textarea> </label></td> </tr> <tr> <td> </td> <td><label> <input type="submit" name="button" id="button" value="Add This Item Now" /> </label></td> </tr> </table> </form> <br /> <br /> </div> <?php include_once("../template_footer.php");?> </div> </body> </html>
-
Oh sorry it was my first comment, I didn't know. Any advice with my problem with my code Thank you
-
so confused my mtag won't upload to mySQL, however when i put information into mysql manually and come back to the page it will echo it some one help me, all the others work just not this 1 yyyyyyyyyyyyy <?php // Connect to the MySQL database include "../storescripts/connect_to_mysql.php"; exit(); ?> <?php // Script Error Reporting error_reporting(E_ALL); ini_set('display_errors', '1'); ?> <?php // Parse the form data and add inventory item to the system if (isset($_POST['product_name'])) { $pid = mysql_real_escape_string($_POST['thisID']); $product_name = mysql_real_escape_string($_POST['product_name']); $price = mysql_real_escape_string($_POST['price']); $category = mysql_real_escape_string($_POST['category']); $subcategory = mysql_real_escape_string($_POST['subcategory']); $details = mysql_real_escape_string($_POST['details']); $mtag = mysql_real_escape_string($_POST['mtag']); // See if that product name is an identical match to another product in the system $sql = mysql_query("UPDATE products SET product_name='$product_name', price='$price', details='$details', mtag='$mtag', category='$category', subcategory='$subcategory' WHERE id='$pid'"); if ($_FILES['fileField']['tmp_name'] != "") { // Place image in the folder $newname = "$pid.jpg"; move_uploaded_file($_FILES['fileField']['tmp_name'], "../inventory_images/$newname"); } header("location: inventory_list.php"); exit(); } ?> <?php // Gather this product's full information for inserting automatically into the edit form below on page if (isset($_GET['pid'])) { $targetID = $_GET['pid']; $sql = mysql_query("SELECT * FROM products WHERE id='$targetID' LIMIT 1"); $productCount = mysql_num_rows($sql); // count the output amount if ($productCount > 0) { while($row = mysql_fetch_array($sql)){ $product_name = $row["product_name"]; $price = $row["price"]; $category = $row["category"]; $subcategory = $row["subcategory"]; $details = $row["details"]; $mtag = $row["mtag"]; $date_added = strftime("%b %d, %Y", strtotime($row["date_added"])); } } else { echo "Sorry dude that crap dont exist."; exit(); } } ?> <?php // This block grabs the whole list for viewing $product_list = ""; $sql = mysql_query("SELECT * FROM products ORDER BY date_added DESC"); $productCount = mysql_num_rows($sql); // count the output amount if ($productCount > 0) { while($row = mysql_fetch_array($sql)){ $id = $row["id"]; $product_name = $row["product_name"]; $price = $row["price"]; $date_added = strftime("%b %d, %Y", strtotime($row["date_added"])); $product_list .= "Product ID: $id - <strong>$product_name</strong> - £$price - <em>Added $date_added</em> <a href='inventory_edit.php?pid=$id'>edit</a> • <a href='inventory_list.php?deleteid=$id'>delete</a><br />"; } } else { $product_list = "You have no products listed in your store yet"; } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Inventory List</title> <link rel="stylesheet" href="../style/style.css" type="text/css" media="screen" /> </head> <body> <div align="center" id="mainWrapper"> <?php include_once("../template_header.php");?> <div id="pageContent"><br /> <div align="right" style="margin-right:32px;"><a href="inventory_list.php#inventoryForm">+ Add New Inventory Item</a></div> <div align="left" style="margin-left:24px;"> <h2>Inventory list</h2> <?php echo $product_list; ?></div> <hr /> <a name="inventoryForm" id="inventoryForm"></a> <h3> ↓ Add New Inventory Item Form ↓ </h3> <form action="inventory_edit.php" enctype="multipart/form-data" name="myForm" id="myform" method="post"> <table width="90%" border="0" cellspacing="0" cellpadding="6"> <tr> <td width="20%" align="right">Product Name</td> <td width="80%" align="left"><label> <input name="product_name" type="text" id="product_name" size="64" value="<?php echo $product_name; ?>" /> </label></td> </tr> <tr> <td align="right">Product Price</td> <td align="left"><label> £ <input name="price" type="text" id="price" size="12" value="<?php echo $price; ?>" /> </label></td> </tr> <tr> <td align="right">Category</td> <td align="left"><label> <select name="category" id="category"> <option value="Clothing">Clothing</option> </select> </label></td> </tr> <tr> <td align="right">Subcategory</td> <td align="left"><select name="subcategory" id="subcategory"> <option value="<?php echo $subcategory; ?>"><?php echo $subcategory; ?></option> <option value="Hats">Hats</option> <option value="Pants">Pants</option> <option value="Shirts">Shirts</option> </select></td> </tr> <tr> <td align="right">Product Details</td> <td align="left"><label> <textarea name="details" id="details" cols="64" rows="5"><?php echo $details; ?></textarea> </label></td> </tr> <tr> <td align="right">Product Image</td> <td align="left"><label> <input type="file" name="fileField" id="fileField" /> </label></td> </tr> <tr> <td align="right">Meta Tag</td> <td align="left"><label> <textarea name="mtag" id="mtag" cols="64" rows="5"><?php echo $mtag; ?></textarea> </label></td> </tr> <tr> <td> </td> <td><label> <input name="thisID" type="hidden" value="<?php echo $targetID; ?>" /> <input type="submit" name="button" id="button" value="Make Changes" /> </label></td> </tr> </table> </form> <br /> <br /> </div> <?php include_once("../template_footer.php");?> </div> </body> </html> when i enter values inside my mtag in mysql they render back, but when i use the forum to upload to mysql doesnt work please please please help i know its something small im over looking but ive been over it and over it and can't spot it MOD EDIT: . . . BBCode tags added.