Jump to content

Two warning messages


co.ador

Recommended Posts

<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

Well given those very detailed error messages, I don't even need to see the code to figure out what is causing your problem :P

 

"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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.