Jump to content

Charaters missing when Displaying Data


Aragorn911

Recommended Posts

hey,

 

I have a database that contains song lyrics in a table. I'm using my webpage to display them when a user searches it. Its a very simple page. But I have 2 problems.. (Probably the same cause for both)

 

1. Some characters are missing when displaying it on the page.

Ex: the table contains this text block:

wínd mshdfKks - wdor foúªks

.e<jqïlre;=uks - Y=oaO wd;aufhks

ia;=;shs Tng ia;=;shs

 

But when i'm displaying it, It becomes:

wínd mshdfKks - wdor foúªks

.e ia;=;shs Tng ia;=;shs

 

** These are gibberish because its a font of a foreign language **

Whats causing the problem? The collation of the DB and the tables is UTF-8.

I even have an INSERT page to add songs to the database. When I use that to add the above code,

the same thing happens.

But when I goto phpmyAdmin and browse the table, the full text is there.

help!

 

2. When I try to add a long text like this using the INSERT page, It goes says succesful. But doesnt add to the databse.

Ex: This is the song that I tried to add:

Above all powers, above all kings

Above all nature and all created things

Above all wisdom and all the ways of man

You were here before the world began

 

Above all kingdoms, above all thrones

Above all wonders the world has ever known

Above all wealth and treasures of the earth

There's no way to measure what you're worth

 

Crucified

Laid behind a stone

You lived to die

Rejected and alone

Like a rose

Trampled on the ground

You took the fall

And thought of me

Above all

 

 

----------------------------------------------

 

Here is the code:

<form name="search" method="post" action="index.php">
     			
        <lable>
        Language:
        <span class="toptext">
        </label>
        </span>
	<select name="Language">
        <option value="Sinhala">Sinhala</option>
	<option value="English">English</option>
        </select>       
          <br /><br /><br /><br />      
          Song Name: <br />
         <input type="text" name="criteria" size="50" /> 
                
        <input type="submit" name="search" value="Search" />
        </form>
        
        <br /><br /><br /> 
<br />

        
        <?php 

	 if(isset($_POST['search'])){
         $Language = $_POST['Language'];
         $criteria = $_POST['criteria'];
         
	 $query = "SELECT * FROM songs WHERE Title LIKE '$criteria%' AND Language = '$Language' ";
         $result = mysql_query($query) or die ("ERROR");

	while($row = mysql_fetch_array($result)){
          
	  echo "<br/><br/>";
	  echo "<b><h1>";		  
          echo $row['Title'];
		  echo "</b></h1>";		  
	  echo "<br/><br/>";
          
	  if($Language == 'Sinhala'){
	  echo "<span class=sinhala>";
	  
          }
	  echo nl2br ($row ['Lyrics']);
	  if($Language == 'English'){
	  echo "<span>";
	  
          }
	  echo "</span>";
	   echo "<br/>";
	  echo "<a href = \"modify.php?id=" . $row['ID'] . "\">EDIT</a>";
	  echo "<span>|</span>";
	  echo "<a href = \"delete.php?id=" . $row['ID'] . "\">DELETE</a>";	
          echo "<br/><br/>";
	  echo "<br/><br/>";
          }      
	  echo "<br/><br/>";
    }

	?>

 

 

Here is the INSERT page code:

<?php
$Language = $_POST['Language'];
$Title = $_POST['song_title'];
$Lyrics = $_POST['song_lyrics'];

if(!$_POST['submit']){
echo "Please Fill out the form";

}else{
	mysql_query ( "INSERT INTO songs (`ID`, `Language`, `Title`, `Lyrics`)
					VALUES (NULL, '$Language', '$Title', '$Lyrics') ");



		header("Location: nt_songadded.php");

}

?>

Link to comment
Share on other sites

RE: problem #1: Look at the character that's causing the problem. It's the same character that signifies the beginning of an HTML tag. It needs to be echoed as < so it renders as a character instead of being interpreted as the start of a tag. That can be done for all applicable characters with htmlentities.

 

RE: problem #2: Not enough information. What is the database field type, and what is the code for the form?

Link to comment
Share on other sites

It worked!!!!!! THANKS DUDE!!! <3 <3

 

OK to the 2nd Question... For some reason, I cant add that song I mentioned earlier. I tried adding verse by verse. When I tried to add the first verse only, it worked. But then I deleted it and tried to add it again... then it didnt work... I cant figure out whats exactly happening...  :shrug:

 

Here is the code for the form.

<form name="search" method="post" action="adding.php">
     	<lable>Language:</label>
	<select name="Language">
        <option value="Sinhala">Sinhala</option>
	<option value="English">English</option>
        </select>        
         <br /><br />

         <label>Song Title:</label> <br />
         <input type="text" name="song_title" /> 
         <br /><br />
		 <label>Song Lyrics:</label> <br />
         
         <textarea name="song_lyrics" id="song_lyrics" cols="50" rows="20"></textarea>
	<br /><br />
        
        <input type="submit" name="submit" value="Submit" />
        </form>

 

And the adding.php is included in my above post...

Database field type is TEXT

 

Link to comment
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.