How to pull info from a dynamic dropdown of array to post in another table

Meeps

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.

JuanSedano

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.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Using jQuery to pull info from a dropdown and creating a div with that info

From Dev

Using jQuery to pull info from a dropdown and creating a div with that info

From Dev

MS Access ?: How to pull information into a table from another linked table

From Dev

How to insert into a table new records based on info from another table?

From Dev

Creating a table with info from another table

From Dev

How to get value of dropdown list from dynamic array?

From Dev

How to pull info from a string and output it?

From Dev

How to create a dynamic table from another table's data in SQL

From Dev

How to load a table, from another webpage, into an array?

From Dev

$pull object from array, and $pull references in another array

From Dev

$pull object from array, and $pull references in another array

From Dev

Pull field from another table in MVC

From Dev

Pull field from another table in MVC

From Dev

Pull data from one table to another

From Dev

Parsing A Table In Google Sheets, Then Storing All Matching Rows Data In An Array I Can Pull Info From (GAS/JavaScript)

From Dev

Move elements from $pull to another array

From Dev

Move elements from $pull to another array

From Dev

How can a dropdown list be displayed at a dynamic table?

From Dev

laravel, displaying data on a dropdown from another table

From Dev

I have a stored procedure that needs to pull info from the same table twice. How do I use Correlation Names?

From Dev

I have a stored procedure that needs to pull info from the same table twice. How do I use Correlation Names?

From Dev

Displaying info an array of arrays from an API as a table

From Dev

store info and pull out in array

From Dev

How to post the result of this dropdown into an sql table?

From Dev

How to pull data from sql, add columns to a row and insert it into another sql table?

From Dev

In Access, how can I pull data from another table by matching a field?

From Dev

How to pull curl_exec info from string

From Dev

How can I pull user info for posts from two tables?

From Dev

Inserting into table from dropdown using data from another table

Related Related

  1. 1

    Using jQuery to pull info from a dropdown and creating a div with that info

  2. 2

    Using jQuery to pull info from a dropdown and creating a div with that info

  3. 3

    MS Access ?: How to pull information into a table from another linked table

  4. 4

    How to insert into a table new records based on info from another table?

  5. 5

    Creating a table with info from another table

  6. 6

    How to get value of dropdown list from dynamic array?

  7. 7

    How to pull info from a string and output it?

  8. 8

    How to create a dynamic table from another table's data in SQL

  9. 9

    How to load a table, from another webpage, into an array?

  10. 10

    $pull object from array, and $pull references in another array

  11. 11

    $pull object from array, and $pull references in another array

  12. 12

    Pull field from another table in MVC

  13. 13

    Pull field from another table in MVC

  14. 14

    Pull data from one table to another

  15. 15

    Parsing A Table In Google Sheets, Then Storing All Matching Rows Data In An Array I Can Pull Info From (GAS/JavaScript)

  16. 16

    Move elements from $pull to another array

  17. 17

    Move elements from $pull to another array

  18. 18

    How can a dropdown list be displayed at a dynamic table?

  19. 19

    laravel, displaying data on a dropdown from another table

  20. 20

    I have a stored procedure that needs to pull info from the same table twice. How do I use Correlation Names?

  21. 21

    I have a stored procedure that needs to pull info from the same table twice. How do I use Correlation Names?

  22. 22

    Displaying info an array of arrays from an API as a table

  23. 23

    store info and pull out in array

  24. 24

    How to post the result of this dropdown into an sql table?

  25. 25

    How to pull data from sql, add columns to a row and insert it into another sql table?

  26. 26

    In Access, how can I pull data from another table by matching a field?

  27. 27

    How to pull curl_exec info from string

  28. 28

    How can I pull user info for posts from two tables?

  29. 29

    Inserting into table from dropdown using data from another table

HotTag

Archive