milla4da8killa Posted June 1, 2008 Share Posted June 1, 2008 Well, I'm still new to PHP and MySQL. The way I've learned everything though before is to jump myself into it...and well, bit harder this time. I get conditional statements, but don't quite yet get how I can get an HTML form to interact with a PHP document, or how to save information into a DB and have it extracted or changed via PHP. So if anyone can really point me to some helpful tutorials or give me some advice or help with the aforementioned, it'd be much appreciated. Quote Link to comment Share on other sites More sharing options...
radar Posted June 1, 2008 Share Posted June 1, 2008 when you have an HTML form you can access those variables via $_POST then to insert into a database do something like this: $sql = "INSERT INTO users SET d_id = '".$id."', f_name = '".$_POST['fname']."', l_name = '".$_POST['lname']."', d_name = '".$_POST['dname']."', email = '".$_POST['email']."', password = '".$_POST['password']."', date_added = now(), status = '1'"; mysql_query($sql); to select stuff from the database you can do it a few ways.. SELECT * FROM users will get everything inside my users table.. SELECT * FROM users WHERE username = 'myname' will get only where username is myname.. then to update which is very similar to my initial insert: $sql = "UPDATE contact SET Address = '$_POST[address]', Telephone = '$_POST[phone]', Fax = '$_POST[fax]', Misc = '$_POST[misc]'"; mysql_query($sql); hope it helps some? Quote Link to comment Share on other sites More sharing options...
milla4da8killa Posted June 1, 2008 Author Share Posted June 1, 2008 ok, so it would be like <form action="http://blah.com/meh_page.php" method=post> and the php would be...? Sorry, I'm extremely noobish to this stuff. I'm fine with HTML though, lol. Some of the stuff's clicking but this kind of stuff ain't. What excactly would be in the php document? $_POST('blah') to retreive name=blah from the HTML form? Quote Link to comment Share on other sites More sharing options...
whizard Posted June 1, 2008 Share Posted June 1, 2008 say you have a simple form with one field (to keep it simple) <form action="parse.php" method="post"> <input type="text" name="sampleField" /> <input type="submit" name="submit" value="submit" /> </form> When the user clicks the submit button the browser sends the value(s) in the field(s) back to the server as POST values. Each value is held in a variable which is named after the name of the field. So, in the above instance, the name of the text field was "sampleField", and you can access it in PHP through the variable $_POST['sampleField']. In other words the $_POST is an associative array which holds all the values submitted by the form (in this case sampleField and submit). So to process this in the PHP file parse.php, you would use something similar to the following: <?php //First step: check to see if the form has been submitted or if someone just came here by direct URL if(isset($_POST['submit'])) { //process the form //here is how we get the value from the form $sampleFieldValue = $_POST['sampleField']; //now to insert into the database - assumes you've already connected //Create the query $query = "INSERT INTO `table` (columnName) VALUES ($sampleFieldValue)"; //Run the query or return the mysql error msg on failure $result = mysql_query($query) or die(mysql_error()); } else { //send them to the form header("Location: form.html"); } ?> I hope that helped a little. If you have any questions, feel free to ask them! Dan Quote Link to comment Share on other sites More sharing options...
milla4da8killa Posted June 1, 2008 Author Share Posted June 1, 2008 Yup! Thanks a bunch man. Quote Link to comment Share on other sites More sharing options...
radar Posted June 1, 2008 Share Posted June 1, 2008 Note: the way he created his insert in his sample can get quite weird, i used to do it that way but when you have a 90 column table you have to insert something into, it makes it easier to do your insert like i did mine... Makes it easier to read, and easier to find an error... Quote Link to comment Share on other sites More sharing options...
milla4da8killa Posted June 1, 2008 Author Share Posted June 1, 2008 Ok, so got that all down now. Thanks for help! New question. I'm using phpWebsite as the base for the website basically but I'm planning on adding a lot to it (like I said, drop myself into it). Making a money code which I'll add to the DB but I'm having issues finding the DB? Can someone help me with that? File name and location? I think once I got that done along with a few other things I'll be about good to go. Quote Link to comment Share on other sites More sharing options...
radar Posted June 1, 2008 Share Posted June 1, 2008 You should be using a MySQL database if i am not mistaking... @ which case you would do something like this: $this->sql_db('server', 'username' , 'password', 'database'); which is what I do in my case.. for you, you might have to do like this: mysql_connect('server', 'username', 'password'); mysql_select_db('database'); at the top of your code... -- Radar Quote Link to comment Share on other sites More sharing options...
milla4da8killa Posted June 1, 2008 Author Share Posted June 1, 2008 So do I need to make a new database? Cause I was hoping to be able to simply add the information to the current DB with their username, group, password, etc. for the add ons I plan on making. In which case, if I need to make a newer DB to store that info, should I make variable $player_name = SELECT * FROM and then the DB with their usernames and passwords? Or is there another way to do this? Quote Link to comment Share on other sites More sharing options...
radar Posted June 1, 2008 Share Posted June 1, 2008 No you dont need to make a new database, just a new table with all of the fields you want.. no need for multiple databases... Quote Link to comment Share on other sites More sharing options...
milla4da8killa Posted June 1, 2008 Author Share Posted June 1, 2008 You wouldn't happen to know as to where I can find the db that's there already? Or should I just be able to make a creat enew table thing in php (I have that somewhere I believe, forgot what it is though.) Quote Link to comment Share on other sites More sharing options...
milla4da8killa Posted June 1, 2008 Author Share Posted June 1, 2008 Argh, can't seem to find the DB. It is a file right? And what extension will it be? Name? etc. Quote Link to comment Share on other sites More sharing options...
radar Posted June 2, 2008 Share Posted June 2, 2008 No databases arent a file. At least not a file thats in your file structure, if your host is any sort of a host (i am a host so i know), they have PHPMyAdmin, which is the greatest tool when working with databases. When I am working on a website I have 5 tabs open.. 1. front end of the site 2. admin side of the site 3. phpmyadmin 4. cpanel 5. google So check and see if you have phpmyadmin, if you do that is where you can add tables (you can do it in PHP too), if you have a cpanel you should be able to check your database and any users you have... If you dont have cpanel or phpmyadmin you might want to look into getting a new host (if you have a domain).. -- Radar Quote Link to comment Share on other sites More sharing options...
milla4da8killa Posted June 2, 2008 Author Share Posted June 2, 2008 I'm running as a user off of CPanel but it isn't my website so I don't have direct access into it. I also don't have HMyAdmin as I tried isntalling but it wouldn't accet because of the hosting structure. =/ And Yeah, I do the same here with having admin, cpanel/phpmyadmin and the website open all at once. I'll talk to him and see what I can do. It's got a database for where the PHPwebsite coding is stored and I do have access to that, but that's about it. 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.