Create dynamic Web Pages with PHP & MySQL - php Form

Author Topic: Create dynamic Web Pages with PHP & MySQL  (Read 3804 times)

Offline alex

  • Global Moderator
  • *****
  • Posts: 77
  • Karma: +19/-0
    • View Profile
Create dynamic Web Pages with PHP & MySQL
« on: January 13, 2009, 09:34:20 AM »


config.php
Code: [Select]
<?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
Code: [Select]
<?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
Code: [Select]
<title>Index Page</title>
<center><h2>INDEX</h2></center><BR>
<?php
include('config.php');
echo 
"&nbsp;<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 
"&nbsp;<a href=\"webpage.php?id=$link[linkid]\">Web Page 1</a><br>";
}
?>





insert.php
Code: [Select]
<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

Code: [Select]
<?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>";
}
?>


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

elfcik

  • Guest
Re: Create dynamic Web Pages with PHP & MySQL
« Reply #1 on: January 19, 2009, 03:16:56 PM »
Good tutorial.. Thanks :)

Offline kateevanne

  • Supporter
  • **
  • Posts: 1
  • Karma: +0/-0
    • View Profile
Re: Create dynamic Web Pages with PHP & MySQL
« Reply #2 on: May 09, 2009, 03:22:53 AM »
Thank you! that was really helpful. ;D

djini

  • Guest
Re: Create dynamic Web Pages with PHP & MySQL
« Reply #3 on: June 01, 2009, 10:59:58 PM »
Thanks for the tutorial! ;D ;D