I have a PHP script that shows an input form, then passes the input field values to a MySQL script that is an INSERT INTO command. The table is updated, but the fields are all blank! I'm posting this here, because I'm not sure if it's a MySQL problem, or a PHP problem. If someone could point me in the right direction, I'd appreciate it. There are 3 fields in the record, authorid, which is an auto-increment key, that value is being populated correctly. The lname and fname fields are both blank. The code is below:
The echo statements output:
Any and all assistance is greatly appreciated. Also, please let me know if this should be posted in the PHP board instead.
Thank you.
Code:
<?php
//leads_process_page.php - Updated: TUESDAY JUNE 30, 2009 - 5:57 PM
// Originally - delete_or_update_leads.php
include('dbconnect.php');
//
$option=$_POST['process_what'];
//
if ($option == "author") {
//
$record_key=$_POST['authorid'];
//
$var1 = ($_POST['formoption']);
[b][COLOR=blue]echo "formoption: $formoption<br>";
echo "lname: $lname<br>";
echo "fname: $fname<br>";[/color][/b]
switch($_POST['formoption']) {
[b][COLOR=red] case 'Add':
$lname = $_POST['lname'];
$fname = $_POST['fname'];
//
$query2 ="INSERT INTO MYAUTHORS (authorid, lname, fname)
VALUES ('0','$lname', '$fname')";
//
$result = mysql_query($query2);
$rows=mysql_affected_rows();
if (!$result) {
echo "<b>Update Failed:</b> <br>" . mysql_error();
echo "<br>Whole query: " . $query2 . "<br>";
die;
} else {
[b][COLOR=green] echo "rows: $rows<br>";
echo "authorid: $authorid<br>";
echo "lname: $lname<br>";
echo "fname: $fname<br>";[/color][/b]
}
// include('leads_message_display.php');
break;[/color][/b]
case 'Delete':
$query ="DELETE from MYAUTHORS where authorid_name = '$record_key'";
$result = mysql_query($query);
$rows=mysql_affected_rows(); // returns number of rows produced by query.
if (!$result) {
$message = 'Invalid query: ' . mysql_error() . "\n";
$message .= 'Whole query: ' . $query;
die($message);
} else {
// if ($rows > 0) {
// echo "$rows record(s) deleted.<br>";
// } else {
// echo "Record not found.<br>";
// }
include('leads_message_display.php');
}
// include('query_check.php');
break;
case 'Update':
echo "Update 2";
break;
case 'Search':
//
$query = "SELECT * FROM MYAUTHORS where authorid_name = '$record_key'";
//
$result = mysql_query($query);
//
$rows=mysql_affected_rows(); // will return the number of rows produced by the query.
if (!$result) {
$message = 'Invalid query: ' . mysql_error() . "\n";
$message .= 'Whole query: ' . $query;
die($message);
} else {
while ($_POST = mysql_fetch_array($result, MYSQL_ASSOC)) {
$id = $_POST['id'];
$authorid = $_POST['authorid_name'];
$title = $_POST['title'];
$type = $_POST['type'];
$cover_type = $_POST['cover_type'];
$pages = $_POST['pages'];
$copyright = $_POST['copyright'];
$date_finished = $_POST['date_finished'];
$has_been_finished = $_POST['has_been_finished'];
}
}
include('leads_message_display.php');
break;
default:
echo "Default";
}
}else{
echo "Process Book";
}
?>
The echo statements output:
Code:
[b][COLOR=blue]
formoption: Add
lname: Kellerman
fname: Jonathan[/color][/b]
[b][COLOR=green]rows: 1
authorid:
lname: Kellerman
fname: Jonathan[/color][/b]
Any and all assistance is greatly appreciated. Also, please let me know if this should be posted in the PHP board instead.
Thank you.