co.ador Posted December 20, 2009 Share Posted December 20, 2009 <b>Warning</b>: mysql_real_escape_string() expects parameter 1 to be string, array given in <b>C:\wamp\www\nyhungry\indexpagination.php</b> on line <b>12</b><br warning</b>: mysql_close(): supplied argument is not a valid MySQL-Link resource in <b>C:\wamp\www\nyhungry\classes\database.class.php</b> on line <b>86</b><b Link to comment https://forums.phpfreaks.com/topic/185809-two-warning-messages/ Share on other sites More sharing options...
merylvingien Posted December 20, 2009 Share Posted December 20, 2009 Are you requesting that all the forum members preform a séance where we could pool all our psychic powers to figure out your code? I am sure that we could try, now everyone, focus your minds... Link to comment https://forums.phpfreaks.com/topic/185809-two-warning-messages/#findComment-981117 Share on other sites More sharing options...
nafetski Posted December 20, 2009 Share Posted December 20, 2009 Well given those very detailed error messages, I don't even need to see the code to figure out what is causing your problem "mysql_real_escape_string() expects parameter 1 to be string, array given.." This happens when you try to pass an array of values to mysql_real_escape_string. It's not smart enough to do that...you have to iterate through your array first and escape each value independently What you are PROBABLY doing (wrong) <?php $data = mysql_real_escape_string($_POST); What you WANT to be doing foreach($_POST as $key=>$value){ $data[$key]=mysql_real_escape_string($value); } // Now your $data array will be your escaped form data and you can perform your inserts /updates based off of that. The second error is another easy one to remedy. Chances are that something failed in your database insert (due to the characters not being escaped properly) and the connection closed. If there is no mysql connection open, then there is no mysql connection to close If you ARE successfully connecting to a database, I will be willing to wager that your code will work fine after you escape your data array properly. Good luck - let me know if I hit the nail on the head Link to comment https://forums.phpfreaks.com/topic/185809-two-warning-messages/#findComment-981119 Share on other sites More sharing options...
co.ador Posted December 21, 2009 Author Share Posted December 21, 2009 hey nafeski thorpe has helped me to properly iterate the extraction of the indexes as you suggested to poperly escape the value with mysql_real_query_string function. <?php $data = array();foreach ($_REQUEST['frmSearch']['food_types'] as $foodtypes) { $data[] = mysql_real_escape_string($foodtypes);} ?> and for offerings index as well <?php $data = array();foreach ($_REQUEST['frmSearch']['offerings'] as $arrOfferings) { $data[] = mysql_real_escape_string($arrOfferings);} ?> But for the offerings index iterations it display the following warning and notice Notice: Undefined index: offerings in C:\wamp\www\nyhungry\indexpagination.php on line 16 Warning: Invalid argument supplied for foreach() in C:\wamp\www\nyhungry\indexpagination.php on line 16 if you don't mind you can go the following link where this topic is being discussed as well http://www.phpfreaks.com/forums/index.php/topic,281400.msg1333561.html#msg1333561 Link to comment https://forums.phpfreaks.com/topic/185809-two-warning-messages/#findComment-981387 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.