Jump to content

Text Display from MySQL database


jcbarr

Recommended Posts

Okay so I have a form that is used to submit a rather large amount of text in to a MySQL database. Then I have a second page that displays said text.

 

I have the column in the database formatted as longblob.

 

Any time there are quotes or basically any kind of punctuation minus a period or comma it displays very strangely.

 

Here is the code for the form;

 

<?

include("include/session.php");
?>

<html>
<title>Backstage Area</title>
<body bgcolor="#000000" style="font-family:tahoma;" text="#FFFFFF">

<table>
<tr><td>


<?
/**
* User has already logged in, so display relavent links, including
* a link to the admin center if the user is an administrator.
*/
if($session->logged_in){
?>
<font size="2">

<h2>Create Roleplay</h2><P>

<form method="post" action="process_roleplay.php">
Character: <? $sql="SELECT wrestler from users WHERE username='$session->username'";
$result=mysql_query($sql);
$wrestler=mysql_fetch_array($result);
echo "{$wrestler['wrestler']}"; ?> <BR><BR>
Event: <select name="event"><? $sql="SELECT * from events ORDER BY date DESC LIMIT 2";
$result=mysql_query($sql);
while ($event=mysql_fetch_array($result)){
echo "<option value='{$event['id']}'>{$event['name']} {$event['date']}</option>";
}
?></select><P>
Title: <input type="text" name="title" maxlength="64"><P>
Content:<br><textarea name="content" cols="75" rows="35"></textarea>
<input type="hidden" value="<? echo "$session->username"; ?>" name="user"><br>
<input type="submit" value="submit">  <input type="reset" value="reset">
</P></form>


<br><br><br>
<P>
<?
/*
*Links to edit profile and whatnot are located here
*Other things that you want to show up only if a user is logged in
*can also be added before the else statement at this point
*/
   echo "Welcome <b>$session->username</b>, you are logged in. <br><br>"
       ."[<a href=\"../index.php\">STRIFE Home</a>]   "
       ."[<a href=\"userinfo.php?user=$session->username\">My Account</a>]   "
       ."[<a href=\"useredit.php\">Edit Pass/Email</a>]   ";
   if($session->isAdmin()){
      echo "[<a href=\"admin/admin.php\">Admin Center</a>]   ";
   }
   echo "[<a href=\"index.php\">Backstage Home</a>]  ";   
   echo "[<a href=\"process.php\">Logout</a>]";
}
else{
?>
</font><br><br><br>
<h1>Login</h1>
<?
/**
* User not logged in, display the login form.
* If user has already tried to login, but errors were
* found, display the total number of errors.
* If errors occurred, they will be displayed.
*/
if($form->num_errors > 0){
   echo "<font size=\"2\" color=\"#ff0000\">".$form->num_errors." error(s) found</font>";
}
?>
<form action="process.php" method="POST">
<table align="left" border="0" cellspacing="0" cellpadding="3">
<tr><td>Username:</td><td><input type="text" name="user" maxlength="30" value="<? echo $form->value("user"); ?>"></td><td><? echo $form->error("user"); ?></td></tr>
<tr><td>Password:</td><td><input type="password" name="pass" maxlength="30" value="<? echo $form->value("pass"); ?>"></td><td><? echo $form->error("pass"); ?></td></tr>
<tr><td colspan="2" align="left"><input type="checkbox" name="remember" <? if($form->value("remember") != ""){ echo "checked"; } ?>>
<font size="2">Remember me next time     
<input type="hidden" name="sublogin" value="1">
<input type="submit" value="Login"></td></tr>
<tr><td colspan="2" align="left"><br><font size="2">[<a href="forgotpass.php">Forgot Password?</a>]</font></td><td align="right"></td></tr>
</table>
</form>

<?
}

?>


</td></tr>
</table>


</body>
</html>

 

Here is the code for the page that processes the form and inserts it in to the database;

 

<?

include("include/session.php");
?>

<html>
<title>Backstage Area</title>
<body bgcolor="#000000" style="font-family:tahoma;" text="#FFFFFF">

<table>
<tr><td>


<?
/**
* User has already logged in, so display relavent links, including
* a link to the admin center if the user is an administrator.
*/
if($session->logged_in){
?>
<font size="2">

<?
$eventid=$_POST['event'];
$title=$_POST['title'];
$content=$_POST['content'];
$user=$_POST['user'];

$sql="INSERT into roleplays (eventid, title, content, user) VALUES ('$eventid', '$title', '$content', '$user')";
if (mysql_query($sql)){
echo "Roleplay successfully created<P><a href=index.php>Return To Backstage Home</a>";
} else {
echo "An Error occurred, contect administrator";
}
?>

<br><br><br>
<P>
<?
/*
*Links to edit profile and whatnot are located here
*Other things that you want to show up only if a user is logged in
*can also be added before the else statement at this point
*/
   echo "Welcome <b>$session->username</b>, you are logged in. <br><br>"
       ."[<a href=\"../index.php\">STRIFE Home</a>]   "
       ."[<a href=\"userinfo.php?user=$session->username\">My Account</a>]   "
       ."[<a href=\"useredit.php\">Edit Pass/Email</a>]   ";
   if($session->isAdmin()){
      echo "[<a href=\"admin/admin.php\">Admin Center</a>]   ";
   }
      echo "[<a href=\"index.php\">Backstage Home</a>]  ";
   echo "[<a href=\"process.php\">Logout</a>]";
}
else{
?>
</font><br><br><br>
<h1>Login</h1>
<?
/**
* User not logged in, display the login form.
* If user has already tried to login, but errors were
* found, display the total number of errors.
* If errors occurred, they will be displayed.
*/
if($form->num_errors > 0){
   echo "<font size=\"2\" color=\"#ff0000\">".$form->num_errors." error(s) found</font>";
}
?>
<form action="process.php" method="POST">
<table align="left" border="0" cellspacing="0" cellpadding="3">
<tr><td>Username:</td><td><input type="text" name="user" maxlength="30" value="<? echo $form->value("user"); ?>"></td><td><? echo $form->error("user"); ?></td></tr>
<tr><td>Password:</td><td><input type="password" name="pass" maxlength="30" value="<? echo $form->value("pass"); ?>"></td><td><? echo $form->error("pass"); ?></td></tr>
<tr><td colspan="2" align="left"><input type="checkbox" name="remember" <? if($form->value("remember") != ""){ echo "checked"; } ?>>
<font size="2">Remember me next time     
<input type="hidden" name="sublogin" value="1">
<input type="submit" value="Login"></td></tr>
<tr><td colspan="2" align="left"><br><font size="2">[<a href="forgotpass.php">Forgot Password?</a>]</font></td><td align="right"></td></tr>
</table>
</form>

<?
}

?>


</td></tr>
</table>


</body>
</html>

 

And finally the page that displays the information from the database;

 

$pid=$_GET['pid'];
$event=$_POST['event'];
?>
<?
if (!isset($pid ) && !isset($event)){
?>
<form name="form1" action="<? echo $_SERVER['PHP_SELF']; ?>" method="post">
<center><B>SELECT EVENT: </B>  <select name="event" onChange="document.form1.submit()"><option></option>
<?
$sql="SELECT * FROM events ORDER BY id DESC";
$a=mysql_query($sql, $link);
while ($b=mysql_fetch_array($a)){
extract($b);
echo "<option value='$id'>$name</option>";
}
?>
</select>
</center>
</form><br /><br />
<?
$sql="SELECT *, name FROM roleplays, bio WHERE bio.user=roleplays.user ORDER BY id DESC LIMIT 50";
$r=mysql_query($sql, $link);
while($a=mysql_fetch_array($r)){
extract($a);
echo "<img src='../images/rp/$user.jpg' align='left'>  ";
echo "<a href='{$_SERVER['PHP_SELF']}?pid=$id'>$title</a><br>";
echo "  <b>Author:</b> $name<br>";
$sql2="SELECT name, eventid FROM events, roleplays WHERE events.id=roleplays.eventid";
$s=mysql_query($sql2, $link);
$b=mysql_fetch_array($s);
extract($b);
echo "  <b>$name</b>";
echo "<hr><br><br><br>";
}
}
?>
<?
if (isset($pid) && !isset($event)){
$sql="SELECT * FROM roleplays WHERE id='$pid'";
$a=mysql_query($sql, $link);
$b=mysql_fetch_array($a);
extract($b);
echo "<img src='../images/body/$user.jpg' align=right hspace=5 vspace=5>";
echo "<b><h2>$title</h2></b><P>";
echo nl2br($content);
echo "<P><center><a href='../promos.php'>Back To Promos</a></center>";
}
?>
<?
if (!isset($pid) && isset($event)){
$sql="SELECT * FROM roleplays WHERE eventid='$event'";
$r=mysql_query($sql, $link);
while($a=mysql_fetch_array($r)){
extract($a);
echo "<img src='../images/rp/$user.jpg' align='left'>  ";
echo "<a href='{$_SERVER['PHP_SELF']}?pid=$id'>$title</a><br>";
echo "  <b>Author:</b> $name<br>";
$sql2="SELECT name, eventid FROM events, roleplays WHERE events.id=roleplays.eventid";
$s=mysql_query($sql2, $link);
$b=mysql_fetch_array($s);
extract($b);
echo "  <b>$name</b>";
echo "<hr><br><br><br>";
}
}
?>

 

Any help at all on this would be great. I thought that I had it figured out once before but I am now lost again.

 

If you type the information in to the form then it works fine. If you copy and paste from something like Notepad or Word, then that is where the problems occur.

 

Thanks in advance for any help that is given.

Link to comment
https://forums.phpfreaks.com/topic/131282-text-display-from-mysql-database/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.