This topic is locked

ESCAPE HYPHEN " ' "

3/21/2012 2:35:04 PM
PHPRunner General questions
M
mune72 author

I did my own insert in same tables.
It fails when I try to insert a ' (hyphen).
Hot to escape a string? It should be pretty simple but haven't found a solution.
Thanks

C
cgphp 3/21/2012

Please, post the query.

M
mune72 author 3/25/2012



Please, post the query.


Sorry for this late answer, you was very promptly, thanks. I supposed an e-mail notification for new replies come in by default, but I learned that I have to ask for it in the first post.
Here is the code for "before record added" for the table "Add Page":

global $conn;
// next VERSAMENTI ID

$strSQL = "SELECT seq FROM sqlite_sequence WHERE name=\"VERSAMENTI\"";

$rs = db_query($strSQL, $conn);

while ($row = db_fetch_array($rs)) {

$versNextId = $row["seq"]+1;

$versNextId = "$versNextId";

//print("VERS NEXT ID: $versNextId");

}

$note = $values["NOTE"];

if ($note=="")

$strSQLInsert = "INSERT INTO VERSAMENTI (ID, DATA_V, VERSAMENTO, MESE) values ($versNextId , \"".$values["DATA_V"]."\", ".$values["VERSAMENTO"].", ".$values["MESE"].")";

else

$strSQLInsert = "INSERT INTO VERSAMENTI (ID, DATA_V, VERSAMENTO, MESE, NOTE) values ($versNextId , \"".$values["DATA_V"]."\", ".$values["VERSAMENTO"].", ".$values["MESE"].", \"$note\")";
//print "
strSQLInsert = $strSQLInsert <BR>";
db_exec($strSQLInsert,$conn);
$newValues = array("CORSO_ID"=>$values["CORSO_ID"], "SOCIO_ID"=>$values["SOCIO_ID"], "VERS_ID"=>$versNextId);
/*print "<BR>";

var_dump($newValues);

print "<BR>;";

var_dump($values);

print "<BR>;";*/
$values = $newValues;
return true;
C
cgphp 3/25/2012
global $conn;
// next VERSAMENTI ID

$strSQL = "SELECT seq FROM sqlite_sequence WHERE name='VERSAMENTI'";

$rs = db_query($strSQL, $conn);

while ($row = db_fetch_array($rs)) {

$versNextId = $row["seq"]+1;

$versNextId = "$versNextId";

//print("VERS NEXT ID: $versNextId");

}

$note = $values["NOTE"];

if ($note=="")

$strSQLInsert = "INSERT INTO VERSAMENTI (ID, DATA_V, VERSAMENTO, MESE) values ($versNextId , '".$values["DATA_V"]."', ".$values["VERSAMENTO"].", ".$values["MESE"].")";

else

$strSQLInsert = "INSERT INTO VERSAMENTI (ID, DATA_V, VERSAMENTO, MESE, NOTE) values ($versNextId , '".$values["DATA_V"]."', ".$values["VERSAMENTO"].", ".$values["MESE"].", '".$note."')";
//print "
strSQLInsert = $strSQLInsert <BR>";
db_exec($strSQLInsert,$conn);
$newValues = array("CORSO_ID"=>$values["CORSO_ID"], "SOCIO_ID"=>$values["SOCIO_ID"], "VERS_ID"=>$versNextId);
/*print "<BR>";

var_dump($newValues);

print "<BR>;";

var_dump($values);

print "<BR>;";*/
$values = $newValues;
return true;