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;

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.