how do i add this to a data base

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
chris_s_22
Forum Commoner
Posts: 76
Joined: Wed Dec 31, 2008 2:05 pm

how do i add this to a data base

Post by chris_s_22 »

this is a form that once filled to make enteries into my database, firstly what tables feild names do i need, secondly what do i add to my functions.php page thirdly what will be entered in my creategame.php

Code: Select all

 
<form action="creategame.php" method="post">   
<input type='text' name='players0' size='35' value='Player 1'>
<select><option value='M'>Male</option><option value='F'>Female</option></select><br>
<input type='text' name='players1' size='35' value='Player 2'>
<select><option value='M'>Male</option><option value='F'>Female</option></select><br>
<input type='text' name='players2' size='35' value='Player 3'>
<select><option value='M'>Male</option><option value='F'>Female</option></select><br>
<input type='text' name='players3' size='35' value='Player 4'>
<select><option value='M'>Male</option><option value='F'>Female</option></select><br>
<input type='text' name='players4' size='35' value='Player 5'>
<select><option value='M'>Male</option><option value='F'>Female</option></select><br>
<input type='text' name='players5' size='35' value='Player 6'>
<select><option value='M'>Male</option><option value='F'>Female</option></select><br>
<input type='text' name='players6' size='35' value='Player 7'>
<select><option value='M'>Male</option><option value='F'>Female</option></select><br>
<input type='text' name='players7' size='35' value='Player 8'>
<select><option value='M'>Male</option><option value='F'>Female</option></select><br>
<input type='text' name='players8' size='35' value='Player 9'>
<select><option value='M'>Male</option><option value='F'>Female</option></select><br>
<input type='text' name='players9' size='35' value='Player 10'>
<select><option value='M'>Male</option><option value='F'>Female</option></select><br>
<input type='text' name='players10' size='35' value='Player 11'>
<select><option value='M'>Male</option><option value='F'>Female</option></select><br>
<input type='text' name='players11' size='35' value='Player 12'>
<select><option value='M'>Male</option><option value='F'>Female</option></select><br>
<input type='text' name='players12' size='35' value='Player 13'>
<select><option value='M'>Male</option><option value='F'>Female</option></select><br>
<input type='text' name='players13' size='35' value='Player 14'>
<select><option value='M'>Male</option><option value='F'>Female</option></select><br>
<input type='text' name='players14' size='35' value='Player 15'>
<select><option value='M'>Male</option><option value='F'>Female</option></select><br>
Select a  tareget score<select name="finalscore">
     <option>20</option>
     <option>25</option>
     <option>30</option>
     <option>35</option>
     <option>40</option>
     <option>45</option>
     <option>50</option>
     <option>55</option>
     <option>60</option>
     <option>65</option>
     <option>70</option>
     <option>75</option>
     <option>80</option>
     <option>85</option>
     <option>90</option>
     <option>55</option>
     <option>100</option>
     </select>
<input type="submit" name="submit" value="PLAY GAME" />
</form>
 
User avatar
jaoudestudios
DevNet Resident
Posts: 1483
Joined: Wed Jun 18, 2008 8:32 am
Location: Surrey

Re: how do i add this to a data base

Post by jaoudestudios »

1. Table field names can be anything you want (reserved words must be escaped)
2. You will need to use mysql_query function to send your mysql queries to the database
3. PHP code :)
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: how do i add this to a data base

Post by califdon »

You seem to be asking "How do I write PHP code to do something that isn't in the script that I got from somewhere, when I don't know how to write PHP code?" There's nothing wrong with not knowing how to do something, but a forum like this is about the worst possible way to learn a programming language. Your best option is to read some beginning PHP tutorials, then when you run into a problem that you can't solve based on the knowledge you gained in the tutorials, ask a very specific question here, and you will find plenty of people (like jaoudestudios and me and many others) who will be very happy to help you. What we can't or won't do is take on the job of rewriting somebody's script for a person who hasn't learned the basics yet.

Here's a good place to start: http://devzone.zend.com/node/view/id/627
User avatar
jaoudestudios
DevNet Resident
Posts: 1483
Joined: Wed Jun 18, 2008 8:32 am
Location: Surrey

Re: how do i add this to a data base

Post by jaoudestudios »

califdon well said :)

I think that should go in the rules!
chris_s_22
Forum Commoner
Posts: 76
Joined: Wed Dec 31, 2008 2:05 pm

Re: how do i add this to a data base

Post by chris_s_22 »

ok guys well as u guessed im new to php in fact 4 days ago was my 1st time i had even thought about adding php to my site or should i say wat wasnt a ready made script.

anyways ive read quite a few books and tutorials and was getting lost whilst reading them so i started actually whilst reading the online tutorials doing it and testing the results, i found this alot easier to understand as just reading wasnt getting me know where, i then gave myself a mini project which to all you guys will no doubt be easy, anyways my project is to create a game in php the game is the truth or dare what people play at parties.
anyways ive designed everything and thought about how everything gonna work, ive done a registration part / the login part, ive created a script that lets me add the truths and dares
now this is where im up to im getting stuck about putting the form feild data into the database if it was just the one player and the sex then the score feild at the bottom then i could do that easily
what is throwing me is that there is more there is more feilds dependent on each other ive got a few things im trying but i was asking for help
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: how do i add this to a data base

Post by califdon »

OK. Then let's start out by focusing on what you need to do. You first asked about your table structure. For that, I'd suggest that you read this: http://www.microsoft-access-tutorial.co ... se_05.html - although it's talking about Microsoft Access, it applies to any database structure. This is a critical area of design and one that you pretty much have to do for yourself, because what you decide to store in a database is entirely up to you. But the thought process is what's important and that's what this tutorial is about.

Your next question, though ("what do i add to my functions.php page"), is what set off the alarms. There's no answer to a question like that. Who knows what you want to do in any particular script? You. The fact that you're thinking in terms like this is not a good sign. You should be thinking in terms of "what must my code accomplish?" first. You said that "ive designed everything and thought about how everything gonna work", but you didn't tell US how everything is gonna work, so we have no way to help you. This stage has to be very detailed, because the task is to translate what you want to happen into lines of PHP code, which is VERY detailed. Then you asked about "putting the form feild data into the database" but said that you knew how to do it for just one player, but that "what is throwing me is that there is more there is more feilds dependent on each other". I just don't understand what your question is. You said that "ive got a few things im trying", but you didn't say what those things were. How can we help you without knowing what you've already tried?

In addition to the above tutorial, you may find the following helpful:
http://www.tizag.com/mysqlTutorial/mysqlinsert.php
http://mkaz.com/ref/php/db/insert_data.html
http://www.phpf1.com/tutorial/php-mysql ... tml?page=4

Look, Chris, this probably sounds like I'm lecturing you, but that's not my intent. I'd like to help you, but I can't unless you explain what you're trying to do and what you've already tried and what results that produced (error messages? wrong data? no data?).

Programming is a skill that requires very rigorous and logical thinking, and when you communicate with other programmers you have to use very strict terminology to be understood. You can learn to do all that, I'm sure, but the help you get will be quite limited until you do.
Post Reply