Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 01/09/2022 in all areas

  1. Here's is how you could handle the problems that people are mentioning. Just a quick "how I would do it": $errmsg = ''; if ($_GET['id'] == '') $errmsg .= 'Missing id value<br>'; else { $q = "SELECT * FROM peminjaman WHERE id_peminjaman='" . $_GET['id'] . "'"; if (!$get = mysqli_query($con, $q)) $errmsg .= "Query failed to run<br>Query was:<br>$q<br>"; } if ($errmsg <> '') { // show the errmsg and let the user know he has // a problem and stop this script } // continue on with query results $fetch = mysqli_fetch_array($get); $nama_pegawai = $fetch['nama_pegawai']; $tanggal_pinjam = $fetch['tanggal_pinjam']; $tanggal_kembali = $fetch['tanggal_kembali']; // no need to do the above 'assignments' when you can simply // use the values from the fetched array You really should check the results of your query since any error in your statement or possibly with your db server will cause issues.
    1 point
  2. the most immediate problem is that the query didn't match any data (or possibly didn't execute at all, but there would have been another php error at the mysqli_fetch_array statement.) see the php.net documentation for mysqli_fetch_array's return value - https://www.php.net/manual/en/mysqli-result.fetch-array.php code should ALWAYS test if data was fetched from a query before trying to use the data, and setup a user message if there was no data. // at the point of using the data if(!$fetch) { echo 'no data was found.'; } else { // use the data here... } the most likely reason for no matching data is either because $_GET['id'] doesn't contain any value or the value it does contain doesn't match any data in the table. you should ALWAYS validate inputs to your code before using them. if $_GET['id'] isn't set, is empty, or doesn't contain an integer value > 0, that's an error. you should setup a user message in this case and not attempt to run the sql query. you should ALWAYS have error handling for statements that can fail. for database statements that can fail - connection, query, prepare, and execute, the easiest way of adding error handling, without adding logic at each statement, is to use exceptions for errors and in most cases let php catch and handle the exception, where php will use its error related settings to control what happens with the actual error information, via and uncaught exception error (database statement errors will 'automatically' get displayed/logged the same as php errors.) next, don't put external, unknown, dynamic values directly into an sql query statement. use a prepared query instead. lastly, don't copy variables to other variables for nothing. this is just a waste of typing. just use the original variables.
    1 point
This leaderboard is set to New York/GMT-04:00
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.