-1

I want to make a link to another page based on the value inside database column.
table member

user_id     name    point
--------------------------
 1          sid     90
 2          mike    100 
 3          john    110 

for example, if we click this link <a href="chkpoint.php?user_id=<?php echo $row['user_id']; ?>" >Buy</a> it will check value in point column, if the value are below or equal than 100 it will go to page buy1.php else it will go to topup.php. so base on table above, for sid click Buy link, he will go to topup.php and for mike and john click Buy link they will go to buy1.php. so how can i create chkpoint.php? so far this is my code for chkpoint.php

<?php
$conn = new PDO('mysql:host=xxx; dbname=xxx', 'xxx', '') or die(mysql_error());

if (isset($_GET['user_id']) && !empty($_GET['user_id'])) {
    $user_id = $_GET['user_id'];
    $stmt = $conn->prepare('SELECT * FROM member WHERE user_id =:user_id');
    $stmt->execute(array(':user_id'=>$user_id));
    $row = $stmt->fetch(PDO::FETCH_ASSOC);
    extract($row);
} else {
    header("Location: memrec.php");
}

if (isset($_GET['point']) <= "100") {
    header("Location: topup.php");
} else {
    header("Location: buy1.php");
}
?>

but that code above doesn't working.

Z. Dmitry
  • 321
  • 4
  • 22
aini
  • 9
  • 6
  • `isset($_GET['point'])<="100"` is wrong. `isset()` returns a boolean. You need to first check if it exist and then check the value: `isset($_GET['point']) && $_GET['point'] <= 100` – M. Eriksson Jul 23 '17 at 21:54
  • You can also remove the `isset()`-part from `isset($_GET['user_id']) && !empty($_GET['user_id'])` since empty() does the same as isset() + some more checks. – M. Eriksson Jul 23 '17 at 21:59
  • @MagnusEriksson Be careful: `!empty()` and `isset()` are not the same. If `$_GET['user_id']=0`, `!empty()` will return FALSE, but `isset()` will return TRUE – BeetleJuice Jul 23 '17 at 22:33
  • @BeetleJuice That's why I wrote _"+ some more checks"_ – M. Eriksson Jul 23 '17 at 22:35
  • *"but that code above doesn't working"* - You're going to have to explain that and how `$row['user_id']` is being populated from. – Funk Forty Niner Jul 23 '17 at 22:36
  • 1
    `or die(mysql_error())` that doesn't work with PDO, so that may very well be *why* your code failed. Btw; are you not seeing these comments? – Funk Forty Niner Jul 23 '17 at 22:36
  • 1
    if you're just going to respond to "answers", then stick with them, I've moved on now. Good luck. Edit: oh and this `if (isset($_GET['point']) <= "100")` is invalid syntax, as a last word. – Funk Forty Niner Jul 23 '17 at 22:41
  • @Fred-ii- sorru, i don't notice your comment. `$row['user_id']` come form previous page tht need to check value in column point either 100 or more 100. – aini Jul 23 '17 at 22:46

1 Answers1

0

Change:

if(isset($_GET['point'])<="100")

With

if ( (int)$point < 100 )
BeetleJuice
  • 39,516
  • 19
  • 105
  • 165
  • You might want to add how the OP should set `$point` first. Just changing the above will throw an "Undefined variable $point"-warning. – M. Eriksson Jul 23 '17 at 21:57
  • @MagnusEriksson the OP uses `extract($row)` which will populate the local variable table with variables named after the keys of the `$row` array. Since the DB data was fetched with `$row = $stmt->fetch(PDO::FETCH_ASSOC)` and the DB table has a `point` column, there is no need to set `$point` – BeetleJuice Jul 23 '17 at 22:00
  • Ah. My bad... You're correct. The OP confused me by using `$_GET['point']`, which got me thinking that the variable comes from the URL instead of the DB. :-) – M. Eriksson Jul 23 '17 at 22:02
  • @BeetleJuice sir are you sure just change `if(isset($_GET['point'])<="100")` to `if ( (int)$point < 100 )`? – aini Jul 23 '17 at 22:05
  • @aini I can't be sure because I don't have the application and DB here to test, but you can check – BeetleJuice Jul 23 '17 at 22:07
  • @BeetleJuice sir. i've try in xampp but its bring me to `locahost/dashboard` instead of `buy1.php` or `topup.php` – aini Jul 23 '17 at 22:10
  • @aini what if you use the full path in the header (start with forward slash) ? `Location: /path/to/buy1.php` – BeetleJuice Jul 23 '17 at 22:14
  • @BeetleJuice same thing happen sir. its bring me to `localhost/dashboard` – aini Jul 23 '17 at 22:18