Hey guys - would you mind looking over this and telling me why it keeps telling me 'username' column cannot be null?
Username is my primary key (I also have an auto-increment user id - could possibly change it but since I'm working with multiple tables, I'd like to keep it the same).
I have a form that lets user put in email address and all of the other columns, and I was letting them create a username in a separate field, but client wants their email to be their username, so I thought it would be a simple fix to delete the field and modify my query to insert $_POST['email'] to the username column. But, it keeps failing to insert, saying that 'username' cannot be null.
Here is the code:
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "applForm")) {
$insertSQL = sprintf("INSERT INTO user_info (username, name, address, city, state, country, postalcode, homephone, phone1, busmobphone, phone2, fax, email, dob, age, sex, notes) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
GetSQLValueString($_POST['email'], "text"),
GetSQLValueString($_POST['name'], "text"),
GetSQLValueString($_POST['address'], "text"),
GetSQLValueString($_POST['city'], "text"),
GetSQLValueString($_POST['state'], "text"),
GetSQLValueString($_POST['country'], "text"),
GetSQLValueString($_POST['postalCode'], "text"),
GetSQLValueString($_POST['hPhone'], "text"),
GetSQLValueString($_POST['phone1'], "text"),
GetSQLValueString($_POST['oPhone'], "text"),
GetSQLValueString($_POST['phone2'], "text"),
GetSQLValueString($_POST['fax'], "text"),
GetSQLValueString($_POST['email'], "text"),
GetSQLValueString($_POST['dob'], "date"),
GetSQLValueString($_POST['age'], "int"),
GetSQLValueString($_POST['sex'], "text"),
GetSQLValueString($_POST['notes'], "text"));
Then this is my form (comes out a little messy in this code editor; sorry):
<form action="<?php echo $editFormAction;?>" method="POST"
enctype="multipart/form-data" name="applForm"
id="applForm"> Applicant Information
<div class="row"> <span class="label required">Name:</span>
<span class="formw"> <input name="name"
id="name" size="45" maxlength="45" type="text" /></span></div>
<div class="row"> <span class="label required">Mailing
Address:</span> <span class="formw"> <input
name="address" id="address" size="45" type="text" />
</span> </div>
<div class="row"> <span class="label required">City:</span>
<span class="formw"> <input name="city"
id="city" size="45" type="text" /> </span></div>
<div class="row"> <span class="label required">State:</span>
<span class="formw"> <select name="state"
id="state"/>
<option value="0">Choose a state</option>
<?php echo showOptionsDrop($states_arr); ?>
</select> </span></div>
<div class="row"> <span class="label required">Country:</span>
<span class="formw"> <input name="country"
id="country" size="45" type="text" /> </span></div>
<div class="row"> <span class="label required">Postal
Code:</span> <span class="formw"> <input
name="postalCode" id="postalCode" size="15"
type="text" /> </span> </div>
<div class="row"> <span class="label required">
Phone 1:</span> <span><select name="phone1" id="phone1"/><option value="0">Please select</option>
<?php echo showOptionsDrop2($phone_arr); ?>
</select><class="formw"> <input
name="hPhone" id="hPhone" size="15" type="text" />
</span> </div>
<div class="row"> <span class="label">
Phone 2:</span> <span><select name="phone2" id="phone2"/><option value="0">Please select</option>
<?php echo showOptionsDrop2($phone_arr); ?>
</select><class="formw"> <input
name="oPhone" id="oPhone" size="15" type="text" />
</span> </div>
<div class="row"> <span class="label">Fax:</span>
<span class="formw"> <input name="fax"
id="fax" size="15" type="text" /> </span></div>
<div class="row"> <span class="label required">Email:</span>
<span class="formw"> <input name="email"
id="email" size="45" type="text" /> </span></div>
<div class="row"> <span class="label required">Date
of Birth:</span> <span class="formw"> <input
name="dob" id="dob" size="15" type="text" />
</span> </div>
<div class="row">
<p><span class="label required">Age:</span> <span
class="formw"> <input name="age" id="age"
size="2" type="text" /> </span></p>
<p> </p>
</div>
<div class="row"> <span class="label required">Sex:</span><span
class="formw"> <input name="sex" value="M"
type="radio" /> Male<input name="sex" value="F"
type="radio" />Female </span></div>
<label for="sex" class="error"><br />
Please select gender.</label>
<br/>
<div class="row"> <span class="label required">Please
create a Password:</span><span class="formw"><input
name="password" id="password" type="VARCHAR" /></span>
</div>
<p></p>
<p> </p>
<div class="row"> <span class="label ">Notes:</span><span class="formw"><textarea
name="notes" id="notes" type="VARCHAR" /></textarea></span>
</div>
<div class="row" style="text-align: center;"> <input
class="submitBtn" name="Submit" value="Submit"
id="Submit" type="submit" /><input
class="submitBtn cancel" name="Cancel" value="Cancel"
type="submit" />
</div>
<input type="hidden" name="MM_insert" value="applForm" />
</form>
Thanks - hope I'm not the only one with nothing better to do on a Saturday night! :-)