same NOOB new problem (adding to database)



sorry about this but i have been trying to spot mistakes and i dont kno where i have gone wrong! I have been trying to follow an online help manual but its crap! :(

Im trying to add into a database using a HTML form. Below is the code i am using. I dont get any errors but when i check the database nothing is added.

The code for the HTML page is:

<title>Clubboss - Add a Member</title><form action="insert.php" method="post">
First Name: <input type="text" name="first name"><br>
Last Name: <input type="text" name="second name"><br>
Forum Name: <input type="text" name="forum name"><br>
Phone: <input type="text" name="phone number"><br>
Mobile: <input type="text" name="mobile number"><br>
Email: <input type="text" name="email address"><br>
Expire: <input type="text" name="membership expire"><br>
  Insurance provider: 
  <select name="select" size="1">
    <option selected>please select</option>
insurance number: <input type="text" name="insurance number"><br>
Insurance expire: <input type="text" name="insurance expire"><br>
<input type="Submit">

The included insert.php page is:
@mysql_select_db($database) or die( "Unable to select database"); 

$query = "INSERT INTO 'members' VALUES ('','$first name','$second name','$forum name','$phone number','$mobile number','$email address','$membership expire','$insurance provider','$insurance number','$insurance expire')";


Once agian any help would be great!
Several problems here. First, your field names should have any spaces in them. Ergo, "first name" should be "first_name". Second, if you're using POST to submit the form, then you need to use the superglobal $_POST to get the value, e.g. $_POST['first_name']. Likewise, if you use the GET method, you should use $_GET.
that was quick! Can i just ask wont the form not work at all if i use underscores instead of spaces since my fields have spaces in them? Also following the usless manual wont the INSERT command work :-o . Do you have an example of the glocal $_post command so that i can learn about it?

I dont ask much do i? LOL. Thanks very much, I will make the alterations now.
thats really helpful thanks! I was looking into buying a book but you can never be sure which ones to get because some are plainly to complicated of newbies.

I will have a go at editing the second page as you suggested now.
i have done what you said and i get no error messages and the form definately does something but nothing is added to my table :-o .
I have checked through for errors and i dont think that there are any (nothing as daft as last time)

@mysql_select_db($database) or die( "Unable to select database"); 

$first_name = $_POST['first_name'];
$second_name = $_POST['second_name'];
$forum_name = $_POST['forum_name'];
$phone_number = $_POST['phone_number'];
$mobile_number = $_POST['mobile_number'];
$email_address = $_POST['email_address'];
$membership_expire = $_POST['membership_expire'];
$insurance_provider = $_POST['insurance_provider'];
$insurance_number = $_POST['insurance_number'];
$insurance_expire = $_POST['insurance_expire'];

$query = "INSERT INTO 'members' VALUES ('','$first_name','$second_name','$forum_name','$phone_number','$mobile_number','$email_address','$membership_expire','$insurance_provider','$insurance_number','$insurance_expire')";


Do i have to change the field names on the actual table? They are actually called things like 'first name' instead of 'first_name'.

I keep hunting for that book...
I don't think that should be a problem.

try echoing the result of mysql_error(); That should shed some light on the situation.
this is what is says:

You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near ''members' VALUES ('','dsfsdf','sdfsdfdsf','fdsfsdf','sdfsdf','d

the jumbled letters are what i have put in as just anything to be added to the table members. Hope that this helps!
is your Membership Number field auto_increment in your database?
Is it is, then why are you asking users to enter that number?

Although it seems if users enter that number, it goes to their FIRST NAME

Also dont forget that users can simply add EMPTY records into your database, so check all the fields (or req. ones) if they are empty or not then try to insert them into your database.

Again if you want to have a complete job, search this forum for database security to see how you can delete illegal characters from user inputs so they cannot hack your database.

Good luck
thanks for the security tip, I am looking into it further. I have not got membership number set to auto incrament. I checked the database itself and it is wrong there too! I have spent the last 2 hours trying to work out whats wrong but i havent had any luck... Its like everything needs putting to the left in the table.

Also I have found that since the input is going wrong it is messing up my Id feild by inserting the expirey date into that field. The ID field is not shown since that is purely for the database. The membership number refers to the club. Any other ideas?