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 14 of 14
  1. #1
    New Coder
    Join Date
    Oct 2012
    Posts
    99
    Thanks
    16
    Thanked 0 Times in 0 Posts

    Coding resulting in a blank page

    Hi, I have a page called careGuideResult.php that I want to display the results of the common_name that is passed in the link:

    mysite.com/careGuideResult.php?common_name = Asian Arowana

    PHP Code:
    <?php 
    include 'core/init.php';
    include 
    'includes/overall/header.php'

    if (isset(
    $_GET['common_name']) === true && empty($_GET['common_name']) === false) {
        
    $common_name $_GET['common_name'];
        
        
    $species_data species_data($common_name'common_name''species_type''scientific_name''synonym''origin''size''environment''water_chemistry''temperature''feeding''sexing''compatability''temperament''breeding''comments');
    ?>
        

            <h2><?php echo $species_data['common_name'];?></h2>
            <p><img src=\"../_images/tropical.png\" height=\"250\" width=\"250\"></p>
            Species Type:<?php echo $species_data['species_type'];?><br>
            Common Name:<?php echo $species_data['common_name'];?><br>
            Scientific Name:<?php echo $species_data['scientific_name'];?><br>
            Synonym:<?php echo $species_data['synonym'];?><br>
            Origin:<?php echo $species_data['origin'];?><br>
            Size:<?php echo $species_data['size'];?><br>
            Environment:<?php echo $species_data['environment'];?><br>
            Water Chemistry:<?php echo $species_data['water_chemistry'];?><br>
            Temperature:<?php echo $species_data['temperature'];?><br>
            Feeding:<?php echo $species_data['feeding'];?><br>
            Sexing:<?php echo $species_data['sexing'];?><br>
            Compatability:<?php echo $species_data['compatability'];?><br>
            Temperament:<?php echo $species_data['temperament'];?><br>
            Breeding:<?php echo $species_data['breeding'];?><br>
            Comments:<?php echo $species_data['comments'];?></p>

    <?php        
    }  else {
        echo 
    'Sorry that care guide does not yet exist';
        }    
      }


        include 
    'includes/overall/footer.php';
    ?>
    The above script calls on the following function, which the above page is linked to already.

    Code:
    function species_data($common_name) {
    
    	$query = mysql_query("SELECT 'common_name', 'species_type', 'scientific_name', 'synonym', 'origin', 'size', 'environment', 'water_chemistry', 'temperature', 'feeding', 'sexing', 'compatability', 'temperament', 'breeding', 'comments' FROM `species` WHERE `common_name` = $common_name") or die ('Query is invalid: ' . mysql_error());
    
    	$species_data = mysql_fetch_array($query);
    }
    But now when I click on the link, I get a blank page.

    Can the variable $common_name be taken from the link clicked, be passed to the mysql_query in this way, to retrieve the correct information depending on which link was clicked?

    Have I gone about doing this the right way?

    Thanks

    Paul

  • #2
    Senior Coder djm0219's Avatar
    Join Date
    Aug 2003
    Location
    Wake Forest, North Carolina
    Posts
    1,301
    Thanks
    4
    Thanked 204 Times in 201 Posts
    You have an extra closing brace in the code you posted which would result in an error and a blank page.

    PHP Code:
    <?php        
    }  else {
        echo 
    'Sorry that care guide does not yet exist';
        }    
      }  
    // <<-- this is extra, remove it


        
    include 'includes/overall/footer.php';
    ?>
    Dave .... HostMonster for all of your hosting needs

  • Users who have thanked djm0219 for this post:

    aquaman (12-05-2013)

  • #3
    New Coder
    Join Date
    Oct 2012
    Posts
    99
    Thanks
    16
    Thanked 0 Times in 0 Posts
    Hi, thanks for your reply, that has certainly cleared up that problem. I also had to make a change to the mysql query

    Code:
    	$query = mysql_query("SELECT 'common_name', 'species_type', 'scientific_name', 'synonym', 'origin', 'size', 'environment', 'water_chemistry', 'temperature', 'feeding', 'sexing', 'compatability', 'temperament', 'breeding', 'comments' FROM `species` WHERE `common_name` = '$common_name'") or die ('Query is invalid: ' . mysql_error());
    I had forgot the ' ' around $common_name

    Now I have come across another problem. The page is not pulling the information from the database and then displaying it. I just get all the form fields but the values that should be next to them are blank.

    And yet again I cant see where I have gone wrong

  • #4
    New Coder
    Join Date
    Oct 2012
    Posts
    99
    Thanks
    16
    Thanked 0 Times in 0 Posts

    Question

    Hi, I did change all the ' to ` so the query now reads

    Code:
    	$query = mysql_query("SELECT `common_name`, `species_type`, `scientific_name`, `synonym`, `origin`, `size`, `environment`, `water_chemistry`, `temperature`, `feeding`, `sexing`, `compatability`, `temperament`, `breeding`, `comments` FROM `species` WHERE `common_name` = '$common_name'") or die ('Query is invalid: ' . mysql_error());
    but still get the same problem

  • #5
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,220
    Thanks
    23
    Thanked 606 Times in 605 Posts
    There is a missing function here
    PHP Code:
    $species_data species_data(....) 
    What does species_data() look like.

    Your query is ok and should work, but I'd like to see how your function is handling the parameters.
    Evolution - The non-random survival of random variants.

    "If you leave hydrogen alone, for long enough, it begins to think about itself."

  • #6
    New Coder
    Join Date
    Oct 2012
    Posts
    99
    Thanks
    16
    Thanked 0 Times in 0 Posts
    Hi Sunfighter, thanks for your reply.

    The function is defined here

    Code:
    function species_data($common_name) {
    
    	$query = mysql_query("SELECT `common_name`, `species_type`, `scientific_name`, `synonym`, `origin`, `size`, `environment`, `water_chemistry`, `temperature`, `feeding`, `sexing`, `compatability`, `temperament`, `breeding`, `comments` FROM `species` WHERE `common_name` = $common_name") or die (`Query is invalid: ` . mysql_error());
    
    	$species_data = mysql_fetch_array($query);
    }
    All the code is printed at the start of this post if you need to refer to that. I really cant see where I have gone wrong here, so any help is much appreciated.

    Thanks

    Paul

  • #7
    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
    $common_name appears to be a string. The argument must be wrapped in single quotations in SQL to be accepted as a string.

    Always enable your error reporting as well:
    PHP Code:
    ini_set('display_errors'1);
    error_reporting(E_ALL); 
    More preferable would be to set that at an ini level. It will tell you of all errors that appear in the script.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #8
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,220
    Thanks
    23
    Thanked 606 Times in 605 Posts
    Your calling the function with 16 parameters:
    PHP Code:
    $species_data species_data($common_name'common_name''species_type''scientific_name''synonym''origin''size''environment''water_chemistry''temperature''feeding''sexing''compatability''temperament''breeding''comments'); 
    But the function only accepts one:
    PHP Code:
    function species_data($common_name) { 
    That's death to the program. call S/B:
    PHP Code:
    $species_data species_data($common_name); 
    And you need to hook up to your DB.
    Evolution - The non-random survival of random variants.

    "If you leave hydrogen alone, for long enough, it begins to think about itself."

  • #9
    New Coder
    Join Date
    Oct 2012
    Posts
    99
    Thanks
    16
    Thanked 0 Times in 0 Posts
    Hi, thanks for your reply. I have enabled error reporting, but no errors are shown.

    Also when you say

    $common_name appears to be a string. The argument must be wrapped in single quotations in SQL to be accepted as a string.

    Do you mean the query should look like this?

    Code:
    	$query = mysql_query("SELECT 'common_name', `species_type`, `scientific_name`, `synonym`, `origin`, `size`, `environment`, `water_chemistry`, `temperature`, `feeding`, `sexing`, `compatability`, `temperament`, `breeding`, `comments` FROM `species` WHERE `common_name` = '$common_name'");
    Thanks

    Paul

  • #10
    New Coder
    Join Date
    Oct 2012
    Posts
    99
    Thanks
    16
    Thanked 0 Times in 0 Posts
    Hi, the DB is already hooked up in the include files at the top of the page. Is there any way I can change this so the function will pull the required info for that page?

    Thanks

  • #11
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,220
    Thanks
    23
    Thanked 606 Times in 605 Posts
    I see no advantage in using a function for this. I'd delete it and just do your query.
    Evolution - The non-random survival of random variants.

    "If you leave hydrogen alone, for long enough, it begins to think about itself."

  • #12
    New Coder
    Join Date
    Oct 2012
    Posts
    99
    Thanks
    16
    Thanked 0 Times in 0 Posts

    Question

    Hi Sunfighter, I took your advice and just done the query so the whole script looks like this. The db connection is already included in the include files.

    PHP Code:
    <?php 
    include 'core/init.php';
    include 
    'includes/overall/header.php'

    if (isset(
    $_GET['common_name']) === true && empty($_GET['common_name']) === false) {
        
    $common_name $_GET['common_name'];
        
        
    $data mysql_query("SELECT * FROM species WHERE `common_name` = '$common_name'") or die(mysql_error()); 
        while(
    $species_data mysql_fetch_array$data )) 
     { 
        
    ?>
        

            <h2><?php echo $species_data['common_name'];?></h2>
            <p><img src=\"../_images/tropical.png\" height=\"250\" width=\"250\"></p>
            Species Type:<?php echo $species_data['species_type'];?><br>
            Common Name:<?php echo $species_data['common_name'];?><br>
            Scientific Name:<?php echo $species_data['scientific_name'];?><br>
            Synonym:<?php echo $species_data['synonym'];?><br>
            Origin:<?php echo $species_data['origin'];?><br>
            Size:<?php echo $species_data['size'];?><br>
            Environment:<?php echo $species_data['environment'];?><br>
            Water Chemistry:<?php echo $species_data['water_chemistry'];?><br>
            Temperature:<?php echo $species_data['temperature'];?><br>
            Feeding:<?php echo $species_data['feeding'];?><br>
            Sexing:<?php echo $species_data['sexing'];?><br>
            Compatability:<?php echo $species_data['compatability'];?><br>
            Temperament:<?php echo $species_data['temperament'];?><br>
            Breeding:<?php echo $species_data['breeding'];?><br>
            Comments:<?php echo $species_data['comments'];?></p>

    <?php        
    }  else {
        echo 
    'Sorry that care guide does not yet exist';
        }    

    }
        include 
    'includes/overall/footer.php';
        
    ?>
    But now I get a blank page

  • #13
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,220
    Thanks
    23
    Thanked 606 Times in 605 Posts
    Again a problem with the brackets. Check them at the bottom of the script. What editor are you using to code with? It doesn't seem to add the brackets in the right places.
    PHP Code:
    <?php
    include 'core/init.php';
    include 
    'includes/overall/header.php';

    if (isset(
    $_GET['common_name']) === true && empty($_GET['common_name']) === false) {
        
    $common_name $_GET['common_name'];
        
    $data mysql_query("SELECT * FROM species WHERE `common_name` = '$common_name'") or die(mysql_error());
        while(
    $species_data mysql_fetch_array$data )){
    ?>
            <h2><?php echo $species_data['common_name'];?></h2>
            <p><img src=\"../_images/tropical.png\" height=\"250\" width=\"250\"></p>
            Species Type:<?php echo $species_data['species_type'];?><br>
            Common Name:<?php echo $species_data['common_name'];?><br>
            Scientific Name:<?php echo $species_data['scientific_name'];?><br>
            Synonym:<?php echo $species_data['synonym'];?><br>
            Origin:<?php echo $species_data['origin'];?><br>
            Size:<?php echo $species_data['size'];?><br>
            Environment:<?php echo $species_data['environment'];?><br>
            Water Chemistry:<?php echo $species_data['water_chemistry'];?><br>
            Temperature:<?php echo $species_data['temperature'];?><br>
            Feeding:<?php echo $species_data['feeding'];?><br>
            Sexing:<?php echo $species_data['sexing'];?><br>
            Compatability:<?php echo $species_data['compatability'];?><br>
            Temperament:<?php echo $species_data['temperament'];?><br>
            Breeding:<?php echo $species_data['breeding'];?><br>
            Comments:<?php echo $species_data['comments'];?></p>
    <?php
        
    }
    }else{
        echo 
    'Sorry that care guide does not yet exist';
    }
    include 
    'includes/overall/footer.php';
    ?>
    Evolution - The non-random survival of random variants.

    "If you leave hydrogen alone, for long enough, it begins to think about itself."

  • Users who have thanked sunfighter for this post:

    aquaman (12-06-2013)

  • #14
    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
    Quote Originally Posted by sunfighter View Post
    But the function only accepts one:
    PHP Code:
    function species_data($common_name) { 
    That's death to the program. call S/B:
    This is actually incorrect. PHP is built on varargs and therefore has no limitation to runtime arguments. What the above means is that there is one required parameter named $common_name, and you can have as many un-named parameters from that point forward. The context in this function would only make use of the one named argument though, so you are correct in that the other arguments are useless (but its not fatal or even a warning to the program).
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 


  •  

    Posting Permissions

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