Jump to content

[SOLVED] The darn "&" sign in my database!


Recommended Posts

I have this code that pulls info from a database and displays it.

 

It works but it fails when it encounters the '&' sign in the database content.

 

Is there a way to look for the '&' sign and display it correctly.

 

 

<?php

$selectSql = "SELECT * FROM  Member".
'         WHERE  ID="'.addslashes($_GET['ID']).'" AND  createDate="'.addslashes($_GET['createDate']).'" AND  loginName="'.addslashes($_GET['loginName']).'" AND  password="'.addslashes($_GET['password']).'" AND  lastName="'.addslashes($_GET['lastName']).'" AND  firstName="'.addslashes($_GET['firstName']).'" AND  company="'.addslashes($_GET['company']).'" AND  title="'.addslashes($_GET['title']).'" AND  email="'.addslashes($_GET['email']).'" AND  phone="'.addslashes($_GET['phone']).'" AND  status="'.addslashes($_GET['status']).'" AND  dayCounter="'.addslashes($_GET['dayCounter']).'" AND  HowHear="'.addslashes($_GET['HowHear']).'"';

$Result    = $MyDb->f_ExecuteSql($selectSql);
$Resultset = $MyDb->f_GetRecord($Result);

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Detailed informations</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/>
<link href="style/style.css" rel="stylesheet" type="text/css"/>
</head>

<body>
<BR><BR><BR><BR><BR>
<div align="center">
<table>
<tr><td class="tableheader" colspan=2>Detailed information</td></tr>
<tr><th>ID:</th><td><div align="left"><?php echo $Resultset['ID'];?>
  </div></td></tr>
<tr><th>CreateDate:</th><td><div align="left"><?php echo $Resultset['createDate'];?>
  </div></td></tr>
<tr><th>LoginName:</th><td><div align="left"><?php echo $Resultset['loginName'];?>
  </div></td></tr>
<tr><th>Password:</th><td><div align="left"><?php echo $Resultset['password'];?>
  </div></td></tr>
<tr><th>LastName:</th><td><div align="left"><?php echo $Resultset['lastName'];?>
  </div></td></tr>
<tr><th>FirstName:</th><td><div align="left"><?php echo $Resultset['firstName'];?>
  </div></td></tr>
<tr><th>Company:</th><td><div align="left"><?php echo $Resultset['company'];?>
  </div></td></tr>
<tr><th>Title:</th><td><div align="left"><?php echo $Resultset['title'];?>
  </div></td></tr>
<tr><th>Email:</th><td><div align="left"><?php echo $Resultset['email'];?>
  </div></td></tr>
<tr><th>Phone:</th><td><div align="left"><?php echo $Resultset['phone'];?>
  </div></td></tr>
<tr><th>Status:</th><td><div align="left"><?php echo $Resultset['status'];?>
</div></td></tr>
<tr><th>HowHear:</th><td><div align="left"><?php echo $Resultset['HowHear'];?>
  </div></td></tr>
<tr><th>Downloads:</th>
<td><div align="left">
<?

Link to comment
https://forums.phpfreaks.com/topic/65120-solved-the-darn-sign-in-my-database/
Share on other sites

you should ALWAYS validate your input before passing through a script.  This wil prevent sql injection.  If you do not know what tis means...google it quick as you are VERY vunerable to attacks.

 

Because you will now read up and validate you data, you can now add

 

$mystring= "Mills & Boon";

 

$mystring=str_replace("&",&",$mystring);

 

or any other replacement method you see fit to use.

 

 

Does the user data come from a form?

Daniel0. Yes the user data comes from a form

 

 

When you insert the data do you use get or post?

plutomed, I use get.

 

 

 

Willpower. I did do validation, like numbers only, email check, you know the usual stuff. But I did not think to change the ampersand to &amp. So you are saying to change it on the way in. 

 

 

 

 

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.