Jump to content

posting form data if fields arent filled in or ticked


jesushax

Recommended Posts

hi all my code below, updates my table according to form data it recieves, what ive found out though, if a user unticks a checbox or deltes text in a field, the data is not posted

so a user cant update any checkboxes, is there away that a form can post all its fields even if the field has nothing in it?

 

i know if i put each post in a variable i can do it that way becuase the variable will be empty

but a way for the below code to work, the whole point of my code below was to save me typing out 100s of variables

 

Cheers

 

case "part5";

$ID = $_SESSION["DirectoryID"];

$posts = $_POST;

$SQL = "UPDATE tblDirectory2 SET ";
foreach($posts as $key=>$value){
$SQL .= "`".mysql_real_escape_string($key)."`='".mysql_real_escape_string($value)."', ";
}
$SQL = rtrim($SQL,", ");
$SQL .=" WHERE `CompanyID`='$ID'";

echo "<p>".$SQL."</p>";


mysql_query($SQL) or die (mysql_error());

header("Location: /new_directory/reg_completed.php");
exit();
break;

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.