Current location: Hot Scripts Forums » Programming Languages » PHP » dynamic web pages using the checkbox component


dynamic web pages using the checkbox component

Reply
  #1 (permalink)  
Old 08-11-03, 07:37 AM
oasp oasp is offline
New Member
 
Join Date: Aug 2003
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
dynamic web pages using the checkbox component

Hi I am not sure where I should post this topic but, I am trying to create a page where my users choose from a list of topics with a checkbox, then have a page generated from the topics that they have chosen. How do I go about doing this or where I could find the script for this. Thanks in advance for the help.
Oasp
Reply With Quote
  #2 (permalink)  
Old 08-12-03, 04:57 AM
kickinhard007's Avatar
kickinhard007 kickinhard007 is offline
Newbie Coder
 
Join Date: Aug 2003
Location: Manchester, UK
Posts: 65
Thanks: 0
Thanked 0 Times in 0 Posts
i take it you're looking to generate the content my pulling it out of a database like MySQL?
Reply With Quote
  #3 (permalink)  
Old 08-12-03, 07:49 AM
oasp oasp is offline
New Member
 
Join Date: Aug 2003
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
yes I am actually, the checkboxes will have the name of the fields in the table and when a user clicks whatever checkbox they want a new page is generated from the database. Any ideas on what to do or where i may find that script.
Reply With Quote
  #4 (permalink)  
Old 08-12-03, 08:57 AM
kickinhard007's Avatar
kickinhard007 kickinhard007 is offline
Newbie Coder
 
Join Date: Aug 2003
Location: Manchester, UK
Posts: 65
Thanks: 0
Thanked 0 Times in 0 Posts
i tend to use the scripts on hotscripts as a learning tool, i try to write all my own code rather than actually use the scripts.

anyway, here goes:-

1) The Form - selection.html
============================================

<html>

<head>
<title>test form</title>

</head>

<body bgcolor="#ffffff" text="#000000">

<form action="content.php" method="post">
Selection 1: <input type="checkbox" name="selection1" value="yes"><br><br>
Selection 2: <input type="checkbox" name="selection2" value="yes"><br><br>
Selection 3: <input type="checkbox" name="selection3" value="yes"><br><br>
Selection 4: <input type="checkbox" name="selection4" value="yes"><br><br>
Selection 5: <input type="checkbox" name="selection5" value="yes"><br><br>
<input type="submit" value="Submit">
<input type="reset" value="Reset"></td>

</form>

</body>

</html>


2) The Script - content.php
============================================

**remember to embed this in the html, and name the file content.php**

<?php

//Take the form fields and turn them into variables

$selection1 = $_POST['selection1'];
$selection2 = $_POST['selection2'];
$selection3 = $_POST['selection3'];
$selection4 = $_POST['selection4'];
$selection5 = $_POST['selection5'];

// Define MySQL connection settings - Alter to suit your own

$host = "localhost";
$username = "username";
$password = "password";
$database = "database";

//Pull the relevant data out of the database and store it into the variable $result

mysql_connect($host,$username,$password) or die("Unable to connect to database");

@mysql_select_db("$database") or die("Unable to select database $database");

$sqlquery = "SELECT choice1,choice2,choice3,choice4,choice5 FROM database_table";

$result = mysql_query($sqlquery);

//Take the values from $result and store them in seperate variables

$row = mysql_fetch_array($result);
$data1 = $row['choice1'];
$data2 = $row['choice2'];
$data3 = $row['choice3'];
$data4 = $row['choice4'];
$data5 = $row['choice5'];

//Print the data for each choice if the variable has a value

if ($selection1 == "yes") { print "$data1<br><br>"; }
if ($selection2 == "yes") { print "$data2<br><br>"; }
if ($selection3 == "yes") { print "$data3<br><br>"; }
if ($selection4 == "yes") { print "$data4<br><br>"; }
if ($selection5 == "yes") { print "$data5<br><br>"; }

// Print error message if the table is empty

if(mysql_num_rows($result)<1){
echo "There are no records in the database!";
}

mysql_free_result($result);
mysql_close();

?>

Last edited by kickinhard007; 08-12-03 at 09:01 AM.
Reply With Quote
  #5 (permalink)  
Old 08-12-03, 09:22 AM
oasp oasp is offline
New Member
 
Join Date: Aug 2003
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
thanks alot, that was a big help.
Oasp
Reply With Quote
  #6 (permalink)  
Old 08-12-03, 10:05 AM
kickinhard007's Avatar
kickinhard007 kickinhard007 is offline
Newbie Coder
 
Join Date: Aug 2003
Location: Manchester, UK
Posts: 65
Thanks: 0
Thanked 0 Times in 0 Posts
hope it works, let me know if you get any problems if you need to expand upon the script.
Reply With Quote
  #7 (permalink)  
Old 08-12-03, 02:54 PM
sirpeterpan sirpeterpan is offline
New Member
 
Join Date: Aug 2003
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Cool Test

This is a test message
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
SEO Expert Available nakulgoyal Job Offers & Assistance 2 08-14-04 12:38 PM
dynamic url's in xhtml pages? tom HTML/XHTML/XML 4 09-26-03 05:11 PM
dynamic web pages using the checkbox component oasp Script Requests 1 08-11-03 09:07 AM
Dynamic Navigation Menu! edigitalxp ASP 1 08-01-03 12:35 AM
dynamic uploader (progress bar) [PL]Greg PHP 8 07-02-03 12:07 PM


All times are GMT -5. The time now is 05:17 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.