1

Am new to php, so any help would be greatly appreciated. I have a page to create account for users, and while creating account, there is a select field which has three specific value to select from "notfcode" "tfail" **"tfcode".

There is another page check.php which allows the user check his ttype. What i want to do is make the page try to read the sql table row which is ttype and if the value present on the user's account is "notfcode" it redirects to notfcode.php page, if its "tfail" it redirects to tfail.php and if its "tfcode" it stays on the page. below is the code i have been battling with without success.

<?php session_start();
include_once ('session.php');
require_once 'class.user.php';
if(!isset($_SESSION['acc_no'])){
header("Location: login.php");
exit(); 
}
$reg_user = new USER();

$stmt = $reg_user->runQuery("SELECT * FROM account WHERE acc_no=:acc_no");
$stmt->execute(array(":acc_no"=>$_SESSION['acc_no']));
$row = $stmt->fetch(PDO::FETCH_ASSOC);
$email = $row['email'];

$temp = $reg_user->runQuery("SELECT * FROM transfer WHERE email = '$email' ORDER BY id DESC LIMIT 1");
$temp->execute(array(":acc_no"=>$_SESSION['acc_no']));
$rows = $temp->fetch(PDO::FETCH_ASSOC);

$transfertype = $row['ttype'];   

if(isset($_SESSION['acc_no'])){
    $transfertype = $row['ttype'];
    if($transfertype == nocodetf){
        header("Location: nocodetf.php");
    }
    elseif($transfertype == tfail){
        header("Location: nocodetf.php");
    }
    else {
        header("Location: check.php");
    }
}


include_once ('counter.php');
?>

When the page loads up, it does nothing, no redirects which is what i intend. A pointer in the right direction will be appreciated.

2 Answers 2

1

This are strings.

if($transfertype == "nocodetf"){ or if($transfertype == 'nocodetf'){

Activate PHP error reporting than PHP shows you this.

error_reporting(E_ALL);
ini_set('display_errors', 1);

$transfertype = "foo";

if ($transfertype == nocodetf) {  # <-- as you did it
//...
}

// <b>Warning</b>:  Use of undefined constant nocodetf - assumed 'nocodetf' (this will throw an Error in a future version of PHP) in ...
Sign up to request clarification or add additional context in comments.

6 Comments

nocodetf is defined in sql table as a row, is there a way i should define it on the page? I am not too good in php, so am finding it difficult understanding your point.
nocodetf is in every case wrong PHP syntax as used above. What is nocodetf? A Variable? A DB-Column? (I have no idea what you are doing there.)
First i created a row under account table which is ttype using this -- phpMyAdmin SQL Dump -- version 4.7.7 -- phpmyadmin.net -- -- Host: localhost:3306 -- Generation Time: Oct 16, 2018 at 10:23 AM -- Server version: 10.0.36-MariaDB-cll-lve -- PHP Version: 5.6.30 SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO"; SET AUTOCOMMIT = 0; START TRANSACTION; SET time_zone = "+00:00"; -- -- Dumping data for table account -- ALTER TABLE account ADD ttype varchar(20) NOT NULL; -- --------------------------------------------------------
Then i created a form page to insert either nocodetf or codetf into ttype as a value, so am trying to redirect to different pages if it's either of the two value respectively.
let me be more clearer, lets imagine you have a table named "ttype" which is compulsory field for every user you register on your database and there are basically two things which you can fill there as value i.e nocodetf and codetf, now you have a user who you registered and filled nocodetf as the value. Now prior to my code above, i want a php code to read the value in ttype and if it's nocodetf redirect to nocodetf.php and if it's codeft redirect to codetf i might be wrong even with the above code so please help me out.
|
0

I was finally able to resolve it using this code

<?php

$transfertype = $row['ttype'];
if($transfertype == 'nocodetf'){
    header('Location: nocodetf.php'); }
else if($transfertype == 'failtf'){
    header('Location: failtf.php');
    exit();
}

?>

The problem seemed to be in the fact that i wasn't quoting the value which php should try to get from the sql column.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.