Help with displaying the name "O'Brien"

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
ciaranholland
Forum Newbie
Posts: 6
Joined: Sat Feb 20, 2010 6:50 pm

Help with displaying the name "O'Brien"

Post by ciaranholland »

Hi folks,

I'm using php and a mysql database. I've a page where users can edit a name. When i select to edit the name "O'Brien" the only thing that appears in the input box is "O" before i start editing it. When these names are added i have the code below featured before it writes it to the database:

Code: Select all

 
 
  $SurName=mysql_real_escape_string($_POST['inputSurName']);
 
 
I thought that would have fixed it, as it's writing "O'Brien" to the database but it's not. Below is the code from the form that displays the name in the text box:

Code: Select all

 
 
$query = "SELECT * FROM tblpupil WHERE PupilID = $id";
    
    
    $result = mysql_query($query);
    
    
    
    while($row = mysql_fetch_array($result)) {
        echo "<form method=post action=editname2.php?id=" . $row['PupilID'] . ">";
        echo "<table border=0 cellSpacing=2 cellPadding=1 width=90%>";
        echo "<tr><td colspan=4><FONT align=left color=#808080 size=5>Edit Pupil Name</Font></td></tr>";
        
        echo "<TR><TD></td></tr><TR><TD></td></tr><TR><TD></td></tr>";
        echo "<tr><td width=50%>First Name</td>";
        echo "<td><input type=text name=editFirstName size=20 value='" . $row['FirstName'] . "'></td></tr>";
        echo "<tr><td>Surname</td>";
        echo "<td><input type=text name=editSurName size=20 value='" . $row['SurName'] . "'></td></tr>";
        echo "<tr><td colspan=2 align=center><input type=submit name=submit value=Save>  <input type=submit name=cancel value=Cancel></td></tr></table>";
        
    }
 

Here the surname is for the pupil Stephen O'Brien is displaying just "O". Does anybody know how to fix this? Any help would be greatly appreciated.

Thanks guys!
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Help with displaying the name "O'Brien"

Post by requinix »

It's not proper HTML unless you quote your attributes.

Wrong:

Code: Select all

<table border=0 cellSpacing=2 cellPadding=1 width=90%>
Right:

Code: Select all

<table border="0" cellSpacing="2" cellPadding="1" width="90%">
Single quotes are also acceptable.
jraede
Forum Contributor
Posts: 254
Joined: Tue Feb 16, 2010 5:39 pm

Re: Help with displaying the name "O'Brien"

Post by jraede »

The code that displays O'Brien would read ...value = 'O'brien'. The value attribute is being cut off at the single quote after the "O". If you enclose the value with double quotes, it should work. I know you're already using double quotes in your echoed string, but it may be easier to simply close the php and display the html normally. Any conditionals in the php will still hold true even if you close it. Example:

Code: Select all

 
<?php
$x = TRUE;
if($x) :?>
<p>X is true</p>
<?php endif;?>
 
Post Reply