WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDESPHP CLASSESCODE SEARCHARTICLES SEARCHPHP FORUMSPHP MANUALPHP FUNCTIONS LISTWEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search


Submit a code Example / Snippet Join us on FaceBook
Submit a code Example / Snippet Submit Your Code
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Resources
Web Development Content
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder



Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : Multiple Select box, Select multiple Items from Menu.List box
Categories : PHP, HTML and PHP, Beginner Guides Click here to Update Your Picture
eli n
Date : Sep 19th 2004
Grade : 2 of 5 (graded 70 times)
Viewed : 227669
File : No file for this code example.
Images : No Images for this code example.
Search : More code by eli n
Action : Grade This Code Example
Tools : My Examples List

Submit your own code examples  Submit your own code examples 
 

Ok,
I create 3 files and 1 database with 1 table.
select3.php this is the form
select4.php this is the function for sending to the database
display.php this is to display result from database

MySQL Database structure:

Table structure for table `multiple`
CREATE TABLE `multiple` (
  `id1` int(4) NOT NULL auto_increment,
  `id` varchar(4) default '1',
  `test` varchar(255) default '2',
  PRIMARY KEY  (`id1`)
) TYPE=MyISAM AUTO_INCREMENT=45 ;



select3.php
<html>
<head>
<title>Select Multiple Box</title>
</head>
<body>
<table width="300" cellpadding="5" cellspacing="0" border="2">
<tr align="center" valign="top">
<td align="left" colspan="1" rowspan="1" bgcolor="#FFFFFF">
<h3>Insert Record <a href="display.php">Display result </a></h3>
<form method="POST" action="select4.php">
<!--The hidden fields are provided to maintain state.  They are used to pass the username and password from script to script.-->
<input type="hidden" name="username" value="<? print $_POST['id']?>">
<?php
print "Enter name: <input type=text name=id size=20><br>\n";
print
"Select Items: <select name=test[] size=5 multiple >
          <option value=item1 >item1</option>
          <option value=item2 >item2</option>
          <option value=item3 >item3</option>
          <option value=item4 >item4</option>
          <option value=item5 >item5</option>
          <option value=item6 >item6</option>
          <option value=item7 >item7</option>
        </select><br>\n"
;
print
"<br>\n";
print
"(Shif+Right Mouse) for multiple selection<br>\n";
print
"<br>\n";
print
"<input type=submit value=Submit><input type=reset>\n";
?>
</form></td></tr></table>
</body>
</html>



select4.php
<html>
<head>
<title>Birthdays Insert Record</title>
</head>
<body>
<?php
$id
=$_POST['id'];
$test=$_POST['test'];
$db="select";
$link = mysql_connect("localhost","root","");
//$link = mysql_connect("localhost",$_POST['username'],$_POST['password']);
if (! $link)
die(
"Couldn't connect to MySQL");
mysql_select_db($db , $link) or die("Select Error: ".mysql_error());
//for($i=0;$i<sizeof($_POST["test"]);$i++)
//{
//$sql = "insert into tbl_name values ($_POST["test"][$i])"; }
//sql = "INSERT INTO table_name VALUES ('" . join(",",$_POST["test"]) . "')";
$result=mysql_query("INSERT INTO multiple (id, test) VALUES ('$id','" . join(",",$_POST["test"]) . "')")or die("Insert Error: ".mysql_error());
mysql_close($link);
print
"Record added\n";
?>
<a href="display.php">Display Records</a>
<form method="POST" action="select3.php">
<input type="submit" value="Insert Another Record">
</form>
</body>
</html>



display.php
<html>
<head>
<title>(Title Here)</title>
</head>
<body>
<?php
$db
="select";
$link = mysql_connect("localhost","root","");
if (!
$link)
die(
"Couldn't connect to MySQL");
mysql_select_db($db , $link)
or die(
"Couldn't open $db: ".mysql_error());
$result = mysql_query( "SELECT * FROM multiple" )
or die(
"SELECT Error: ".mysql_error());
$num_rows = mysql_num_rows($result);
print
"There are $num_rows records.<P>";
print
"<table width=200 border=1>\n";
while (
$get_info = mysql_fetch_row($result)){
print
"<tr>\n";
foreach (
$get_info as $field)
print
"\t<td><font face=arial size=1/>$field</font></td>\n";
print
"</tr>\n";
}
print
"</table>\n";
mysql_close($link);
?>
<a href="select3.php">Back</a>
</body>
</html>



Nested repeat region
Categories : PHP, HTML and PHP, Beginner Guides
Form Submission Using Array's
Categories : PHP, HTML and PHP, Beginner Guides, Arrays
How to preset a text string in a textarea input field
Categories : HTML, HTML and PHP, PHP, Beginner Guides
Simple PHP Form Field Generator
Categories : PHP, Beginner Guides, Form Processing, HTML and PHP
PHP3: Formmail. Just a cgi formmail, but than in PHP. It is easy to use!
Categories : HTML and PHP, Email, PHP, Perl, HTML and PHP
How to Create a Shoutbox Using PHP & MySQL
Categories : PHP, MySQL, Web Applications, Beginner Guides, HTML and PHP
Real simple example of removing HTML tags from text then changing \n (new line) to <br>. Could be used in a forum for instance.
Categories : HTML, PHP, HTML and PHP, Beginner Guides
Newbie Notes #9 - Hyperlinking a post
Categories : PHP, Java Script, HTML and PHP, Beginner Guides
Kewl Date Example
Categories : PHP, HTML and PHP, Date Time, CSS, Beginner Guides
PHP based HTML rabbing Tools
Categories : PHP, HTML and PHP, Tag Extractors, Regexps, Beginner Guides
Using PHP im HTML image tags
Categories : PHP, HTML and PHP, Graphics, Beginner Guides
Newbie Notes #1 - Making a form return to itself
Categories : PHP, Beginner Guides, HTML and PHP
mySQL/PHP/search with multientry form and table output with colored rows
Categories : PHP, Beginner Guides, MySQL, HTML and PHP, Databases
This PHP function creates dropdown select lists for time and date that you can change, outputs a 14 char MySQL timestamp in a text field
Categories : PHP, MySQL, Java Script, HTML and PHP
PageRank Display
Categories : Search Engines, HTML and PHP, PHP
 Aadi Dugar wrote : 1650
Thanks guys, I was missing the brackets \[\] in my multiple option select field. Cheers for that.
 
 buggeroff none wrote : 1797
what kind of a code is this? I ve copied it and pasted it
 and it doesn't work! what is it? you dont even bother to 
check if it works before launching it publicly?


this is the thanks I got for wasting my time here:


Parse error: syntax error, unexpected '"', expecting 
T_STRING or T_VARIABLE or T_NUM_STRING in 
C:\xampp\htdocs\select4.php on line 17


 
 ivette groombridge wrote :1914
Thanks a lot for that. Just what I was looking for. I am now able to put multiple numbers in a field. Can you tell me how to retrieve a record based on the 2nd number in this field entry? Or is it not possible?