Not allowing characters after Space. Mysql Insert With PHP

Posted by Jake on Stack Overflow See other posts from Stack Overflow or by Jake
Published on 2011-01-11T03:42:09Z Indexed on 2011/01/11 3:53 UTC
Read the original article Hit count: 209

Filed under:
|
|

Ok so I think this is easy but I dont know (I'm a novice to PHP and MySQL).

I have a select that is getting data from a table in the database. I am simply taking whatever options the user selects and putting it into a separate table with a php mysql insert statement.

But I am having a problem. When I hit submit, everything is submitted properly except for any select options that have spaces don't submit after the first space. For example if the option was COMPUTER REPAIR, all that would get sent is COMPUTER. I will post code if needed, and any help would be greatly appreciated. Thanks!

Ok here is my select code:

<?php
  include("./config.php");
  $query="SELECT id,name FROM category_names ORDER BY name";
  $result = mysql_query ($query);
  echo"<div style='overflow:auto;width:100%'><label>Categories (Pick three that describe your business)</label><br/><select name='select1'><option value='0'>Please Select A Category</option>";
  // printing the list box select command
  while($catinfo=mysql_fetch_array($result)){//Array or records stored in $nt


  echo "<option>$catinfo[name]</option><br/>

 ";

  }

echo"</select></div>";

  ?>

And here is my insert code ( Just to let you know its got everything not just the select!)

?php
    require("./config.php");
    $companyname = mysql_real_escape_string(addslashes(trim($_REQUEST['name'])));
    $phone = mysql_real_escape_string(addslashes($_REQUEST['phone']));
    $zipcode = mysql_real_escape_string(addslashes($_REQUEST['zipcode']));
    $city = mysql_real_escape_string(addslashes($_REQUEST['city']));
    $description = mysql_real_escape_string(addslashes($_REQUEST['description']));
    $website = mysql_real_escape_string(addslashes($_REQUEST['website']));
    $address = mysql_real_escape_string(addslashes($_REQUEST['address']));
    $other = mysql_real_escape_string(addslashes($_REQUEST['other']));
    $payment = mysql_real_escape_string(addslashes($_REQUEST['payment']));
    $products = mysql_real_escape_string(addslashes($_REQUEST['products']));
    $email = mysql_real_escape_string(addslashes($_REQUEST['email']));
    $select1 = mysql_real_escape_string(addslashes($_REQUEST['select1']));
    $select2 = mysql_real_escape_string(addslashes($_REQUEST['select2']));
    $select3 = mysql_real_escape_string(addslashes($_REQUEST['select3']));
    $save=$_POST['save'];
    if(!empty($save)){

    $sql="INSERT INTO gj (name, phone, city, zipcode, description, dateadded, website, address1, other2, payment_options, Products, email,cat1,cat2,cat3)
    VALUES
    ('$companyname','$phone','$city','$zipcode','$description',curdate(),'$website','$address','$other','$payment','$products','$email','$select1','$select2','$select3')";

    if (!mysql_query($sql,$link))
      {
      die('Error: ' . mysql_error());
      }
    echo "<br/><h2><font color='green' style='font-size:15px'>1 business         added</font></h2>";

    mysql_close($link);
}

    ?>

© Stack Overflow or respective owner

Related posts about php

Related posts about mysql