Archive for November, 2006

php – Including Files in PHP

<?php

// this will help

include(“config.php”);  // show error if not included
include_once(“config.php”); // not show error when it is already included

?>

Advertisements

Leave a Comment

Inserting and Displaying Information From a Database

<?php

// database information
$host = ‘localhost’;
$user = ‘username’;
$password = ‘password’;
$dbName = ‘databasename’;

// connect and select the database
$conn = mysql_connect($host, $user, $password) or die(mysql_error());
$db = mysql_select_db($dbName, $conn) or die(mysql_error());

// insert new entry in the database if entry submitted
if (isset($_POST[‘newEntry’]) && trim($_POST[‘newEntry’]) != ”) {
// for easier variable handling…
$newEntry = $_POST[‘newEntry’];

// insert new entry into database
$sql = “insert into testTable (someField) values (‘$newEntry’)”;
$result = mysql_query($sql, $conn) or die(mysql_error());
} // end if new entry posted

// select all the entries from the table
$sql = “select someField from testTable”;
$result = mysql_query($sql, $conn) or die(mysql_error());

// echo out the results to the screen
while ($list = mysql_fetch_array($result)) {
echo “{$list[‘someField’]} <br>”;
} // end while

// echo out the form to add a new entry
echo <<<FORMENT
<br> Make a new entry: <br>
<form action = “{$_SERVER[‘PHP_SELF’]}” method = “post”>
<input type = “text” name = “newEntry” maxlength=”20″ size = “10”>
<input type = “submit” value = “Add Entry”>
</form>
FORMENT;

?>

Leave a Comment

php – getting server info

<?php

# This will help in getting server info

# Like GD modules are there or not.

phpinfo();

?>

Leave a Comment