I'm a rookie with php and my sql and I'm setting up my first users register pulling data from a couple of different mysql tables. I basically want to have one table where admins can create gp practices and then this can be displayed as a dropdown to users when registering.
I want to pull the a field named GPName from gppractices into a drop down on my page which I do using;
<?php $gpquery="SELECT GPName FROM gppractices";
$gpresult=mysql_query($gpquery) or die ("Query to get data from the GP Practice list has failed: ".mysql_error()); ?>
<select name="GPdrop" id="GPdrop">
<?php while ($gprow=mysql_fetch_array($gpresult)) {
$GPName=$gprow["GPName"];
echo '<option id="GPName" value="GPName">'.
$GPName.
'</option>'; } ?>
</select>
I then want to output the selected item into a string which is inserting all info into another table (user);
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "UserDetails")) {
$insertSQL = sprintf("INSERT INTO users (FirstName, LastName, Gender, DOB, UserPractice, Email, UserName, Password, PostCode) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s)",
GetSQLValueString($_POST['FirstName'], "text"),
GetSQLValueString($_POST['LastName'], "text"),
GetSQLValueString($_POST['Gender'], "text"),
GetSQLValueString($_POST['DOB'], "text"),
GetSQLValueString($_POST['Practice'], "text"),
GetSQLValueString($_POST['Email'], "text"),
GetSQLValueString($_POST['UserName'], "text"),
GetSQLValueString($_POST['Password'], "text"),
GetSQLValueString($_POST['PostCode'], "text"));
The problem I have is I can't seem to get the dropdown into the UserPractice column in the database users. I've no idea how to define the index correctly and keep getting the same error.
Notice: Undefined index: Practice in B:\Program Files\XAMMP(new)\htdocs\UserTests\UserRegistration.php on line 78 Column 'UserPractice' cannot be null
I thought I could fix it with something like; $Practice = $_POST['GPdrop'
];
I know I'm a dumb dumb and I'm very new to all this. Still trying to patch things together from tutorials etc but if someone could assist and shed a little light on this for me I'd appreciate it greatly.
The problem is not in the PHP, is in the table, the column 'UserPractice
' requires a value and the variable you are sending ($_POST['Practice']
) is null or empty.
Change your field 'UserPractice
' to allow NULL.
Verify the value before you try to insert it.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments