alpha1 Posted November 12, 2011 Share Posted November 12, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/251011-so-confused-my-mtag-wont-upload-to-mysql/ Share on other sites More sharing options...
Pikachu2000 Posted November 12, 2011 Share Posted November 12, 2011 When posting code, enclose it within the forum's . . . BBCode tags. Quote Link to comment https://forums.phpfreaks.com/topic/251011-so-confused-my-mtag-wont-upload-to-mysql/#findComment-1287703 Share on other sites More sharing options...
alpha1 Posted November 13, 2011 Author Share Posted November 13, 2011 Oh sorry it was my first comment, I didn't know. Any advice with my problem with my code Thank you Quote Link to comment https://forums.phpfreaks.com/topic/251011-so-confused-my-mtag-wont-upload-to-mysql/#findComment-1287722 Share on other sites More sharing options...
alpha1 Posted November 13, 2011 Author Share Posted November 13, 2011 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> Quote Link to comment https://forums.phpfreaks.com/topic/251011-so-confused-my-mtag-wont-upload-to-mysql/#findComment-1287845 Share on other sites More sharing options...
alpha1 Posted November 13, 2011 Author Share Posted November 13, 2011 <?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 Quote Link to comment https://forums.phpfreaks.com/topic/251011-so-confused-my-mtag-wont-upload-to-mysql/#findComment-1287847 Share on other sites More sharing options...
alpha1 Posted November 13, 2011 Author Share Posted November 13, 2011 p.s i changed teh mtag name in the daabase to m_tag also Quote Link to comment https://forums.phpfreaks.com/topic/251011-so-confused-my-mtag-wont-upload-to-mysql/#findComment-1287848 Share on other sites More sharing options...
Pikachu2000 Posted November 13, 2011 Share Posted November 13, 2011 Duplicate threads merged. Don't double post. As for your problem, look at how you've put the $m_tag variable into the query string, and what happened to NOW(). Quote Link to comment https://forums.phpfreaks.com/topic/251011-so-confused-my-mtag-wont-upload-to-mysql/#findComment-1287854 Share on other sites More sharing options...
alpha1 Posted November 13, 2011 Author Share Posted November 13, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/251011-so-confused-my-mtag-wont-upload-to-mysql/#findComment-1287867 Share on other sites More sharing options...
Pikachu2000 Posted November 13, 2011 Share Posted November 13, 2011 The query string looks fine, syntactically. Have you tried echoing the $m_tag variable immediately before the query execution to make sure it contains a value that you'd expect it to contain? Quote Link to comment https://forums.phpfreaks.com/topic/251011-so-confused-my-mtag-wont-upload-to-mysql/#findComment-1287870 Share on other sites More sharing options...
alpha1 Posted November 13, 2011 Author Share Posted November 13, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/251011-so-confused-my-mtag-wont-upload-to-mysql/#findComment-1287885 Share on other sites More sharing options...
alpha1 Posted November 13, 2011 Author Share Posted November 13, 2011 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 :'( Quote Link to comment https://forums.phpfreaks.com/topic/251011-so-confused-my-mtag-wont-upload-to-mysql/#findComment-1287888 Share on other sites More sharing options...
KevinM1 Posted November 14, 2011 Share Posted November 14, 2011 Comment out your query, i.e.: /*$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"); */ And literally echo out $m_tag to the screen: echo "m_tag is: $m_tag"; Do you see a value? Quote Link to comment https://forums.phpfreaks.com/topic/251011-so-confused-my-mtag-wont-upload-to-mysql/#findComment-1287974 Share on other sites More sharing options...
alpha1 Posted November 14, 2011 Author Share Posted November 14, 2011 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> Quote Link to comment https://forums.phpfreaks.com/topic/251011-so-confused-my-mtag-wont-upload-to-mysql/#findComment-1288127 Share on other sites More sharing options...
KevinM1 Posted November 14, 2011 Share Posted November 14, 2011 1. Do not create a new thread for the same problem. 2. Have you tried checking to see if $m_tag actually contains a value, as I suggested here: http://www.phpfreaks.com/forums/index.php?topic=347751.msg1641373#msg1641373 ? EDIT: Topics merged. Let's not do that again, eh? Quote Link to comment https://forums.phpfreaks.com/topic/251011-so-confused-my-mtag-wont-upload-to-mysql/#findComment-1288131 Share on other sites More sharing options...
alpha1 Posted November 14, 2011 Author Share Posted November 14, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/251011-so-confused-my-mtag-wont-upload-to-mysql/#findComment-1288157 Share on other sites More sharing options...
alpha1 Posted November 14, 2011 Author Share Posted November 14, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/251011-so-confused-my-mtag-wont-upload-to-mysql/#findComment-1288170 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.