• PHP Help PHP Coding
  • Warning: mysql_real_escape_string() expects parameter 1 to be string, array given

Hi:

This is the code I'm using


 <?php  require_once ("config.php");
			function error($msg) {
				global $message;
				$message = $msg;
				include "postad.php";
				die();
								}
			function error2($msg) {
				error("<font color=\"red\"><b><i>$msg</i></b></font>");
								  }
			function esc($data) {
				return mysql_real_escape_string($data);
								}
			function getesc($varname) {
				global $$varname;
				$$varname = isset($_POST[$varname])    ? esc($_POST[$varname])    : "";
				return $$varname;
										}					
			//Get data in local variable
			getesc('adype');
			getesc('cat');
			getesc('title');
			getesc('desc');
			getesc('price');
			getesc('country');
			getesc('region');
			getesc('city');
			getesc('area');
			getesc('address');

		// check for null values
		if ($adype=="Free") {
		if ($cat=="") error2("Please select a Category");
		if ($title=="") error2("Please enter a Title");
		if ($desc=="") error2("Please enter a Description");
		$price = 0;
							} 
		else {
			if ($cat=="") error2("Please enter a Category");
			if ($title=="") error2("Please enter a Title");
			if ($desc=="") error2("Please enter a Description");
			$price = $price;
			}
	// insert local variables into database
	$query = "INSERT INTO normalposts (adype, cat, title, desc, price, country, region, city, area, address) VALUES 
		('$adype','$cat','$title','$desc','$price','$country','$region','$city','$area','$address')";
	if (mysql_query($query)===FALSE) error2("Error inserting into the database.");

	else 	{
		// nothing to do, service seeker has no extra fields
			}			
						include "header.php";
?>
                <font color=blue>
                    <center>
                        <b><i>Your ad has been successfully posted and will appear online after it has passed moderation.</i></b>
                            <br /><br />
                              We wish you success.
                    </center>
                    <br />
                </font>
<?php
include "footer.php";
?>

This is the error I get

Warning: mysql_real_escape_string() expects parameter 1 to be string, array given in D:\Hosting\xxx\htmlaaa\postingsuccess.php on line 12

Please help .

Thanks

    The error message tells you what the problem is: [font=monospace]$esc[/font] (that's the only thing you are giving to [man]mysql_real_escape_string[/man]) needs to be a string. One of those POST variables you are giving it is an array.

      Write a Reply...