A database with testimonials

lanbo

Elite Member
Jr. VIP
Premium Member
Joined
Aug 23, 2009
Messages
4,499
Reaction score
677
How can I make something that will take a random testimonial from a database and post it on the site?
 
Here you go, but can't test it.

PHP:
<?php

$dbhost = 'localhost';
$dbuser = 'username'; 
$dbpass = 'password';
$dbname = 'database_name';
$url = 'http://example.com/post.php';

$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');
mysql_select_db($dbname);

$query = "SELECT * FROM $dbname";
$results = mysql_query($query);

$resultsCount = mysql_numrows($results);

if($resultsCount > 0){
	$randomNumber = rand(0, $resultsCount-1);
	$randomTestimonial = mysql_result($results,$randomNumber,'testimonial');
	
	
	$ch = curl_init();
	curl_setopt($ch, CURLOPT_URL, $url);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
	curl_setopt($ch, CURLOPT_POST, true);
	
	$data = array(
		'testimonial' => $randomTestimonial,
		'something_else' => 'some_other_post_field'
	);

	curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
	$output = curl_exec($ch);
	curl_close($ch);
	
	echo $output;

	
	
}else{
	echo "DID NOT FIND ANYTHING";
}



?>
 
Back
Top