Ad block is installed and active. Please support us by disabling it.
HomeSunday, November 19, 2017, 13:52:32
1

Random MySQL Query

Tuesday, February 10, 15, 00:45:40, 3 Yaers Ago Via wain, Hits: 2941
Random MySQL query, requirement(s): PHP Server, MySQL
Download source code:

http://phpform.net/download.php?f=random.zip

config.php

Code:
<?php
//MySQL Configuration
//DB Host (Normally 'localhost')
$dbhost = 'localhost';
//DB Database Username
$dbusername = 'root';
//DB Database User Password
$dbpassword = 'mypassword';
//DB Database Name
$dbname = 'mydbname';
//mysql_connect function
$conn=mysql_connect($dbhost, $dbusername, $dbpassword);
if(!$conn) :
die('Could not connect: ' . mysql_error());
endif;
$db=mysql_select_db($dbname, $conn);
if(!$db) :
die ('Cant connect to database : ' . mysql_error());
endif;
?>


install.php

Code:
<?php
//make a MySQL connection
include('config.php');
//create a MySQL table in the selected database
mysql_query("CREATE TABLE `text` (
`textid` int(11) NOT NULL auto_increment,
`textvalue` text collate utf8_unicode_ci,
PRIMARY KEY (`textid`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8
COLLATE=utf8_unicode_ci AUTO_INCREMENT=1")
or die(mysql_error());
?>


index.php

Code:
<title>Index Page</title>
<center><h2>Index</h2></center>
<?php
include('config.php');
$query = mysql_query("SELECT MAX(textid) FROM text");
$results = mysql_fetch_array($query);
$maxresults = $results['MAX(textid)'];
if($maxresults <= '5'){
echo "<a href="insert.php">Insert Something</a><br />";
}
echo "Max results in MySQL: " . $maxresults . "<br />";
$random = rand(1,$maxresults);
echo "Displaying Result: " . $random . "<br />";
$query = "SELECT * FROM text WHERE textid ='$random'";
$result = mysql_query($query);
$row = mysql_fetch_assoc($result);
echo $row['textvalue'];
?>


insert.php

Code:
<title>Insert Page</title>
<center><h2>Insert Page</h2>
<a href="insert.php">Insert Something</a><br />
<a href="index.php">Index</a>
</center>
<?php
//make a MySQL connection
include('config.php');
//to check if a submit button was clicked, use this...
if(isset($_POST['submit']))
{
$textvalue = $_POST['textvalue'];
//The INSERT INTO statement is used to add new records
//to a database table.
mysql_query("INSERT INTO text (textvalue)
VALUES ('$textvalue')")
or die(mysql_error());
}else{
?>
<table><tr><td>
<form method="post" action="insert.php">
Textvalue:
</td><td>
<input name="textvalue" size="60" maxlength="255">
</td></tr>
<tr><td>
<input type="submit" name="submit" value="submit">
</form>
</td></tr></table>
<?php
}
?>

Sign In

Sponsor

Related

PHP highlight_string - PHP Tutorial

Outputs or returns a syntax highlighted version of the given PHP code using the colors defined in the built-in syntax highlighter for PHP. Requirement(s): PHP Server.

php Array

These functions allow you to interact with and manipulate arrays in various ways. Arrays are essential for storing, managing, and operating on sets of variables.

Password Protect With PHP

Password protect tith PHP - tutorial

Inserting form data in MySql table

Inserting form data in MySql table with PHP

PHP Links Script 1.1.

This script allows you to manage your links using a MySQL database. It features easy install, user submission, and an admin panel to add, edit and remove categories and links. The script is easy to customize to suit your needs.

Link Base L.1.1.

This script allows you to manage your links using a MySQL database. It features easy install, user submission, and an admin panel to add, edit and remove categories and links. The script is easy to customize to suit your needs.

Captcha V1 - Free PHP Script

An anti-spam form protection image written in PHP, Version: 1.1.

Show / Hide Div with CSS

CSS Display and Visibility:The visibility property specifies whether or not an element is visible.

Create dynamic Web Pages with PHP & MySQL

Create dynamic Web Pages with PHP & MySQL, Requirement(s): PHP Server, MySQL

Sitemap

phpForm.net Website Sitemap
About Author

wain

Date Registered: Sun, Feb 8, 15
Last Time Online: Thu, Jun 15, 17
So far has created 115 entries.
wain
This author has not yet filled in any details.