Page 1 of 1
PHP Problem !
Posted: Thu Nov 13, 2003 1:54 am
by gopinathd
Hi all,
I have got a problem in using Insert Query.
Here is Insert SQL query
<?php
$st="GOPINATH'S';
$sql="Insert into emp_tab values(12,$st)";
..
..
..
?>
In the above program, String itself contains Single quote ('). If i try to execute
the above query, I got the error message stating that 'String not properly terminated'
How to use single quote in SQL Query?
I got the same proble in Select query as well.
Give the solution to the above mentioned problems.
Thanks in advance.
Gopi

Posted: Thu Nov 13, 2003 2:35 am
by Paddy
The problem you have in the $st string is that it needs to be enclosed in a double quote, not a single one. So the correct code would be
Your next problem is that you have not properly concatenated the string and the variables together. To do this you must place a full stop between them. Also, because $st is a string a single quote must go around the variable for the insertion to work. For instance
Code: Select all
$sql="Insert into emp_tab values(12,'".$st."')";
Please note that the single quotes are on the outside of the double quotes. Doesn't turn up too well between the php tags.

Posted: Thu Nov 13, 2003 9:52 pm
by gopinathd
<?php
$st="Gopin'ath";
$sql="insert into test1 values(10,'".$st."')";
$user="milky";
$pass="milky";
$servicename="DSMKMS";
$conn=ocilogon($user,$pass,$servicename);
$stmt=ociparse($conn,$sql);
ociexecute($stmt);
?>
I got the following error message when i executed the above mentioned program.
Warning: OCIParse: ORA-01756: quoted string not properly terminated in c:\program files\apache group\apache\htdocs\dms\dialog\georef\segregation\test1.php on line 8
Warning: Supplied argument is not a valid OCI8-Statement resource in c:\program files\apache group\apache\htdocs\dms\dialog\georef\segregation\test1.php on line 9
Your immediate replay will make me glad.
Posted: Thu Nov 13, 2003 9:57 pm
by Paddy
Can you tell us what is on line 8 and 9?
Posted: Thu Nov 13, 2003 10:03 pm
by gopinathd
1<?php
2 $st="Gopin'ath";
3 $sql="insert into test1 values(10,'".$st."')";
4 $user="milky";
5 $pass="milky";
6 $servicename="DSMKMS";
7 $conn=ocilogon($user,$pass,$servicename);
8 $stmt=ociparse($conn,$sql);
9 ociexecute($stmt);
?>
I got the following error message when i executed the above mentioned program.
Warning: OCIParse: ORA-01756: quoted string not properly terminated in c:\program files\apache group\apache\htdocs\dms\dialog\georef\segregation\test1.php on line 8
Warning: Supplied argument is not a valid OCI8-Statement resource in c:\program files\apache group\apache\htdocs\dms\dialog\georef\segregation\test1.php on line 9
I am not able to insert the record into the db
Posted: Thu Nov 13, 2003 10:11 pm
by Paddy
It is to do with your database connectivity. I am unable to help you there. Perhaps someone else can.
Posted: Thu Nov 13, 2003 10:14 pm
by d3ad1ysp0rk
2 $st="Gopin'ath";
makes
3 $sql="insert into test1 values(10,'".$st."')";
this:
$sql="insert into test1 values(10,'"Gopin'ath'")"; and the ' in Gopin ath ends the SQL statement, giving you:
quoted string not properly terminated
Posted: Thu Nov 13, 2003 10:17 pm
by gopinathd
Single quote (') will come in variable $st sometimes. In such a case, Query should accept that one also.
Is there any way to store the string "Gopin'ath" into the database?
Regards,
Gopi
Posted: Thu Nov 13, 2003 10:18 pm
by Paddy
Interesting, but echoing this
echo("It's working");
echoes
It's working