Jump to content

Recommended Posts

Another quick question :)

 

I have a set up a basic database management system for my website where I can update database entires via a form. A few of my fields for each row do not require data (i.e. the membership expiry date is blank for a member who has not yet paid.)

When I edit a row (that has blank fields) and submit the changes the fields such as the date have been replaced with "0000-00-00".

 

Is there any way I can stop this from happening? I need blank fields to be left blank, other wise my "WHERE ExpiryDate<CURRENT_DATE" condition gets messed up.

 

Cheers for any info.

Link to comment
https://forums.phpfreaks.com/topic/81120-blank-fields/
Share on other sites

Can we see the UPDATE or INSERT statement that processes your form?

 

Umm i'll just post the body of it:

 

if ($submit) {

  // here if no ID then adding else we're editing

  if ($id) {

    $sql = "UPDATE FBI_Applications SET Name='$Name',Email='$Email',Phone='$Phone',Address='$Address' ,ForumUsername='$ForumUsername' ,Paid='$Paid' ,Dispatched='$Dispatched' ,MembershipNumber='$MembershipNumber' ,Expire='$Expire' WHERE id=$id";

  } else {

    $sql = "INSERT INTO FBI_Applications (Name,Email,Phone,Address,ForumUsername,Paid,Dispatched,MembershipNumber,Expire) VALUES ('$Name','$Email','$Phone','$Address','$ForumUsername','$Paid','$Dispatched','$MembershipNumber','$Expire')";

  }

  // run SQL against the DB

  $result = mysql_query($sql);

  echo "Record updated!<p>";

} elseif ($delete) {

// delete a record

    $sql = "DELETE FROM FBI_Applications WHERE id=$id";	

    $result = mysql_query($sql);

    echo "$sql - Record deleted!<p>";

} else {

  // this part happens if we don't press submit

  if (!$id) {

    // print the list if there is not editing

    $result = mysql_query("SELECT * FROM FBI_Applications",$db);

    while ($myrow = mysql_fetch_array($result)) {

      printf("<a href=\"%s?id=%s\">%s</a> \n", $PHP_SELF, $myrow["id"], $myrow["ForumUsername"]);

  printf("<a href=\"%s?id=%s&delete=yes\">(DELETE)</a><br>", $PHP_SELF, $myrow["id"]);

    }

  }



  ?>

  <P>

  <a href="<?php echo $PHP_SELF?>">Add Record</a>

  <P>

  <form method="post" action="<?php echo $PHP_SELF?>">

  <?php



  if ($id) {

    // editing so select a record

    $sql = "SELECT * FROM FBI_Applications WHERE id=$id";

    $result = mysql_query($sql);

    $myrow = mysql_fetch_array($result);

    $id = $myrow["id"];

    $Name = $myrow["Name"];

    $Email = $myrow["Email"];

    $Phone = $myrow["Phone"];

    $Address = $myrow["Address"];

    $ForumUsername = $myrow["ForumUsername"];

    $Paid = $myrow["Paid"];

    $Dispatched = $myrow["Dispatched"];

$MembershipNumber = $myrow["MembershipNumber"];

$Expire = $myrow["Expire"];

Link to comment
https://forums.phpfreaks.com/topic/81120-blank-fields/#findComment-419269
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.