Hello. I just started learning PHP. I'm also not very good at programming :(
I want to add a new member to a table in my database. The table is set up so that the person_id is an automatically incremented number (so with each new member added, the person_id is +1 from the previous person_id). I don't know how to add the information I pull off a form from a webpage to the database. I keep getting an error telling me that it's unable to insert into the database. Everything I have is set up on localhost using Windows XP IIS 5.0 and MySQL Server. I made a screencap of the ER-diagram I drew of my database. I'm only using the member and person tables for now (I think):
http://img105.imageshack.us/img105/2056/db1do.jpg. Please let me know what I did wrong, or if you need more information. Thank you.
Partial coding:
--------------------------
----------
----------
----------
---
...
if ($isPostback) {
$username = getRequestValue("username"
);
$password = getRequestValue("password"
);
$firstname = getRequestValue("firstname
");
$middlename = getRequestValue("middlenam
e");
$lastname = getRequestValue("lastname"
);
$employer = getRequestValue("employer"
);
$graduation_date = getRequestValue("graduatio
n_date");
$subnewsletter = getRequestValue("subnewsle
tter");
$validated = true;
if ($validated) {
// $staff_id = $_SESSION["LoggedOnPersonI
d"];
$sql = "INSERT INTO person (NULL, username, password, firstname, middlename, lastname) VALUES ";
// person_id is supposed to be on auto-increment
$sql = $sql."('NULL', '$username', '$password', '$firstname', '$middlename', '$lastname')";
$sql = "INSERT INTO member (employer, NULL, graduation_date, NULL, subnewsletter, firstname, middlename, lastname, NULL,) VALUES ";
// person_id is supposed to be on auto-increment
$sql = $sql."('$employer', 'NULL', '$graduation_date', 'NULL', '$subnewsletter', '$firstname', '$middlename', '$lastname', 'NULL', )";
//echo($sql);
$conn = getConnection();
if (mysql_query($sql, $conn)) {
$feedback = "Activity inserted into database successfully.";
}
else {
$feedback = "Error, unable to insert record into database.";
}
}
else {
$feedback = "Invalide input.";
}
}
?>
...
<form name="form1" method="post">
<p><strong>Member Entry Form </strong></p>
<table border="0">
<!-- This gathers information for the person table. -->
<tr>
<th>UserName:</th>
<td><input name="username" id="username"><?php echo(getRequestValue("user
name"))?><
/td>
</tr>
<tr>
<th>Password:</th>
<td><input name="password" id="password"><?php echo(getRequestValue("pass
word"))?><
/td>
</tr>
<tr>
<th>First Name:</th>
<td><input name="firstname" id="firstname"><?php echo(getRequestValue("firs
tname"))?>
</td>
</tr>
<tr>
<th>Middle Name:</th>
<td><input name="middlename" id="middlename"><?php echo(getRequestValue("midd
lename"))?
></td>
</tr>
<tr>
<th>Last Name:</th>
<td><input name="lastname" id="lastname"><?php echo(getRequestValue("last
name"))?><
/td>
</tr>
<tr>
<th>Employer:</th>
<td><input name="employer" id="employer"><?php echo(getRequestValue("empl
oyer"))?><
/td>
</tr>
<tr>
<th>Graduation Date:</th>
<td><input name="graduation_date" id="graduation_date"><?php
echo(getRequestValue("grad
uation_dat
e"))?></td
>
</tr>
<tr>
<th>Subscribe Newsletter:</th>
<td><input name="subnewsletter" id="subnewsletter"><?php echo(getRequestValue("subn
ewsletter"
))?></td>
</tr>
</table>
<br>
<input type="submit" name="Submit" value="Submit">
<input type="reset" name="Submit2" value="Clear">
<p align="center"> </p>
</form>
...
Start Free Trial