简体   繁体   中英

how to display my id number from db table?

I'm a student studying web programming im trying to display some of information from my db table which are(name, date, dll), all of the information are displayed perfectly except my id number from the db table and also there are no error so its hard for me to detect what i did wrong. can anyone see what i did wrong in my coding and explain what have i missed?

for further reference this is my php coding:

<?php   

$con = mysql_connect("localhost", "root", "");
mysql_select_db("tempahperalatan");


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

    $noID = 'noID';
    $pemohon = $_POST['pemohon'];
    $trkhMula = $_POST['trkhMula'];
    $trkhAkhir = $_POST['trkhAkhir'];
    $n_program = $_POST['n_program'];
    $lokasi = $_POST['lokasi'];
    $n_anjuran = $_POST['n_anjuran'];
    $catatan = $_POST['catatan'];
    $masa = $_POST['masa'];
    $t_Log = $_POST['t_Log'];
    $modified_date;
    $modified_time;

$sql = "INSERT INTO daftartempah (pemohon, trkhMula, trkhAkhir, n_program, lokasi, n_anjuran, catatan, modified_date, modified_time) VALUES ('$pemohon', '$trkhMula', '$trkhAkhir', '$n_program', '$lokasi', '$n_anjuran', '$catatan', CURDATE(), CURTIME())";  
$res = mysql_query($sql);   
}

    $viewPerson = "SELECT * FROM daftartempah";
    $viewPersonRes = mysql_query($viewPerson);

?>

and this is a table im trying to display some of my info from my db table:

<?php


while($row = mysql_fetch_array($viewPersonRes)){

    echo "<tr>";
        echo "<td".$row['noID']."</td>";
        echo "<td>".$row['trkhMula']."</td>";
        echo "<td>".$row['modified_time']."</td>";
        echo "<td>".$row['n_program']."</td>";
        echo "<td>".$row['pemohon']."</td>";
        echo "<td>".$row['n_anjuran']."</td>";
        echo "<td>".$row['lokasi']."</td>";
        echo "<td>".$row['catatan']."</td>";
    echo "</tr>";
}
?>

my table name from my db is: daftartempah

thank you in advance, your help is much needed :)

You have a missing closure for your <td> tag.

echo "<td".$row['noID']."</td>";
         ^ right there.

That's why it's not displaying.

Therefore:

echo "<td>".$row['noID']."</td>";

and looking at your developer console and the HTML source would have shown you something about it.

Make sure that you also have the opening and closing <table> - </table> tags. That's unknown.

You're also practicing with an outdated API, which isn't good practice to begin with.

Use either the mysqli_ or PDO API for "this century".

You're also open to an serious SQL injection; use a prepared statement:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM