Reply to Re: Single quotes in MSSQL

Your name:

Reply:


Posted by nick.bonadies on 04/12/07 15:27

Toby A Inkster wrote:

>
> This means that the actual data in your database has two apostrophes. Fix
> that and you'll be sorted.

Here is some sample code:

$queryAddRecord = "INSERT INTO tbl_employees(firstName, lastName)
VALUES(";
if (!empty($_POST['firstName']))
{
$queryAddRecord .= "'".$_POST['firstName']."',";
}
else {$queryAddRecord .="Null,";}

if (!empty($_POST['lastName']))
{
$queryAddRecord .= '"'.str_replace("'", "''",
$_POST['lastName']).'",';
}
else {$queryAddRecord .="Null,";}
$dbresults = mssql_query($queryAddRecord);

So if you feed that Erin O'Brien, it inputs Erin for the first name
and O''Brien as the last name. Then when i call it back i use
something like this:

<?php
$queryFullTimeemployees = "SELECT firstName, lastName FROM
tbl_employees ORDER BY lastName ASC";
$dbFullTime = mssql_query($queryFullTimeemployees);
?>

then display the records:

<table>
<?php
// List the departments from the DB
//display the results
while($row = mssql_fetch_array($dbFullTime)){
$pageAddress = "employees_edit.php?id=".trim($row['id']);
echo "<tr>
<td>".trim($row['lastName'])."</td>
<td>".trim($row['firstName'])."</td>
</tr>" ;
}
?>
</table>

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация