将数据接收到另一个表

时间:2017-08-14 07:27:29

标签: php mysql

<?php
    session_start();
    require('../connection.php');

    if(empty($_SESSION['admin_id'])){
       header("location:access-denied.php");
    } 

    $result=mysql_query("SELECT * FROM tbCandidates")
    or die("There are no records to display ... \n" . mysql_error()); 
    if (mysql_num_rows($result)==0){
       $result = null;
    }
    ?>
    <?php

    $positions_retrieved=mysql_query("SELECT * FROM tbPositions")
    or die("There are no records to display ... \n" . mysql_error()); 
    $name_retrieved=mysql_query("SELECT * FROM tbstudent")
    or die("There are no records to display ... \n" . mysql_error());


    $row = mysql_fetch_array($name_retrieved);
    if($row)
    {
    //get data from db
     $name = $row['student_name'];
     $gender =$row['student_gender'];
     $grade =$row['student_grade'];
     $section =$row['candidate_section'];

     }

     ?>

    <?php

       if (isset($_POST['Submit']))
    {

    $newCandidateName = addslashes( $_POST['name'] ); //prevents types of SQL injection

    $newCandidatePosition = addslashes( $_POST['position'] ); //prevents types of SQL injection

    $sql = mysql_query( "INSERT INTO tbCandidates(candidate_name,candidate_gender,candidate_grade,candidate_section,
    candidate_position) VALUES
   ('$newCandidateName','$gender','$grade','$section','$newCandidatePosition')" )or die("Could not insert candidate at the moment". mysql_error() );
 ?>

当我添加来自另一个表的新候选人时,候选人姓名和候选人职位是正确的,但性别,成绩和部分与数据相同。 Check Image

0 个答案:

没有答案