看一些教程我添加了单选按钮,但由于某些原因它无法正常工作。当我提交表单时,值不会输入数据库
这是我的代码 案例'添加':
if( $_POST['addbtn'] == 'Save' )
{
$name = '';
if(isset($_REQUEST['name']))
{
$name = $_REQUEST['name'];
}
$imageName = '';
$field = 'banner_images';
if($_FILES[$field ]['error'] == 0)
{
if($_FILES[$field]['tmp_name'] != '')
{
$uploaddir = "../inner_page_banner_images/";
$banner_images = $_FILES[$field]['name'];
$tag = "";
$Twidth = 980;
$Theight = 420;
@move_uploaded_file($_FILES[$field]['tmp_name'],$uploaddir.$_FILES[$field]['name']);
}
$site = '';
if(isset($_REQUEST['site']) == 'hino')
{
$site = $_REQUEST['checked'];
}
elseif(isset($_REQUEST['site']) == 'storm')
{
$site = $_REQUEST['checked'];
}
}
//--------------------------------------------------------------------------------------------------------
$Query = "INSERT INTO inner_banner SET ";
$Query .= "name = '".$name."',";
$Query .= "banner_images = '".$banner_images."'";
$Query .= "site = '".$site."'";
//echo $Query; die();
mysql_query($Query);
$_SESSION['msg'] = " New banner image uploaded successfully ";
@header("Location: inner_banner.php? module=inner_banner&action=view");
die();
}
include "add_banner.php";
break;
我的Html代码
<form method="post" name="frm1" id="frm1" action="" autocomplete="off" enctype="multipart/form-data" onsubmit="return ValidateForm(this);" >
<table cellspacing="0" cellpadding="3" border="0" align="center" width="100%">
<tr>
<td width="18%">Banner Title</td>
<td width="1%">:</td>
<td><input type="text" name="name" id="name" size="40" value="" />
<span class="required">*</span> </td>
</tr>
<tr>
<td colspan="3" style=" background-color: #FFFFFF;"> </td>
</tr>
<tr>
<td valign="top">Banner Image </td>
<td valign="top">:</td>
<td><input type="file" name="banner_images" id="banner_images" size="20" />
</td>
</tr>
<tr>
<td colspan="3" style=" background-color: #FFFFFF;"> </td>
</tr>
<tr>
<td valign="top">Select:</td>
<td valign="top">:</td>
<td><input type="radio" value="hino" name="site" id="site" />
HINO
<input type="radio" value="storm" name="site" id="site" />
Storm
<span class="required">*</span>
</td>
</tr>
<tr>
<td colspan="3" style=" background-color: #FFFFFF;"> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td><input type="submit" name="addbtn" value="Save" />
<input type='button' value='Cancel' onclick="document.location.href='inner_banner.php?module=inner_banner'" />
<input type="hidden" name="Validation" id="Validation" value="
Field=name|Alias=Banner Title|Validate=BLANK^
Field=banner_images|Alias=Banner Image|Validate=BLANK" />
有些人可以查看为什么没有在数据库中输入值
答案 0 :(得分:0)
此行缺少逗号:
$Query .= "banner_images = '".$banner_images."'";
应该是
$Query .= "banner_images = '".$banner_images."',";
作为旁注,您很容易使用sql injection代码,您可能希望使用预准备语句或至少使用mysql_real_escape_string
答案 1 :(得分:0)
不应该这样:
if(isset($_REQUEST['site']) == 'hino')
{
$site = $_REQUEST['checked'];
}
elseif(isset($_REQUEST['site']) == 'storm')
{
$site = $_REQUEST['checked'];
}
是:
if(isset($_REQUEST['site']) == 'hino')
{
$site = $_REQUEST['site'];
}
elseif(isset($_REQUEST['site']) == 'storm')
{
$site = $_REQUEST['site'];
}
如果是这样,更好的编码方式是:
if(isset($_REQUEST['site']) && ($_REQUEST['site'] == 'hino' || isset($_REQUEST['site']) == 'storm') {
$site = $_REQUEST['site'];
}
另外:
$Query .= "name = '".$name."',";
$Query .= "banner_images = '".$banner_images."',";
$Query .= "site = '".$site."'";