0

谁能帮助我,我有一个将major_id 设置为隐藏的表单,当我不尝试提交我的表单时,我没有将major_id 值输入我的数据库。我真的很陌生,我不知道该怎么做。我知道我的 jquery 有问题

    $(function() {

    $(".button").click(function() {


    var major_id = $("input[name='major_id']").val('1');
    var titlesBg = $("#titlesBg").val();
    var subBg = $("#subBg").val();
    var smp = $("#smp").val();
    var sbu = $("#sbu").val();
    var dataString =  { 'major_id': major_id , 'titlesBg': titlesBg , 'subBg': subBg , 'smp': smp , 'sbu': sbu };



$sql_check = mysql_query("SELECT * FROM sub_guidelines username =" . $_SESSION['username'] . "order by sub_id desc");

if(isSet($_POST['titlesBg']) || ($_POST['subBg']) || ($_POST['smp']) || ($_POST['sbu']))

{
$major_id = $_GET['major_id'];
$titlesBg = mysql_real_escape_string($_POST['titlesBg']);
$subBg = mysql_real_escape_string($_POST['subBg']);
$smp = mysql_real_escape_string($_POST['smp']);
$sbu = mysql_real_escape_string($_POST['sbu']);
$username = $_SESSION['username'];


mysql_query("insert into sub_guidelines(username, major_id, titlesBg, subBg, smp, sbu) values ('$username','$major_id','$titlesBg','$subBg','$smp','$sbu')");

$sql_in= mysql_query("SELECT * FROM sub_guidelines WHERE username = '$username' AND major_id = '$major_id' order by sub_id desc");
$row = mysql_fetch_array($sql_in);
}
4

1 回答 1

1

很容易:

var major_id = $("input[name='major_id']").val('1');

将隐藏字段的值设置为 1,不返回隐藏字段的值;)这将返回一个 jquery 对象;)

var major_id = $("input[name='major_id']").val();

返回值

所以:

您使用 post 方法发送数据,但尝试使用 get 获取 major_id。这应该有帮助:

$major_id = $_POST['major_id'];

我很抱歉,但这是完全错误的:

if(isSet($_POST['titlesBg']) || ($_POST['subBg']) || ($_POST['smp']) || ($_POST['sbu']))

你必须检查它自己的价值

if(isset($_POST['titlesBg']) || isset($_POST['subBg']) || isset($_POST['smp']) || isset($_POST['sbu']))

此外,我会使用逻辑 AND 而不是 OR ;)

于 2013-01-23T06:29:54.670 回答