Update 26/10
Somehow, my program gets Object not found too. This error has been happening this whole week, several days after this question was posted.
Here's the whole error message:
The requested URL was not found on this server. The link on the referring page seems to be wrong or outdated. Please inform the author of that page about the error.
If you think this is a server error, please contact the webmaster.
Error 404
localhost
Apache/2.4.41 (Win64) OpenSSL/1.1.1c PHP/7.4.3
I clicked this link [HTTP/1.1 404 Not Found 134ms] on my console and it directed me here (I'm using Mozilla Firefox). It says I got this error probably because "my page is a subject to link rot".
Truth is, my page has been in its exact same location this whole time.
This is how my code looks like now:
PHP
<?php
define('DB_SERVER', 'localhost');
define('DB_USERNAME', 'root');
define('DB_PASSWORD', '');
define('DB_NAME', 'sip-krl');
ini_set('display_errors', '1');
ini_set('display_startup_errors', '1');
error_reporting(E_ALL);
$connect = mysqli_connect(DB_SERVER, DB_USERNAME, DB_PASSWORD, DB_NAME);
// Define variables and initialize with empty values
$id_jenisPembayaran = ""; $nama_jenisPembayaran = "";
// Processing form data when form is submitted
if($_SERVER["REQUEST_METHOD"] == "POST"){
// Assigning variables with data from input fields
$id_jenisPembayaran = trim($_POST["id_jenisPembayaran"]);
$nama_jenisPembayaran = trim($_POST["nama_jenisPembayaran"]);
// Prepare an insert statement
$sql = "INSERT INTO jenispembayaran (id_jenisPembayaran, nama_jenisPembayaran) VALUES (?,?)";
if($stmt = mysqli_prepare($connect, $sql)){
// Bind variables to the prepared statement as parameters
mysqli_stmt_bind_param($stmt, "is", $param_id_jenisPembayaran, $param_nama_jenisPembayaran);
// Set parameters
$param_id_jenisPembayaran = $id_jenisPembayaran;
$param_nama_jenisPembayaran = $nama_jenisPembayaran;
// Attempt to execute the prepared statement
if(mysqli_stmt_execute($stmt)){
// Records created successfully. Redirect to landing page
header("location: ./skripsi-manual/data-jenisPembayaran.php");
exit();
} else{
echo "Ada yang salah. Mohon cek coding";
}
// Close statement
mysqli_stmt_close($stmt);
}
}
// Close connection
mysqli_close($connect);
?>
HTML
<div class="content">
<form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>" method="POST">
<article class="card">
<h4> Masukkan Jenis Pembayaran </h4>
<br>
<br>
<label for="id_jenisPembayaran">Kode Jenis Pembayaran:</label>
<input type="text" name="id_jenisPembayaran" value="<?php echo $id_jenisPembayaran;?>">
<br>
<br>
<label for="nama_jenisPembayaran">Nama Jenis Pembayaran:</label>
<input type="text" name="nama_jenisPembayaran" value="<?php echo $nama_jenisPembayaran;?>">
<br>
<br>
<button type="submit" value="submit">Masukkan</button>
</article>
</form>
</div>
Regarding my previous question, I've tried changing php.ini file as suggested in here and here, I still got Object not found too.
Those errors notwithstanding, my page manages to insert data into database.
I tried searching main keywords: "link rot xampp php" in google but I only got links on how to fix link rot on online server. I've browsed that in stackoverflow, but none of the questions solve my problem. Could anyone show me what's wrong with my code?
Thanks in advance.
I have a form to input data to MySQL and redirect me back once it's done. Here is the code:
connecttodb.php
<?php
/* Database credentials.*/
define('DB_SERVER', 'localhost');
define('DB_USERNAME', 'root');
define('DB_PASSWORD', '');
define('DB_NAME', 'sip-krl');
/*Connect to MySQL database */
$connect = mysqli_connect(DB_SERVER, DB_USERNAME, DB_PASSWORD, DB_NAME);
// Check connection
if($connect === false){
die("ERROR: Could not connect. " . mysqli_connect_error());
}
PHP
<?php
include_once './assets/php/connecttodb.php';
// Define variables and initialize with empty values
$id_jenisPembayaran = $nama_jenisPembayaran = "";
// Processing form data when form is submitted
if($_SERVER["REQUEST_METHOD"] == "POST"){
// Assigning variables with data from input fields
$id_jenisPembayaran = trim($_POST["id_jenisPembayaran"]);
$nama_jenisPembayaran = trim($_POST["nama_jenisPembayaran"]);
// Prepare an insert statement
$sql = "INSERT INTO jenispembayaran (id_jenisPembayaran, nama_jenisPembayaran) VALUES (?,?)";
if($stmt = mysqli_prepare($connect, $sql)){
// Bind variables to the prepared statement as parameters
mysqli_stmt_bind_param($stmt, "is", $param_id_jenisPembayaran, $param_nama_jenisPembayaran);
// Set parameters
$param_id_jenisPembayaran = $id_jenisPembayaran;
$param_nama_jenisPembayaran = $nama_jenisPembayaran;
// Attempt to execute the prepared statement
if(mysqli_stmt_execute($stmt)){
// Records created successfully. Redirect to landing page
header("location: ./skripsi-manual/data-jenisPembayaran.php");
exit();
} else{
echo "Ada yang salah. Mohon cek coding";
}
// Close statement
mysqli_stmt_close($stmt);
}
// Close connection
mysqli_close($connect);
}
?>
HTML Form
<div class="content">
<form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>" method="POST">
<article class="card">
<h4> Masukkan Jenis Pembayaran </h4>
<br>
<br>
<label for="id_jenisPembayaran">Kode Jenis Pembayaran:</label>
<input type="text" name="id_jenisPembayaran"
value="<?php echo $id_jenisPembayaran;?>">
<br>
<br>
<label for="nama_jenisPembayaran">Nama Jenis Pembayaran:</label>
<input type="text" name="nama_jenisPembayaran"
value="<?php echo $nama_jenisPembayaran;?>">
<br>
<br>
<button type="submit" value="submit">Masukkan</button>
</article>
</form>
</div>
I'm running this with XAMPP and Mozilla Firefox. The PHP and HTML codes are in one file: data-jenisPembayaran.php. It manages to submit data into my database and it manages to redirect me back to the intended page. In other words, the code works as it should. But it also gives me two problems:
1. It writes an error message on top left of my page:
"Ada yang salah. Mohon cek coding."
which means: "something's wrong with my code".
2. Sometimes, it returns error of "Object not found." Like this
When I check to phpMyAdmin, the data I've typed are submitted, even when either of the two errors happened.
I tried deleting that . from in page address lines, it gave me undefined variables and undefined index.
Could anyone show me what's wrong with my code? Why did it display error messages like those and manage to input data into database in the same time?