Hi,

I was trying to import the excel values in mysql DB. While trying, am facing this error. Please help me out:

Fatal error: Call to undefined function mysql_real_espace_string() in E:\xampp\htdocs\read.php on line 49

CODING:

<?php
ini_set('memory_limit', '16M');
set_time_limit(0);
require_once("E:/xampp/htdocs/phpexcel/Classes/PHPExcel.php");

$inputFileName='./xls/test_data.xls';

/** Identify the type of  $inputFileName **/
$inputFileType=PHPExcel_IOFactory::identify($inputFileName);

/** Create a new reader of the type that has been identified **/
$objReader=PHPExcel_IOFactory::createReader($inputFileType);

/**Load $inputFileName to a PHPExcel object **/
$objPHPExcel=$objReader->load($inputFileName);

/**Get the calculated value from a cell**/
$worksheet='Worksheet';

#$cell='A1';
/**Get a normal value from a cell **/
#$cellValue=$objPHPExcel->getSheetByName($worksheet)->getCell($cell)->getCalculatedValue();

$worksheet=$objPHPExcel->getActiveSheet();

$highestRow = $worksheet->getHighestRow(); 
$highestColumn = $worksheet->getHighestColumn(); 

$highestColumnIndex = PHPExcel_Cell::columnIndexFromString($highestColumn); 


$myServer = "local";
	$myUser = "zzzz";
	$myPass = "yyyy";
	$myDB = "xxxx"; 
	
	//connection to the database
	$dbhandle = mysql_connect($myServer, $myUser, $myPass) or die("Couldn't connect to SQL Server on $myServer");
  
    //select a database to work with
	$selected = mysql_select_db($myDB, $dbhandle)	or die("Couldn't open database $myDB");
    

$row = array();
for ($row = 1; $row <= $highestRow; ++$row) 
{
  for ($col = 0; $col <= $highestColumnIndex; ++$col) 
  {
    $row[$col] = mysql_real_espace_string($worksheet->getCellByColumnAndRow($col, $row)->getValue());
  }

    mysql_query("INSERT INTO test (name,hours) VALUES ($row[1],$row[2])") or die("can't insert");
}

?>

Thanks....

because you have a typo in the function and the correct one is

<?php mysql_real_escape_sting()?>

hi,

can't understand. Please could me explain it briefly.

lol not mysql_real_escape_sting, but mysql_real_escape_string
those damn typos hahaha

LOL :D
that was very funny :D
as 54uydf said in replace line 49 in ur script with this line

$row[$col] = mysql_real_escape_string($worksheet->getCellByColumnAndRow($col, $row)->getValue());

thanks sp much guys.....

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.