Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Jan 2010
    Posts
    127
    Thanks
    9
    Thanked 0 Times in 0 Posts

    $data not returning

    Hi there,

    I need the $data to return from the database if the data was found from the database, but unfortunately, my code is not working to return the data.

    I tried to enter non-exist data, it managed to return the error message but if the data exist, the page displays nothing.

    May I know where did I go wrong in my if statement?

    Below is my code that contain after the $data return the script will execute.

    PHP Code:
    $day  $_POST['day'];
    $month $_POST['month'];
    $year  $_POST['year'];
    $dob implode('/', array($day,$month,$year));

    if(isset(
    $_POST['submit'])){
        if(empty(
    $_POST['day']) || empty($_POST['month']) || empty($_POST['year'])){
            echo 
    "You need to fill in each field.<br /><br /><a href=\"./\" title=\"Fill In Again\">Click here to <b>fill in each field</b> again</a>";
        exit;
        }
    }

    //Date that user keyin
    $userDate $dob;
    $dateTime DateTime::createFromFormat('d/m/Y'$userDate);
    $myFormat $dateTime->format('Y-m-d');

    //Query string and put it in a variable.
    if(isset($_POST['dob_chi'])){
        
    $query "SELECT * FROM $table_n WHERE dob_chi = :date";
    } else {
        
    $query "SELECT * FROM $table_n WHERE dob_eng = :date";
    }

    $stmt $db->prepare($query);
    $stmt->execute(array('date' => $myFormat));
    $data $stmt->fetchAll();
    if ( !
    $data ) {
        echo 
    'No data found in database!';
        exit;
    } else {
        return 
    $data=$userDate;
    }

    //Now we create a while loop for every entry in our DB where the date is match.
    while ($row $stmt->fetchObject()) {
        
    $r1          $row->rowone;
        
    $r2          $row->rowtwo;
        
    $r3          $row->rowthree;
        
    $englishdate $row->dob_eng;
        
    $chinesedate $row->dob_chi;
        
    $zodiac      $row->zodiac;
            
        
    //add all initial data into a matrix variable for easier access to them later
        //To access rowone use $rows[0][0], rowtwo $rows[1][0] ect.
        //The matrix is an array which contains multiple array. eg. 2-dimensional arrays
        //To get all the variables with $r1X simply retrieve the first array of the matrix eg $rows[0]
        
    $rows = array(array($r1),array($r2),array($r3),array());       
    }
    //Similarities between row1 and row2 made me incorporate modulo value as an argument.
    function incmod($a$m){
        return (
    $a $m) + 1;

    Thank you for your time

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    Start by removing this:
    PHP Code:
    else {
        return 
    $data=$userDate;

    You don't return from the main method unless its the return result of the program which should be 0 unless its a failure.

    After this, you'll need to do something with the $data, $rows, $row. Currently there is no output, so you'll need to print something if you want it to display.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •