i am allowing my user to insert either one or 4 checkbox values into one field in my database, and later on want to be able to retrieve this data by doing a query for the each of those words, however, when more than one value is inserted into my field it separates these with a comma, which is fine but how do i seperate the words with a space? so i can later on do a search in my query for values containing 'mechanical' or 'non_mechanical' etc.
heres how it is being stored
mechanical,non_mechanical
also would the comma stop me doing a query for all containing the value of 'mechanical' for example as it would have a comma on the end?
html:
<p>mechanical</p>
<input type="checkbox" id="box1" name="scope_type[]" value="mechanical" onClick="showMore(this);">
<p>Non-Mechanical Hire</p>
<input type="checkbox" id="box1" name="scope_type[]" value="non_mechanical" onClick="showMoreMore(this);">
<p>Tools</p>
<input type="checkbox" id="box1" name="scope_type[]" value="tools" onClick="showMoreMoreMore(this);">
<p>Accessories</p>
<input type="checkbox" id="box1" name="scope_type[]" value="accessories" onClick="showMoreMoreMoreMore(this);">
mysql:
<?php
session_start();
$db_hostname = 'localhost';
$db_database = 'xxxx';
$db_username = 'xxxx';
$db_password = 'xxxx';
$db_server = mysql_connect($db_hostname, $db_username, $db_password)
or die("Unable to connect to MySQL: " . mysql_error());
mysql_select_db($db_database)
or die("Unable to select database: " . mysql_error());
$scope_type = implode(",",$_POST["scope_type"]);
$ipaddress = $_SERVER["REMOTE_ADDR"];
$sql="INSERT INTO supplier_scope (user_ip, scope_type)
VALUES ('$ipaddress', '$scope_type')";
$result = mysql_query($sql);
$sql2="UPDATE supplier_session SET form2_completed = 'Yes' WHERE form2_completed = 'No' AND user_IP = '$ipaddress'";
$result2 = mysql_query($sql2);
if($result){
header("Location: index.php?registration=success");
}else {
echo "ERROR";
}
?>