« on: January 13, 2009, 09:34:20 AM »
config.php<?php
$dbhost = 'localhost';
$dbusername = 'root';
$dbpassword = 'mydbpass';
$dbname = 'mydbname';
$conn=mysql_connect($dbhost, $dbusername, $dbpassword);
if(!$conn) :
die('Could not connect: ' . mysql_error());
endif;
$db=mysql_select_db($dbname, $conn);
if(!$db) :
die ('Can\'t connect to database : ' . mysql_error());
endif;
?>
Install.php<?php
include('config.php');
mysql_query("CREATE TABLE `page` (
`linkid` int(11) NOT NULL auto_increment,
`text` text collate utf8_unicode_ci,
`linkurl` text collate utf8_unicode_ci,
PRIMARY KEY (`linkid`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1")
or die(mysql_error());
?>index.php<title>Index Page</title>
<center><h2>INDEX</h2></center><BR>
<?php
include('config.php');
echo " <a href=\"insert.php\">INSERT PHP</a><br>";
$result = mysql_query("SELECT * FROM page")
or die(mysql_error());
while($link=mysql_fetch_array($result)){
echo " <a href=\"webpage.php?id=$link[linkid]\">Web Page 1</a><br>";
}
?>insert.php<title>Insert Page</title>
<center><h2>INSERT PAGE</h2></center><BR>
<?php
include('config.php');
if(isset($_POST['submit']))
{
$text = $_POST['text'];
$linkurl = $_POST['linkurl'];
mysql_query("INSERT INTO page (text,linkurl)
VALUES ('$text','$linkurl')")
or die(mysql_error());
}else{
?>
<form method="post" action="insert.php">
<TABLE><TR><TD>
Title:
</TD>
<TD>
<input name="text" size="60" maxlength="255">
</TD></TR>
<TR><TD>
URL:
</TD>
<TD>
<input name="linkurl" size="60" maxlength="255">
</TD></TR>
<TR><TD>
<input type="submit" name="submit" value="submit">
</TD></TR></TABLE>
</form>
<?php
}
?>
webpage.php<?php
include('config.php');
$id = $_GET['id'];
$result = mysql_query("SELECT linkid, text, linkurl FROM page WHERE linkid='$id' ")
or die(mysql_error());
while($myrow = mysql_fetch_assoc($result))
{
echo "<title>Web Page $myrow[text]</title>";
echo "<center><h2>Web Page $myrow[text]</center><BR>";
echo "<a href=\"$myrow[linkurl]\">$myrow[text]</a>";
}
?>

« Last Edit: January 13, 2009, 10:51:26 AM by alex »

Logged