Page 1 of 1

Error while inserting values to database

Posted: Tue Oct 05, 2010 9:59 am
by faizpayi
Hi,

I have created a page which will take ask for certain details and those details will be added to the database(MS SQL SERVER 2008).

But when I press submit the following error code is displayed

00sadfsfad23sdfasdfasdfasd1Error in executing query.
Array ( [0] => Array ( [0] => 42000 [SQLSTATE] => 42000 [1] => 8114

Code: Select all

 => 8114 [2] => [Microsoft][SQL Server Native Client 10.0][SQL Server]Error converting data type varchar to numeric. [message] => [Microsoft][SQL Server Native Client 10.0][SQL Server]Error converting data type varchar to numeric. ) ) 

it says that there is some error while converting varchar to numeric.All values are taken with a textbox and the values i have given is correct.Please find a solution for this

Thanks in advance

Faiz

Re: Error while inserting values to database

Posted: Tue Oct 05, 2010 10:06 am
by internet-solution
If you share your code, then it will be easier to debug the issue.

Re: Error while inserting values to database

Posted: Tue Oct 05, 2010 10:18 am
by faizpayi
The values are taken from adding employee.php and on submit the values will be posted to addemp.php.Below is the code for addemp.php


Code: Select all

[b][u]addemp.php[/u][/b]

<?php include("connect.php"); ?> //connecting to the database


<?php
$FN = $_REQUEST["fname"];
$MN = $_REQUEST["mname"];
$LN = $_REQUEST["lname"];
$SC = $_REQUEST["smucode"];
$DN = $_REQUEST["deptname"];
$SN = $_REQUEST["supno"];
$JS = $_REQUEST["jobstat"];
$D = $_REQUEST["desig"];
$G = $_REQUEST["grade"];
$DOJ = isset($_REQUEST["date5"]) ? $_REQUEST["date5"] : "";
$DOB = isset($_REQUEST["date6"]) ? $_REQUEST["date6"] : "";
$DOR = isset($_REQUEST["date7"]) ? $_REQUEST["date7"] : "";
$LPD = $_REQUEST["lastpromdate"];
$TA = $_REQUEST["tempadd"];
$PA = $_REQUEST["permadd"];
$PN = $_REQUEST["phno"];
$EO = $_REQUEST["emailoff"];
$EQ = $_REQUEST["eduqual"];
$ER = $_REQUEST["exprev"];
$EN = $maxemp;







$tsql = "INSERT INTO tb_employees (emp_no,
emp_fname,
emp_mname,
emp_lname,
smu_code,
super_no,
emp_dob,
emp_doj,
emp_dor,
emp_job_status,
desig,
grade,
temp_addr,
perm_addr,
emp_phno,
email_off,
edu_qual,
exp_rev_no)
VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";

$params=array($EN,$FN,$MN,$LN,$SC,$DOB,$DOJ,$DOR,$SN,$JS,$D,$G,$TA,$PA,$PN,$EO,$EQ,$ER);

$stmt = sqlsrv_query( $conn, $tsql,$params);

//$stmt = sqlsrv_query( $conn, $tsql,$params);emp_doj,emp_dob,emp_dor,,$DOJ,$DOB,$DOR


if( $stmt === false )
{
     echo "Error in executing query.</br>";
     die( print_r( sqlsrv_errors(), true));
}



else
{
     echo "The query was successfully executed.";
}


sqlsrv_free_stmt( $stmt);
sqlsrv_close( $conn);

?>

Re: Error while inserting values to database

Posted: Tue Oct 05, 2010 10:51 am
by internet-solution
Whats in your sqlsrv_query() function?

Is this functio adding single quotes (') around all the values passed via $params array? If so, your numeric values are being treated as stirng by MSSQL server and you are getting this error.

Re: Error while inserting values to database

Posted: Wed Oct 06, 2010 3:23 am
by faizpayi
Hi,

Thanks for the help.So is there any other way to insert as numeric itself..??