douping7105 2015-04-05 11:32
浏览 5

无法插入MySQL以获取选择值

I have a web application in which students are divided into "batches".

I am trying to insert student for particular batch and the batch will be chosen by user by select option. After that student is added to the particular batch, he/she will be added to stdhold table. However, it is only inserting for the first selected value of select option.

<?php  
function specialCOn() {
    $connew = mysqli_connect("localhost","root","");
    $db = mysqli_select_db($connew,'mcqs');
    return($connew);
}

if (isset($_POST['add'])) 
{
    $namestd=$_POST['std_name'];
    $batchstd=$_POST['batch'];
    $FNAME=$_POST['f_name'];
    $query3 = "INSERT INTO `$batchstd` VALUES('','$namestd','$FNAME')";
    $rsq3 = mysqli_query(specialCOn(),$query3);
    mysqli_close(specialCOn());
    $queryrollno = "select rollno from `$batchstd` order by rollno desc";
    $rsqrollno = mysqli_query(specialCOn(),$querrollno);
    $getrollno = mysqli_fetch_array($rsqrollno);
    $rollnoto = $getrollno[0];
    echo "<script>alert('$batchstd')</script>";
    echo "<script>alert('$rollnoto')</script>";
    mysqli_close(specialCOn());

    //Problem is here
    $querystdhold = "INSERT INTO stdhold VALUES ($rollnoto, '$namestd', '$FNAME', '$batchstd')";
    $rsqhold = mysqli_query(specialCOn(),$querystdhold);
    mysqli_close(specialCOn());

    if ($rsq3&&$rsqhold) 
    {
         echo "<script> alert('Student Added.');
         window.location.assign('addstudent.php');
     </script>";

    //header('Location:addstudent.php');
}
else
{
    echo "<script> alert('You Havenot added Student.');
    window.location.assign('addstudent.php');</script>";
}
}
?>
  • 写回答

2条回答 默认 最新

  • dongyanjing5975 2015-04-05 11:44
    关注

    Try specifying the column names in your insert query:

    INSERT INTO stdhold (col1, col2, col3, col4) VALUES ($rollnoto, '$namestd', '$FNAME', '$batchstd');

    For reference see the MySQL Insert documentation.

    评论

报告相同问题?

悬赏问题

  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据
  • ¥20 软件测试决策法疑问求解答