我想将最低1和最多9个复选框值存储到我的数据库中。
我需要在sql中使用什么值来插入值。
我是否应该只使用name =“value”来获取每个值?
PHP:
$description = pathinfo(__FILE__, PATHINFO_FILENAME);
$filename = date('Ymdhis').".pdf";
$username = $_SESSION['username'];
$sql = "INSERT INTO documents (id, userid, description, name, date) VALUES (NULL, {$_SESSION['id']}, '{$description}' ,'{$filename}', NOW())";
$success = mysql_query($sql);
$sql2 = "INSERT INTO sprintvisioncc (first_name, last_name, email, telephone, truck_number, truck_mileage, market, carrier, site_number, time_in, time_out, stany_by, foreman, climber1, climber2, resources, issued, issues, root, action, release, materials, remaining, close_out, lat, longitude, comments, job_completion) VALUES ( '" . $_POST['first_name'] . "', '" . $_POST['last_name'] . "', '" . $_POST['email'] . "', '" . $_POST['telephone']. "', '" . $_POST['truck_number'] . "', '" . $_POST['truck_mileage'] . "', '" . $_POST['market'] . "', '" . $_POST['carrier'] . "', '" .$_POST['site_number'] . "', '" . $_POST['time_in'] . "', '" . $_POST['time_out'] . "', '" . $_POST['stand_by'] . "', '" . $_POST['foreman'] . "', '" . $_POST['climber1'] . "', '" . $_POST['climber2'] . "', '" . $_POST['resources'] . "', '" . $_POST['issued'] . "', '" . $_POST['issues'] . "', '" . $_POST['root'] . "', '" . $_POST['action'] . "', '" . $_POST['release'] . "', '" . $_POST['materials'] . "', '" . $_POST['remaining'] . "', '" . $_POST['close_out'] . "', '" . $_POST['lat'] . "', '" . $_POST['longitude'] . "', '" . $_POST['comments'] . "', '" . $_POST['job_completion'] . "')";
$success2 = mysql_query($sql2);
形式: 提供的清仓*
<tr bgcolor="#E1E1E1">
<td valign="top">
<label>Pre Alarm Screen Shots</label>
</td>
<td valign="top">
<input type="checkbox" name="close_out" value="Post Alarm Shots">
</td>
</tr>
<tr>
<td valign="top">
<label>Post Alam Screen Shots</label>
</td>
<td valign="top">
<input type="checkbox" name="close_out" value="Pre Alarm Shots">
</td>
</tr>
<tr bgcolor="#E1E1E1">
<td valign="top">
<label>Pre Photos</label>
</td>
<td valign="top">
<input type="checkbox" name="close_out" value="Pre Photos">
</td>
</tr>
<tr>
<td valign="top">
<label>Post Photos</label>
</td>
<td valign="top">
<input type="checkbox" name="close_out" value="Post Photos">
</td>
</tr>
<tr bgcolor="#E1E1E1">
<td valign="top">
<label>Pre Sweeps</label>
</td>
<td valign="top">
<input type="checkbox" name="close_out" value="Pre Sweeps">
</td>
</tr>
<tr>
<td valign="top">
<label>Post Sweeps</label>
</td>
<td valign="top">
<input type="checkbox" name="close_out" value="Post Sweeps">
</td>
</tr>
<tr bgcolor="#E1E1E1">
<td valign="top">
<label>Pre Fiber Test</label>
</td>
<td valign="top">
<input type="checkbox" name="close_out" value="Pre Fiber Test">
</td>
</tr>
<tr>
<td valign="top">
<label>Post Fiber Test</label>
</td>
<td valign="top">
<input type="checkbox" name="close_out" value="Post Fiber Test">
</td>
</tr>
<tr bgcolor="#E1E1E1">
<td valign="top">
<label>NTP1 Form</span></label>
</td>
<td valign="top">
<input type="checkbox" name="close_out" value="NTP1 Form">
</td>
</tr>
答案 0 :(得分:0)
表格应该是这样的
<tr>
<td valign="top">
<label>Post Sweeps</label>
</td>
<td valign="top">
<input type="checkbox" name="close_out1" value="Post Sweeps">
</td>
</tr>
<tr bgcolor="#E1E1E1">
<td valign="top">
<label>Pre Fiber Test</label>
</td>
<td valign="top">
<input type="checkbox" name="close_out2" value="Pre Fiber Test">
</td>
</tr>
<tr>
<td valign="top">
<label>Post Fiber Test</label>
</td>
<td valign="top">
<input type="checkbox" name="close_out3" value="Post Fiber Test">
</td>
</tr>
<tr bgcolor="#E1E1E1">
<td valign="top">
<label>NTP1 Form</span></label>
</td>
<td valign="top">
<input type="checkbox" name="close_out4" value="NTP1 Form">
</td>
</tr>
和php应该是这样的
for($i=1;$i>=4;$i++)
{
if(isset($_POST["close_out".$i]))
${"close_out".$i}=1;
else
${"close_out".$i}=0;
}
并使用$close_out1,..,$close_out4
输入数据库