zrweber Posted November 3, 2006 Share Posted November 3, 2006 Ok on my page (index.php) I have 3 numbers.1.2.3.I want people to be able to fill out a form then depending on what number they select they're name will be on that number..So like if someone choosed option 2 on the form and their name was Bob it'd look like this1.2. Bob3.Then someone else signs it and chooses option 1 and their name is John1. John2. Bob3.How would I do this? Also how can I make it to where people cannot choose the same number? So if 1 is taken people cannot choose it.Thanks Quote Link to comment Share on other sites More sharing options...
JasonLewis Posted November 3, 2006 Share Posted November 3, 2006 you would need a database of some sort with a list of all the numbers and the assigned names etc.use mysql and create a table then add a field called ID and have it as an auto_increment then make a field called number and another called user. then in your php form you could just make something like this:[code]<?php$connect = mysql_connect("localhost","user","pass");mysql_select_db("db");if(isset($_POST['submit'])){ //checks if they have submitted our form}?><form action="index.php" method="POST">Your Name: <input type="text" name="name"><br>Number: <select name="number"><?php$query = mysql_query("SELECT * FROM table WHERE `user`=''"); //this selects all the numbers from table that dont have users assigned to them.if(mysql_num_rows($query) == 0){echo "<option value=''>There are no numbers left</option>"; //if there are no numbers, an option with that text will be displayed.}else{while($r = mysql_fetch_array($query)){ //selects all the rows$number = $r['number'];echo "<option value='".$number."'>Number ".$number."</option>"; //this shows all the options with Number ??}}?></select><br><input type="submit" name="submit" value="Add Me!"></form>Current Users:<br><?php$query2 = mysql_query("SELECT * FROM table"); //selects ALL the numberswhile($r2 = mysql_fetch_array($query2)){$number = $r2['number'];$user = $r2['user'];echo "#".$number.". ".$user."<br>"; //displayed the following: #??. Username}?>[/code]that should b your index.php. that should do it. i hope. good luck. Quote Link to comment Share on other sites More sharing options...
zrweber Posted November 3, 2006 Author Share Posted November 3, 2006 Thanks for responding!It's not really working, did I make the table wrong?[code]CREATE TABLE `numberselect` (`ID` INT NOT NULL AUTO_INCREMENT ,`number` VARCHAR( 31 ) NOT NULL ,`user` MEDIUMTEXT NOT NULL ,PRIMARY KEY ( `ID` ) ) TYPE = innodb;[/code] Quote Link to comment Share on other sites More sharing options...
JasonLewis Posted November 4, 2006 Share Posted November 4, 2006 did you give ID any values. like 11 or something. and is it outputting any errors? Quote Link to comment Share on other sites More sharing options...
zrweber Posted November 4, 2006 Author Share Posted November 4, 2006 I'm not getting any errors, I gave ID a value and it's still not wanting to work for me.Hmm, sorry I must be doing somethin wrong I'm a big noob at PHP I just started to learn it last month. I just need a form like this to put it on this guys website who needs it Quote Link to comment Share on other sites More sharing options...
JasonLewis Posted November 5, 2006 Share Posted November 5, 2006 what is it doing? is it displaying anything. errors. anything at all. what is happening exactly? Quote Link to comment Share on other sites More sharing options...
zrweber Posted November 5, 2006 Author Share Posted November 5, 2006 I'm not getting any errors it's showing up and everything but it just says under the numbers dropdown list is "There are no numbers left" Quote Link to comment Share on other sites More sharing options...
Kelset Posted November 5, 2006 Share Posted November 5, 2006 Did you populate the DB with the numbers you want to use? If you didn't then this query would be empty.Would that not not cause your "There are no numbers left" to come up. Just guessing here, I a new to PHP$query = mysql_query("SELECT * FROM table WHERE `user`=''");\Cheers!Stephen Quote Link to comment Share on other sites More sharing options...
zrweber Posted November 5, 2006 Author Share Posted November 5, 2006 How exactly do I do that? I'm using PHPMyAdmin, I dont know much at all about DB's, again I'ma big noobie lol but I'm really trying to learn PHP and MySQL. Quote Link to comment Share on other sites More sharing options...
tet3828 Posted November 5, 2006 Share Posted November 5, 2006 start by creating a database in PHPMyAdmin. Im pretty new at this too. but I'd say make a table with 3 columns to start. One column for the number. one for the name and one just to have as an extra. Quote Link to comment Share on other sites More sharing options...
Kelset Posted November 5, 2006 Share Posted November 5, 2006 If you have the DB made all you do in PHPMyAdmin is hit the insert tab at the top. Then insert the numbers you want to usein the numer colum.Cheers!Stephen Quote Link to comment Share on other sites More sharing options...
JasonLewis Posted November 6, 2006 Share Posted November 6, 2006 you could easily do it in mysql with a while command and just run it once to populate it then you should be fine.example:[code=php:0]$connect = mysql_connect($host, $user, $pass);mysql_select_db($db);for($i = 0; $i < 100; $i++){ //this will run until i is 100mysql_query("INSERT INTO table (`number`) VALUES ('".$i."')");}[/code]Then your done. this would be a lot quicker then manually doing it in phpMyAdmin.good luck. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.