PHP Problem !

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
gopinathd
Forum Newbie
Posts: 8
Joined: Thu Nov 13, 2003 1:54 am

PHP Problem !

Post 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
:(
Paddy
Forum Contributor
Posts: 244
Joined: Wed Jun 11, 2003 8:16 pm
Location: Hobart, Tas, Aussie
Contact:

Post 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

Code: Select all

$st="GOPINATH'S";
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. :)
gopinathd
Forum Newbie
Posts: 8
Joined: Thu Nov 13, 2003 1:54 am

Post 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.
Paddy
Forum Contributor
Posts: 244
Joined: Wed Jun 11, 2003 8:16 pm
Location: Hobart, Tas, Aussie
Contact:

Post by Paddy »

Can you tell us what is on line 8 and 9?
gopinathd
Forum Newbie
Posts: 8
Joined: Thu Nov 13, 2003 1:54 am

Post 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
Paddy
Forum Contributor
Posts: 244
Joined: Wed Jun 11, 2003 8:16 pm
Location: Hobart, Tas, Aussie
Contact:

Post by Paddy »

It is to do with your database connectivity. I am unable to help you there. Perhaps someone else can.
d3ad1ysp0rk
Forum Donator
Posts: 1661
Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA

Post 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
gopinathd
Forum Newbie
Posts: 8
Joined: Thu Nov 13, 2003 1:54 am

Post 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
Paddy
Forum Contributor
Posts: 244
Joined: Wed Jun 11, 2003 8:16 pm
Location: Hobart, Tas, Aussie
Contact:

Post by Paddy »

Interesting, but echoing this

echo("It's working");

echoes

It's working
Post Reply