haris244808 Posted August 7, 2011 Share Posted August 7, 2011 i did a form that will add my informations to database but i am facing with these problems when ipress the submit button(i uploaded also as picture you can see it down): Warning: include(../storescripts/connect_to_mysql.php) [function.include]: failed to open stream: No such file or directory in C:\xampp\htdocs\html\upload_form.php on line 10 Warning: include() [function.include]: Failed opening '../storescripts/connect_to_mysql.php' for inclusion (include_path='.;C:\xampp\php\PEAR') in C:\xampp\htdocs\html\upload_form.php on line 10 Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\html\upload_form.php on line 13 No database selected here is my upload_form.php <?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']); include "../storescripts/connect_to_mysql.php"; // 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())") 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: upload_form.php"); exit(); } ?> <!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>qwerty</title> <link rel="stylesheet" href="css/style.css" type="text/css" media="all" /> <!--[if lte IE 6]><link rel="stylesheet" href="css/ie6.css" type="text/css" media="all" /><![endif]--> <!--[if IE]><style type="text/css" media="screen"> #navigation ul li a em { top:32px; } </style><![endif]--> </head> <body> <form action="upload_form.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%"><label> <input name="product_name" type="text" id="product_name" size="64" /> </label></td> </tr> <tr> <td align="right">Product Price</td> <td><label> $ <input name="price" type="text" id="price" size="12" /> </label></td> </tr> <tr> <td align="right">Category</td> <td><label> <select name="category" id="category"> <option value="Clothing">Clothing</option> </select> </label></td> </tr> <tr> <td align="right">Subcategory</td> <td><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><label> <textarea name="details" id="details" cols="64" rows="5"></textarea> </label></td> </tr> <tr> <td align="right">Product Image</td> <td><label> <input type="file" name="fileField" id="fileField" /> </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> </body> </html> connect_to_mysql.php: <?php $db_host="localhost"; $db_username="root"; $db_pass=""; $db_name="database_web"; mysql_connect("$db_host","$db_username","$db_pass") or die ("Nuk mund te lidhet me databazen"); mysql_select_db("$db_name") or die ("Nuk ka databaze"); ?> and here is the sql code for the table products that i created: "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, PRIMARY KEY (id), UNIQUE KEY product_name (product_name) ) "; How to fix this. I want to add my informations to the form then add those to database [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/244128-need-help/ Share on other sites More sharing options...
ZulfadlyAshBurn Posted August 7, 2011 Share Posted August 7, 2011 please check that the connect_to_mysql.php is located at the correct place. Quote Link to comment https://forums.phpfreaks.com/topic/244128-need-help/#findComment-1253770 Share on other sites More sharing options...
haris244808 Posted August 7, 2011 Author Share Posted August 7, 2011 please check that the connect_to_mysql.php is located at the correct place. i took out the include part and now it shows this error: (i am tired of this error) Warning: mysql_numrows() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\html\upload_form.php on line 13 No database selected Quote Link to comment https://forums.phpfreaks.com/topic/244128-need-help/#findComment-1253774 Share on other sites More sharing options...
ZulfadlyAshBurn Posted August 7, 2011 Share Posted August 7, 2011 Firstly, without the connect_to_mysql.php, its not going to connect to the mySQL server. secondly, change your connect_to_mysql.php to this. <?php //connect to server $con = mysql_connect("localhost","root","root"); if (!$con) { die('Nuk mund te lidhet me databazen ' . mysql_error()); } // select database mysql_select_db("database_web", $con) or die ("Nuk ka databaze"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/244128-need-help/#findComment-1253775 Share on other sites More sharing options...
haris244808 Posted August 7, 2011 Author Share Posted August 7, 2011 Firstly, without the connect_to_mysql.php, its not going to connect to the mySQL server. secondly, change your connect_to_mysql.php to this. <?php //connect to server $con = mysql_connect("localhost","root","root"); if (!$con) { die('Nuk mund te lidhet me databazen ' . mysql_error()); } // select database mysql_select_db("database_web", $con) or die ("Nuk ka databaze"); ?> same error. I tried to echi the error too. It says Query was empty Quote Link to comment https://forums.phpfreaks.com/topic/244128-need-help/#findComment-1253779 Share on other sites More sharing options...
ZulfadlyAshBurn Posted August 7, 2011 Share Posted August 7, 2011 sorry my bad, change it to this script. the previous script, i added root as the password <?php //connect to server $con = mysql_connect("localhost","root",""); if (!$con) { die('Nuk mund te lidhet me databazen ' . mysql_error()); } // select database mysql_select_db("database_web", $con) or die ("Nuk ka databaze"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/244128-need-help/#findComment-1253780 Share on other sites More sharing options...
haris244808 Posted August 7, 2011 Author Share Posted August 7, 2011 sorry my bad, change it to this script. the previous script, i added root as the password <?php //connect to server $con = mysql_connect("localhost","root",""); if (!$con) { die('Nuk mund te lidhet me databazen ' . mysql_error()); } // select database mysql_select_db("database_web", $con) or die ("Nuk ka databaze"); ?> yes yes i saw that .. the problem is when i try with include (ex. i have the connect_to_mysql another folder and i want this page to only include) when i do this with include doesnt work, but when i write the connection to database code directly to the page it works. so how should i include : my connect_to_mysql.php page is in the same place with this other one but inside a folder called storescripts. so how do i include this connect_to_mysql.pph page to this other page(upload page) Quote Link to comment https://forums.phpfreaks.com/topic/244128-need-help/#findComment-1253781 Share on other sites More sharing options...
ZulfadlyAshBurn Posted August 7, 2011 Share Posted August 7, 2011 can you list how is your folder structured? eg www -index.php www/storescripts -connect_to_mysql.php Quote Link to comment https://forums.phpfreaks.com/topic/244128-need-help/#findComment-1253787 Share on other sites More sharing options...
haris244808 Posted August 7, 2011 Author Share Posted August 7, 2011 can you list how is your folder structured? eg www -index.php www/storescripts -connect_to_mysql.php thank you man but i solved. should have included with require (hahaha what a mistake) thanks again Quote Link to comment https://forums.phpfreaks.com/topic/244128-need-help/#findComment-1253788 Share on other sites More sharing options...
ZulfadlyAshBurn Posted August 7, 2011 Share Posted August 7, 2011 haha. no prob Quote Link to comment https://forums.phpfreaks.com/topic/244128-need-help/#findComment-1253789 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.