•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 391,609 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,626 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 855 | Replies: 8 | Solved
![]() |
•
•
Join Date: Apr 2008
Posts: 31
Reputation:
Rep Power: 1
Solved Threads: 0
Hi I have a form and I have a list of checkboxes I am trying to check 2 or all of them and get them to insert into one sql column in my database. When I select them it submits ok but in the cloumn on the database is storing it as Array not the values I have checked.
Here is the form and the code.
the submit file
Any help with this wil be appreciated
Here is the form and the code.
<form name="padform" method="post" action="catsubmit.php" />
<input name="userID" type="hidden" id="userID" value="<?=$userID?>">
<table width="540" cellspacing="3" cellpadding="0" border="0">
<tr>
<td width="300" id="t_category1">
<input type="checkbox" name="vccategory[]" value="Quality Control & Consultants">Quality Control & Consultants</td></tr>
<tr>
<td><input type="checkbox" name="vccategory[]" value="Quilting Materials & Supplies">Quilting Materials & Supplies</td></tr>
<tr>
<td><input type="checkbox" name="vccategory[]" value="Quilts & Quilting">Quilts & Quilting</td></tr>
<tr>
<td><input name="submit" type="submit" class="button" value="Submit Ad" /><input class="button" type="reset" name="reset" value="Reset" /></td>
</tr>
</table>
</form>the submit file
<?
session_start();
error_reporting(apsolutions);
?>
<?PHP
include("../secure/global/connection.php");
include("../secure/global/mail.class.php");
error_reporting(7);
$vccategory = ($_POST['vccategory']);
$intUserID = ($_POST["userID"]);
{
$insertsql = " insert into tbladvertdetails (intUserID, vccategory, dtCreatedOn) values ('".addslashes($intUserID)."','".addslashes($vccategory)."','".date("Y-m-d h:m:s")."')";
$DB_site->query($insertsql);
$accountid = mysql_insert_id();
}
?>
<script>
alert("Profile UPdated")
document.location.href="adcat.php"
</script>Any help with this wil be appreciated
•
•
Join Date: Jun 2008
Location: Phoenix, AZ
Posts: 534
Reputation:
Rep Power: 2
Solved Threads: 50
right, because you are submitting it as an array and trying to enter it directly in the db that way.
When you say
Your output will be just "array".
The following will process the array and create a comma separated list of selected values.
When you say
$array = array("val1", "val2");
echo $array;The following will process the array and create a comma separated list of selected values.
$vccategory = "";
foreach($_POST['vccategory'] as $value)
{
$vccategory .= $value . ", ";
}
$vccategory = substr($vccategory, 0, -2); //to get rid of the final ", " Last edited by R0bb0b : Jun 14th, 2008 at 11:09 am.
•
•
Join Date: Apr 2008
Posts: 31
Reputation:
Rep Power: 1
Solved Threads: 0
Yes you are right i managed to just solved the problem myself quite simple really this is what i used it posts all the values to the database now here is the updated version of my script for others to use.
the submit script
hope this helps someone in the future
<form name="padform" method="post" action="catsubmit.php" />
<input name="userID" type="hidden" id="userID" value="<?=$userID?>">
<table width="540" cellspacing="3" cellpadding="0" border="0">
<tr>
<td width="300" id="t_category1">
<input type="checkbox" name="vccategory[]" value="Quality Control & Consultants">Quality Control & Consultants</td></tr>
<tr>
<td><input type="checkbox" name="vccategory[]" value="Quilting Materials & Supplies">Quilting Materials & Supplies</td></tr>
<tr>
<td><input type="checkbox" name="vccategory[]" value="Quilts & Quilting">Quilts & Quilting</td></tr>
<tr>
<td><input name="submit" type="submit" class="button" value="Submit Ad" /><input class="button" type="reset" name="reset" value="Reset" /></td>
</tr>
</table>
</form>the submit script
<?
session_start();
error_reporting(apsolutions);
?>
<?PHP
include("../secure/global/connection.php");
include("../secure/global/mail.class.php");
error_reporting(7);
$vccategory = ($_REQUEST['vccategory']);
$intUserID = ($_POST["userID"]);
{
$insertsql = " insert into tbladvertdetails (intUserID, vccategory, dtCreatedOn) values ('".addslashes($intUserID)."','".addslashes($vccategory[0]).",".addslashes($vccategory[1]).",".addslashes($vccategory[2])."','".date("Y-m-d h:m:s")."')";
$DB_site->query($insertsql);
$accountid = mysql_insert_id();
}
?>
<script>
document.location.href="adcat.php"
</script>hope this helps someone in the future
Last edited by peter_budo : Jun 16th, 2008 at 8:16 am. Reason: Adding forgoten closing tag [/code]
•
•
Join Date: Jun 2008
Location: Phoenix, AZ
Posts: 534
Reputation:
Rep Power: 2
Solved Threads: 50
•
•
Join Date: Apr 2008
Posts: 31
Reputation:
Rep Power: 1
Solved Threads: 0
hi it doesn't but then i tried your script it didn't work? returned a parse error.
I only want the user to be able to select a maximum of 3 values but one thing that is a bit annoying is that when ithe user only selects 1 value it stores in the database like this Quilts,,
not sure how to get rid of the 2 commas? but at the end of the day it works.
I only want the user to be able to select a maximum of 3 values but one thing that is a bit annoying is that when ithe user only selects 1 value it stores in the database like this Quilts,,
not sure how to get rid of the 2 commas? but at the end of the day it works.
•
•
Join Date: Jun 2008
Location: Phoenix, AZ
Posts: 534
Reputation:
Rep Power: 2
Solved Threads: 50
tested, works fine for me
$_POST['vccategory'] = array("one", "two");
$vccategory = "";
foreach($_POST['vccategory'] as $value)
{
$vccategory .= $value . ", ";
}
$vccategory = substr($vccategory, 0, -2); //to get rid of the final ", "
echo $vccategory;•
•
Join Date: Jun 2008
Location: Phoenix, AZ
Posts: 534
Reputation:
Rep Power: 2
Solved Threads: 50
<form name="padform" method="post" action="<? echo $_SERVER['REQUEST_URI']; ?>" />
<input name="userID" type="hidden" id="userID" value="<?=$userID?>">
<table width="540" cellspacing="3" cellpadding="0" border="0">
<tr>
<td width="300" id="t_category1">
<input type="checkbox" name="vccategory[]" value="Quality Control & Consultants">Quality Control & Consultants</td></tr>
<tr>
<td><input type="checkbox" name="vccategory[]" value="Quilting Materials & Supplies">Quilting Materials & Supplies</td></tr>
<tr>
<td><input type="checkbox" name="vccategory[]" value="Quilts & Quilting">Quilts & Quilting</td></tr>
<tr>
<td><input name="submit" type="submit" class="button" value="Submit Ad" /><input class="button" type="reset" name="reset" value="Reset" /></td>
</tr>
</table>
</form>
<?
$vccategory = "";
foreach($_POST['vccategory'] as $value)
{
$vccategory .= $value . ", ";
}
$vccategory = substr($vccategory, 0, -2); //to get rid of the final ", "
echo $vccategory;
?>•
•
Join Date: Jul 2007
Location: Devon UK
Posts: 1
Reputation:
Rep Power: 0
Solved Threads: 0
"sorry so how does that work it doesn't link to my submit to database script which is on another page"
<form ... action="<? echo $_SERVER['REQUEST_URI']; ?>" />
This submits the form back to the same URL you're currently viewing without destroying any variables that may be in the address bar...
(more info can be found here: http://blog.taragana.com/index.php/a...n-to-use-what/)
You just have to set the page to retrieve the variables from the POST.
<?
$vccategory = $_POST['vccategory']
?>
This will set the variable '$vccategory' to whatever form field was submitted with that name
eg:
<input type="text" name="vccategory" value="this is vccategory!" />
...would mean $vccategory = "this is vccategory!";
hope this helps
<form ... action="<? echo $_SERVER['REQUEST_URI']; ?>" />
This submits the form back to the same URL you're currently viewing without destroying any variables that may be in the address bar...
(more info can be found here: http://blog.taragana.com/index.php/a...n-to-use-what/)
You just have to set the page to retrieve the variables from the POST.
<?
$vccategory = $_POST['vccategory']
?>
This will set the variable '$vccategory' to whatever form field was submitted with that name
eg:
<input type="text" name="vccategory" value="this is vccategory!" />
...would mean $vccategory = "this is vccategory!";
hope this helps
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb PHP Marketplace
- Previous Thread: exit
- Next Thread: how to provide an option to create new site


Linear Mode