Note that there are some explanatory texts on larger screens.

plurals
  1. POInserting form values with spaces into mysql 4.1
    text
    copied!<p>I'm trying to insert form data into a MySQL 4.1 DB. The problem I'm having is form fields that include spaces get truncated before insertion. The POST variables are complete, spaces and all. Just being cut off somewhere. For instance, "South Lake Tahoe" is inserted simply as "South". Zip codes and telephone numbers with dashes are also fine. The site I'm working on is hosted by Yahoo Small Business, and they're still using MySQL 4.1. I don't know if that is the problem, but I do know I never had issues doing this with MySQL 5+. The user fills out a form to add a new member. Upon Submit, the form data is POSTED to another page for processing:</p> <pre><code>$k = array(); $v = array(); $first_name = $_POST['first_name']; $last_name = $_POST['last_name']; $result = mysql_query("SELECT * FROM members WHERE first_name='$first_name' AND last_name='$last_name'"); if(mysql_num_rows($result)&gt;0){ mysql_free_result($result); exit("Duplicate User in Database"); } mysql_free_result($result); array_pop($_POST);//Don't need the Submit value foreach($_POST as $key=&gt;$value){ array_push($k, "$key"); array_push($v, "$value"); } $fields = implode(", ", $k); $values = array(); foreach($v as $key=&gt;$value){ array_push($values, '"'.$value.'"'); } $values_string = implode(", ", $values); $result = mysql_query("INSERT INTO members($fields) VALUES($values_string)"); </code></pre> <p>I'm sure there are better ways of doing this, but I'm still on the way up the learning curve. Please point out any obvious flaws in my thinking. Any suggestions are greatly appreciated.</p> <p>EDIT: The field types in MySQL are correct and long enough. For example, the field for City is set as VARCHAR(30).</p> <p>Thanks much, Mark</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload