I'm currently attempting to insert data into a MySQL database using PHP. To help, I am following this tutorial.
Thus far, I have taken the following steps:
- Manually created a database via phpMyAdmin named "core_group_me" on my WAMPSERVER
Created a form page named "form.php" (code below):
<html> <head> <title></title> </head> <body> <form method="post" action="update.php"> Username:<br /> <input type="text" name="id" size="30" /><br /> First Name:<br /> <input type="text" name="firstname" size="30" /><br /> Last Name:<br /> <input type="text" name="lastname" size="30" /><br /> Email:<br /> <input type="text" name="email" size="30" /><br /> Location:<br /> <input type="text" name="location" size="30" /><br /> Expertise:<br /> <input type="text" name="expertise" size="30" /><br /><br /> <input type="submit" value="Update Database" /> </body> </html>Created a page to update the "core_group_me" database named "update.php" (code below):
<?php $id = $_POST['id']; $firstname = $_POST['firstname']; $lastname = $_POST['lastname']; $email = $_POST['email']; $location = $_POST['location']; $expertise = $_POST['expertise']; mysql_connect ("localhost", "core_group_me", "") or die ('Error: ' .mysql_error()); mysql_select_db ("members"); $query="INSERT INTO members (id, firstname, lastname, email, location, expertise)VALUES ('".$id."', '".$firstname."', '".$lastname."', '".$email."', '".$location."', '".$expertise."')"; mysql_query($query) or die ('Error updating database'); echo "Database Updated With: " .$id. " " .$firstname. " ".$lastname. " ".$email. " " .$location. " " .$expertise ; ?>
That being said, when I open up the "form.php" page, input information in the specified fields and submit everything, I receive the the following error: "Error updating database". I'm very new to programming in PHP and working with MySQL databases, so I honestly have absolutely no idea where I've gone wrong. Any help would be much appreciated!
mysql_select_db ("members");command. Is members table in members database?mysql_query($query) or die(mysql_error());?