Location: PHPKode > scripts > Random Text > admin/functions.php
<?
/**
*
* @Script Random Text
* @version 1.0.0
* @copyright (c) Agrizlive.com
* @license You are allowed to modify this script. But you must provide a link of agrizlive.com in your footer (bottom of the page)
*
* Tested : PHP 5.2.11
*/

/**
*/
	function getTotalTexts()
	{
		$query = "SELECT * FROM agriz_text";
		$result = mysql_query($query);
		return $result;
	}
	
	function add_text()
	{
		$url = $_POST['url'];
		
		if($_POST['rtext'] != "")
		{
			$query = "INSERT INTO agriz_text(url,rtext) VALUES('".$url."','".addslashes($_POST['rtext'])."')";
			$result = mysql_query($query);
			return "Inserted successfully";
		}
		else
		{
			return "Text should not be empty";
		}
	}
	
	function edit_text()
	{
		$url = $_POST['url'];
		
		if($_POST['rtext'] != "")
		{
			$query = "UPDATE agriz_text SET url = '".$url."',rtext = '".addslashes($_POST['rtext'])."' WHERE id = ".$_REQUEST['id']."";
			$result = mysql_query($query);
			return "Updated successfully";
		}
		else
		{
			return "Text should not be empty";
		}
		
	}
	
	function get_text($id)
	{
		$query = "SELECT * FROM agriz_text WHERE id = $id";
		$result = mysql_query($query);
		$value = mysql_fetch_array($result);
		
		return $value;
	}
	
	function change_passowrd()
	{
		if($_POST['pass-1'] == $_POST['pass-2'] && $_POST['pass-1'] != "")
		{
			$query = "UPDATE agriz_admin_text SET password = '".MD5($_POST['pass-1'])."' WHERE user_name = '".$_SESSION['agriz_text_user']."'";
			$result = mysql_query($query);
			return  "Password changed successfully";
		}
		else
		{
			return "Password does not match";
		}
	}
	
	function display_text()
	{
		$query = "SELECT * FROM agriz_text ORDER BY RAND()";
		$result = mysql_query($query);
		$value = mysql_fetch_array($result);
		if($value['url'] == "")
		{
			return "<p>".stripslashes($value['rtext'])."</p>";
		}
		else
		{
			return "<p><a href='".$value['url']."'>".stripslashes($value['rtext'])."</a></p>";
		}	
	}
	
	function delete_text($id)
	{
		$query = "DELETE FROM agriz_text WHERE id = $id LIMIT 1";
		$result = mysql_query($query);
	}
?>
Return current item: Random Text