Jump to content

Spaces in data that needs to be saved


cliftonbazaar

Recommended Posts

$query = "SELECT * FROM friends";
  $sql_statement = "UPDATE friends SET ";
  $column = "memberName";
  $values = "'$_POST[memberName]'";
  
  if ($result = $mysqli->query($query)) {
    /* Get field information for all columns */
    while ($info = $result->fetch_field()) {
      if($info->name <> 'memberID') {  //If the column isn't memberID
        if($info->name == 'memberName') {  //If the column is the memberName
          $sql_statement .= $info->name."='".$_POST[$info->name]."'";
        } else {  //Put the commas in
          $sql_statement .= ", ".$info->name."='".$_POST[$info->name]."'";
        }
      }
    } 
    $result->close();
  }
  $sql_statement .= " WHERE memberID='$_REQUEST[member]'";

now if I echo the $sql_statement it all works fine - EXCEPT if the data has a space in it, which the Address column nearly always does - if the Address is 'Box 73' it only saves the 'Box' part, how do I get it to save all of the address?

Link to comment
https://forums.phpfreaks.com/topic/215931-spaces-in-data-that-needs-to-be-saved/
Share on other sites

Did you look directly in your database to see what exactly is being saved? If you do, you will find that the data is saved correctly.

 

Your problem is most likely invalid HTML where you output/echo the contents. This problem is usually due to missing quotes around the data value when you output it into form fields.

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.