Reputation: 1
I dont know why this is not working, its most simple and easy part of my project.
I know that its not made with PDO but i will redo it soon as i know whats wrong with it.
Code logic:
If user have taken order, accept.php changes status value from 0 to odottaa.
If second user takes same order before its being removed from the list, status=odottaa is TRUE and moves user back to kuljettaja.php
<?php
require "secure/secure.php"; // Require login to page to prevent usage if not logged in
include "secure/config.php"; // Using database connection file here
$id = $_GET['id']; // get id through query string
$request = mysqli_query($link,"SELECT status FROM tilauskanta WHERE id=$id"); // Ask status value
echo "$request"; //Test print value
if ($request == "Odottaa"){
header("location:kuljettaja.php");
}
else{
header("location:accept.php?id=$id");
}
?>
Upvotes: 0
Views: 60
Reputation: 8103
Fetch data is required. Please change
if ($request == "Odottaa"){
to
$row = mysqli_fetch_assoc($request);
if ($row["status"]== "Odottaa"){
Please remove echo "$request";
and ALL other output statements from your script before the header statement so that header location can be executed.
on the other hand, please use parameterized prepared statement to avoid SQL injection
Upvotes: 1
Reputation: 1163
First of all avoid using parameters in your queries, that are passed by the user, as that makes you susceptible to mysql injection. Use prepared statements instead.
Secondly, in order for header("Location")
to work, it must be placed before anything else is printed on your page, like html, or (in your case) echo
Also you seem to be missing the actual fetching from the MySQL and instead are comparing the request, but since you are echoing it above, I guess you know what you are comparing...
If that is not your problem, then you will need to share a bit more about your log-in logic
Upvotes: 2