Firstly forgive the use of mysql_*, I appreciate it is depreciated but for completely ridiculous reasons I have to use it for this project.
So I have a dropdown menu populated out of my database with the use of this function
func.php
function artistQuery(){
$myData = mysql_query("SELECT * FROM artists");
while ($record = mysql_fetch_array($myData)){
echo '<option value="' . $record['artistID'] . '">' . $record['artistFirst'] . ' ' . $record['artistSurname'] . '</option>';
}
It populates the drop down menu on:
newprod.php
<h1>New Product Entry:</h1>
<form action="php/addproduct.php" method="_POST">
<p>Please select the artist:</p>
<select name="artist">
<?php artistQuery();
?>
</select>
</form>
So from my function although the first name and surname of the artist are displayed the option value is actually the artistID.
I then use
addproduct.php
<?php
include_once 'php/dbconn.php';
connect();
$artist = $_POST['artist'];
$query = "INSERT INTO products ('artistID') VALUES ('$artist')";
//execute query
$result = mysql_query($query) or die("Error in Query. $query. " . mysql_error());
echo "$artist";
?>
To write the artistID into the database, except it isn't writing.
I am assuming the issue lies somewhere in the newprod.php (Middle block of code) not assigning the artistID to the name of 'artist'.
Any and all help from you wonderful people would be appreciated.
EDIT: Missing letters!
method="post", notmethod="_post". It might get ignored and handled as a GET form.error_reporting(E_ALL); ini_set('display_errors', 1);at the beginning of the scripts. usevar_dump()to analyze your variables (var_dump($_POST);.