Jump to content

Posibility to the user to format text before sending it to database


bemax

Recommended Posts

I have an login system. Now I want the user to have the possibility to format the text before sending to database as he want. Something like what I have here where I sending this message.

Example:

 

Something like what I have

here where I sending this message

 

How can I do it in php?

 

 

  • 2 weeks later...

Thanks for your reply! It was very helpfull but i have an other question. I doing a pagination and I getting an error message witch is : Query failed: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '8, 4' at line 1

 

I cant realy find where is the mistake, could you please help me with this? Here is the code:

 

<?php
/* 
////////////////////////////////////////// 
////1) MySQL Database Connection /////////// 
////////////////////////////////////////// 
*/
$host = "localhost"; 
$user = "francine"; 
//$db_name= "yourdatabasename";
$db_name= "francine"; 

$pass= "123"; 
$conn = mysql_connect($host, $user, $pass) or die(mysql_error()); 
mysql_select_db($db_name, $conn) or die(mysql_error()); 
?> 

<?php
/*
//////////////////////////////////////////////////
////2) Get page number, if any 
///////////////////////////////////////// 
////// Prevent Injection Attack ///////// 
////// Set $pageno variable ///////////// 
///////////////////////////////////////// 
*/
if(isset($_GET['pageno'])) 
{ 
    if(!is_numeric($_GET['pageno'])) 
    { 
        echo 'Error.'; 
        exit(); 
    } 
    $pageno = $_GET['pageno']; 
} 
else 
{ 
    $pageno=1; 
} 
?> 
<!--
//////////////////////////////////////////////////////////////////
//3) Calculate how many rows or records in total the query will output 
/////////////////////////////////////////////////////////////////
-->
<?php 
$queryCount = 'SELECT count(*) FROM proverbes'; 
$resultCount = mysql_query($queryCount); 
$fetch_row = mysql_fetch_row($resultCount); 
$numrows = $fetch_row[0]; 
// if there is no results 
if($numrows == 0) 
{ 
    echo 'Sorry, we have no products yet.'; 
    exit(); 
}?> 
<!--
///////////////////////////////////////////////////////////////
///4) Calculate number of pages 
////////////////////////////////////////////////////////////////
-->
<?php 
$perPage = 4; 
$lastpage = ceil($numrows/$perPage); 
$pageno = (int)$pageno; 
if($pageno<1) 
{ 
    $pageno=1; 
} 
elseif($pageno>$lastpage) 
{ 
    $pageno=$lastpage; 
} 
?> 
<!--
////////////////////////////////////////////////////////////////
///5) Generate page links 
////////////////////////////////////////////////////////////////
-->
<?php 
// ----- PAGE LINKS ----- 
if($pageno==1) 
{ 
    $pages .= 'FIRST | PREVIOUS '; 
} 
else 
{ 
    $pages .= "<a href='{$_SERVER['PHP_SELF']}?pageno=1'>FIRST</a> | "; 
    $prevpage=$pageno-1; 
    $pages .= " <a href='{$_SERVER['PHP_SELF']}?pageno=$prevpage'>PREVIOUS</a> "; 
} 
$pages .= ' ( Page '.$pageno.' of '.$lastpage.' ) '; 
if($pageno==$lastpage) 
{ 
    $pages .= ' NEXT | LAST '; 
} 
else 
{ 
    $nextpage = $pageno+1; 
    $pages .= " <a href='".$_SERVER['PHP_SELF']."?pageno=$nextpage'>NEXT</a> | "; 
    $pages .= " <a href='".$_SERVER['PHP_SELF']."?pageno=$lastpage'>LAST</a>"; 
} 
?> 
<!--
/////////////////////////////////////////////////////////////////
/////6) Calculate LIMIT clause for the MySQL query 
////////////////////////////////////////////////////////////////
-->
<?php 
//$limit=' LIMIT '.($pageno-1)*$perPage.', '.$perPage;
$limit=($pageno-1)*$perPage.', '.$perPage; 

?> 
<!--
//////////////////////////////////////////////////////////////////
////7) Run the query, echo the results and echo the page links 
/////////////////////////////////////////////////////////////////
-->
<?php 

$query  = $query.$limit; 
$result = mysql_query($query); 

if(!$result) 
{ 
    echo 'Query failed: '.mysql_error(); 
    

}
else
{

	while($row = mysql_fetch_array($result , MYSQL_NUM)) 
	{ 

	   echo $row['id'].' '.$row['theme'].' '.$row['proverbe'].' '.$row['explication'].' '.$row['nom'].'<br />'; 
	   //echo $row[0];

	} 
}
echo '<div style="width:100%; text-align: center; font-size: smaller; color: #999;">'.$pages.'</div>' ;
echo ' Total number of products: '.$numrows; 
?> 

 

 

 

 

 

 

 

 

 

 

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.