radiations3 Posted August 10, 2011 Share Posted August 10, 2011 I am using following code to submit my record but when click on insert record i receive following error messages Notice: Undefined index: image in D:\WEB MAKING\DEALSMELA\untitled.php on line 39 Warning: file_get_contents() [function.file-get-contents]: Filename cannot be empty in D:\WEB MAKING\DEALSMELA\untitled.php on line 39 Kindly help (is there anything wrong with my code?) <form action="insert.php" method="post" name="form1" id="form1"> <table align="center"> <tr valign="baseline"> <td nowrap="nowrap" align="right">Company_name:</td> <td><input type="text" name="company_name" value="" size="32" /></td> </tr> <tr valign="baseline"> <td nowrap="nowrap" align="right">City:</td> <td><input type="text" name="city" value="" size="32" /></td> </tr> <tr valign="baseline"> <td nowrap="nowrap" align="right">Max_counter:</td> <td><input type="text" name="max_counter" value="" size="32" /></td> </tr> <tr valign="baseline"> <td nowrap="nowrap" align="right">Start_date:</td> <td><input type="text" name="start_date" value="" size="32" /></td> </tr> <tr valign="baseline"> <td nowrap="nowrap" align="right">End_date:</td> <td><input type="text" name="end_date" value="" size="32" /></td> </tr> <tr valign="baseline"> <td nowrap="nowrap" align="right">Original_price:</td> <td><input type="text" name="original_price" value="" size="32" /></td> </tr> <tr valign="baseline"> <td nowrap="nowrap" align="right">Suggested_price:</td> <td><input type="text" name="suggested_price" value="" size="32" /></td> </tr> <tr valign="baseline"> <td nowrap="nowrap" align="right">Discount:</td> <td><input type="text" name="discount" value="" size="32" /></td> </tr> <tr valign="baseline"> <td nowrap="nowrap" align="right">Description:</td> <td><input type="text" name="description" value="" size="32" /></td> </tr> <tr valign="baseline"> <td nowrap="nowrap" align="right">Status:</td> <td><input type="text" name="status" value="" size="32" /></td> </tr> <tr valign="baseline"> <td nowrap="nowrap" align="right">Dealtype:</td> <td><input type="text" name="dealtype" value="" size="32" /></td> </tr> <tr valign="baseline"> <td nowrap="nowrap" align="right">Detail:</td> <td><input type="text" name="detail" value="" size="32" /></td> </tr> <tr valign="baseline"> <td nowrap="nowrap" align="right">Image:</td> <td><label for="button"></label> <input type="file" name="image" /></td> </tr> <tr valign="baseline"> <td nowrap="nowrap" align="right">Buyscount:</td> <td><input type="text" name="buyscount" value="" size="32" /></td> </tr> <tr valign="baseline"> <td nowrap="nowrap" align="right"> </td> <td><input type="submit" value="Insert record" /></td> </tr> </table> <input type="hidden" name="MM_insert" value="form1" /> </form> Insert.php <?php require_once('Connections/deal.php'); ?> <?php $name = addslashes(file_get_contents($_FILES['image']['tmp_name'])); echo $name; // checking the image crapy values $insertSQL = mysql_query("INSERT INTO `deals` VALUES (company_name, city, max_counter, start_date, end_date, original_price, suggested_price, discount, `description`, status, dealtype, detail, image, buyscount) ('$_POST[company_name]' , '$_POST[city]' , '$_POST[max_counter]' ,'$_POST[start_date]' ,'$_POST[end_date]', '$_POST[original_price]', '$_POST[suggested_price]', '$_POST[discount]','$_POST[description]','$_POST[status]', '$_POST[dealtype]', '$_POST[detail]', '$name', '$_POST[buyscount]')"); mysql_select_db($database_deal, $deal); $Result1 = mysql_query($insertSQL, $deal) ; ?> Link to comment https://forums.phpfreaks.com/topic/244407-problem-with-insertion-need-help/ Share on other sites More sharing options...
PFMaBiSmAd Posted August 10, 2011 Share Posted August 10, 2011 Your <form ...> tag does not have the necessary enctype= attribute that would allow the form to upload a file. Have you read the upload handling section in the php documentation so that you would know the requirements to get this to work - http://md.php.net/manual/en/features.file-upload.php Link to comment https://forums.phpfreaks.com/topic/244407-problem-with-insertion-need-help/#findComment-1255289 Share on other sites More sharing options...
radiations3 Posted August 10, 2011 Author Share Posted August 10, 2011 Exactly that was the problem but one last error now when i click on submit i got the error "Query was empty" kindly check the following query is there something wrong with it??? $insertSQL = mysql_query("INSERT INTO `deals` VALUES (company_name, city, max_counter, start_date, end_date, original_price, suggested_price, discount, `description`, status, dealtype, detail, image, buyscount) ('$_POST[company_name]' , '$_POST[city]' , '$_POST[max_counter]' ,'$_POST[start_date]' ,'$_POST[end_date]', '$_POST[original_price]', '$_POST[suggested_price]', '$_POST[discount]','$_POST[description]','$_POST[status]', '$_POST[dealtype]', '$_POST[detail]', '$name', '$_POST[buyscount]')"); $name is getting the image. Link to comment https://forums.phpfreaks.com/topic/244407-problem-with-insertion-need-help/#findComment-1255303 Share on other sites More sharing options...
PFMaBiSmAd Posted August 10, 2011 Share Posted August 10, 2011 The "Query is empty" error is coming from the OTHER mysql_query() statement in your code. Why do you have a second mysql_query() statement that is trying to use $insertSQL as a sql query statement ($insertSQL is not a sql query statement.) Link to comment https://forums.phpfreaks.com/topic/244407-problem-with-insertion-need-help/#findComment-1255314 Share on other sites More sharing options...
radiations3 Posted August 10, 2011 Author Share Posted August 10, 2011 The "Query is empty" error is coming from the OTHER mysql_query() statement in your code. Why do you have a second mysql_query() statement that is trying to use $insertSQL as a sql query statement ($insertSQL is not a sql query statement.) $insertSQL is getting the insert command where as other is getting this command from $insert and saving it into my database i made previously all of my insertions just like this but i got stuck this time Is the something wrong with my query? Link to comment https://forums.phpfreaks.com/topic/244407-problem-with-insertion-need-help/#findComment-1255328 Share on other sites More sharing options...
PFMaBiSmAd Posted August 10, 2011 Share Posted August 10, 2011 I recommend that you re-read those three lines of your code a few more times. They are not doing what you think they are and they are also not what you previously used that worked. 1) You are executing a mysql_query() statement with an INSERT query, 2) You are selecting a database, 3) You are executing a second mysql_query() statement using a variable that is NOT an sql query statement, which produces the error you are getting. The query being given to the second msyql_query is EMPTY because the variable contains either a true or false value from the first mysql_query() statement. Link to comment https://forums.phpfreaks.com/topic/244407-problem-with-insertion-need-help/#findComment-1255337 Share on other sites More sharing options...
radiations3 Posted August 10, 2011 Author Share Posted August 10, 2011 LOLx i got my query worked still with the error if i put or die(mysql_error()); but if i don't put it its working perfectly(without even single data loss) I got the following error with or die(mysql_error()); : You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '1' at line 1 But without it i am getting perfect result don't know why MY FINAL CODE: $name = addslashes(file_get_contents($_FILES['image']['tmp_name'])); //echo $name; $insertSQL = mysql_query("INSERT INTO `deals` (company_name, city, max_counter, start_date, end_date, original_price, suggested_price, discount, `description`, status, dealtype, detail, image, buyscount) VALUES ('$_POST[company_name]' , '$_POST[city]' , '$_POST[max_counter]' ,'$_POST[start_date]' ,'$_POST[end_date]', '$_POST[original_price]', '$_POST[suggested_price]', '$_POST[discount]','$_POST[description]','$_POST[status]', '$_POST[dealtype]', '$_POST[detail]', '$name', '$_POST[buyscount]')"); mysql_select_db($database_deal, $deal); $Result1 = mysql_query($insertSQL, $deal); Thanx alot PFMaBiSmAd Link to comment https://forums.phpfreaks.com/topic/244407-problem-with-insertion-need-help/#findComment-1255351 Share on other sites More sharing options...
radiations3 Posted August 10, 2011 Author Share Posted August 10, 2011 Following code is working perfectly without an error: $name = addslashes(file_get_contents($_FILES['image']['tmp_name'])); $insertSQL = sprintf("INSERT INTO deals (company_name, city, max_counter, start_date, end_date, original_price, suggested_price, discount, `description`, status, dealtype, detail, image, buyscount) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)", GetSQLValueString($_POST['company_name'], "text"), GetSQLValueString($_POST['city'], "text"), GetSQLValueString($_POST['max_counter'], "text"), GetSQLValueString($_POST['start_date'], "text"), GetSQLValueString($_POST['end_date'], "text"), GetSQLValueString($_POST['original_price'], "text"), GetSQLValueString($_POST['suggested_price'], "text"), GetSQLValueString($_POST['discount'], "text"), GetSQLValueString($_POST['description'], "text"), GetSQLValueString($_POST['status'], "text"), GetSQLValueString($_POST['dealtype'], "text"), GetSQLValueString($_POST['detail'], "text"), GetSQLValueString($name, "text"), GetSQLValueString($_POST['buyscount'], "text")); mysql_select_db($database_deal, $deal); $Result1 = mysql_query($insertSQL, $deal) or die(mysql_error()); Link to comment https://forums.phpfreaks.com/topic/244407-problem-with-insertion-need-help/#findComment-1255354 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.