Jump to content

Recommended Posts

hi

i have field that you can save address and it will insert into sql.

it is address field and i want to save tim's international. ( field with ' ) how can i do that?

 

and when i call back from server if i update the field still i need to save with '

 

can someone please help me

 

thanks

Link to comment
https://forums.phpfreaks.com/topic/128786-how-to-save-with/
Share on other sites

you could escape it with mysql_real_escape_string() that would turn ' into " or you could use str_replace();something like this

$string = "test ' string";
$string = str_replace("'","|||",$string);

then when you pull data out you need to

$string = str_replace("|||","'",$string);

 

Scott.

 

Link to comment
https://forums.phpfreaks.com/topic/128786-how-to-save-with/#findComment-667652
Share on other sites

i tried to use this function

function escape_string($str) {

if ($str !== null) {

$str = str_replace(array('\\','\''),array('\\\\','\\\''),$str);

$str = "'".$str."'";

} else {

$str = "null";

}

 

return strtoupper($str);

}

 

im inserting data into sql like  ,'".$_SESSION['dco']."',

,'".$_SESSION['dadd1']."','".$_SESSION['dadd2']."',

 

 

but then when open modification page and when i click  save button im gettingthis error

 

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'p 1/2 MARCO'l AVE', 'matt', '3.0', '3.000', '3')' at line 1

 

please advice

Link to comment
https://forums.phpfreaks.com/topic/128786-how-to-save-with/#findComment-667659
Share on other sites

this is where i add - adding.php page

 

<?php
$sql = "INSERT INTO addr (TO_LOC, TO_DET1, TO_DET2, TO_DET3) VALUES (";
$sql .= $_SESSION['dsuburb']."', '".$_SESSION['dcomp']."', '".mysql_real_escape_string($_SESSION['dadd1'])."', '".$_SESSION['dadd2']. "')"; 

--------modify.php  -when i click that i can see all the data i entered from adding.php
$sql = "SELECT * FROM addr WHERE JOB_NO = ".$id;
//echo $sql;
$db->query($sql);

if ($row = $db->next_record()) {
$_SESSION['audit'] = $row;
$_SESSION['dsuburb'] = $row['TO_LOC'];
$_SESSION['dcomp'] = $row['TO_DET1'];
$_SESSION['dadd1'] = $row['TO_DET2'];
$_SESSION['dadd2'] = $row['TO_DET3'];
}

if want to update i will use this


$sql = "UPDATE addr SET ";

$sql .= ", TO_LOC = '".$_SESSION['dsuburb']."'";
$sql .= ", TO_DET1 = '".$_SESSION['dcomp']."'";
$sql .= ", TO_DET2 = '".mysql_real_escape_string($_SESSION['dadd1'])."'";
$sql .= ", TO_DET3 = '".$_SESSION['dadd2']."'";

$sql .= " WHERE JOB_NO = ".$_SESSION['jobno'];
?>

 

when i add mysql_real_escape_string()

it si working fine. but when i do update something click save then add / to dadd1 field.

eg.VICTORIA\\\'L RD

 

how can i stop that

 

Link to comment
https://forums.phpfreaks.com/topic/128786-how-to-save-with/#findComment-667669
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.