PHP contact form - displaying the last updated record

thanks for all the help so far. PHP errors aren’t very user friendly!
I have been able to update the contact information to the Database.
Now I’d like to select the last record updated using mysql_insert_id()
and once I get that working, display it nicely in a table. Now I’m getting
the error

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result

include ‘db_connect.php’;
$sql = “INSERT INTO dealers (company, lastname, firstname, middlename, email, notes) VALUES (‘$company’, ‘$lastname’, ‘$firstname’, ‘$middlename’, ‘$email’, ‘$notes’)”;

if ( ! mysql_query($sql, $conn))
{
die('Error: ’ . mysql_error());
}

else
{

include ‘db_connect.php’;
$lastidaddedsql = mysql_query(“SELECT company, lastname, firstname, middlename, email, notes FROM dealers WHERE dealerid=mysql_insert_id()”);
$result=mysql_query($lastidaddedsql);
while ($row = mysql_fetch_array($result, MYSQL_BOTH))
{
echo $row;
echo "Email : ".$row[‘email’];
echo "field : ".$row[‘2’];
}

echo “------------------------------------------------------------”;
echo $row=mysql_fetch_array($result);
echo “<br><br>”;
echo “<br><br>”;
echo $sql;
echo “<br><br>”;
echo 'LAST_INSERT_ID: ‘, mysql_query( “SELECT LAST_INSERT_ID()” ),’<br>mysql_insert_id: ‘,mysql_insert_id();
echo “<br><br>”;
echo ‘<p>’ . mysql_affected_rows($conn) . ’ record added.</p>’;
}
mysql_close($conn);

?>

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result

This almost 100% of the time means “Your query failed. Go take a look at it.”

And I can see why.
“SELECT company, lastname, firstname, middlename, email, notes FROM dealers WHERE dealerid=mysql_insert_id()

Woah there.
Double-Quoted strings will unfurl VARIABLES correctly - but they wont execute functions (functions are things with ()'s at the end, variables start with $)
Try this instead:


$lastidaddedsql = mysql_query("SELECT company, lastname, firstname, middlename, email, notes FROM dealers WHERE dealerid=".mysql_insert_id());

PS: Not entirely sure why you’re doing this select, since it will just retrieve the values you already have stored in the variables $company, $firstname, etc…