Results 1 to 11 of 11
  1. #1

    Can you find the bug? (Easy Script)

    Here's the situation: Right now I have a static title at epasture.com What I want to do is when a particular product, laughable, tutorial, or brainteaser is selected it becomes the title of that page.

    I use the ID variable to ID the item from the the database if an item is selected. Every item, regardless of which table it is in has a TITLE record so thats not an issue. The code seems to work fine when there isn't an item selected ($ID < 1). However, when an item is selected it doesn't seem to work. The title doesn't return properly and the whole page is left as a blank white sheet (so no content gets returned either - that code isn't shown here but does work before I tried this so its not the problem).

    Here is the code I'm using:
    PHP Code:
    <TITLE>ePasture.com - 

        <?php /* IF NO TITLE IS DEFINED */
        
    if ($ID 1) {

             echo 
    "Laughables, Brainteasers, Ridiculous Products, Tutorials";
        
         } else { 
    //$ID has a value
         
            
    if ($content "laughables.php") { //if we are in the laughables section
                
    $result mysql_query("SELECT * FROM laughables WHERE ID = {$row['ID']}"
                   or die(
    "Invalid query: " mysql_error()); //then select the appropriate laughable

                
    while ($row mysql_fetch_array($result)) {
                    echo 
    "{$row['TITLE']}"// and out put the title
                
    }
            } elseif (
    $content "brainteasers.php") { //if we are in the brainteasers section 
                
    $result mysql_query("SELECT * FROM brainteasers WHERE ID = {$row['ID']}"
                   or die(
    "Invalid query: " mysql_error()); //then select the appropriate brainteaser

                
    while ($row mysql_fetch_array($result)) {
                    echo 
    "{$row['TITLE']}"// and out put the title
                
    }
            } elseif (
    $content "products.php") { //if we are in the products section 
                
    $result mysql_query("SELECT * FROM products WHERE ID = {$row['ID']}"
                  or die(
    "Invalid query: " mysql_error()); //then select the appropriate product

                
    while ($row mysql_fetch_array($result)) {
                    echo 
    "{$row['TITLE']}"// and out put the title
                
    }
            } elseif (
    $content "tutorials.php") { //if we are in the tutorials section 
                
    $result mysql_query("SELECT * FROM tutorials WHERE ID = {$row['ID']}"
                   or die(
    "Invalid query: " mysql_error()); //then select the appropriate tutorial

                
    while ($row mysql_fetch_array($result)) {
                    echo 
    "{$row['TITLE']}"// and out put the title
                
    }
            } else {
                echo 
    "Laughables, Brainteasers, Ridiculous Products, Tutorials";
            }
        }
    ?>


    </TITLE>
    Please let me know if there is anything else I can provide you to help you help me solve this problem. Any Ideas?

  2. #2
    on this line:
    Code:
    if ($ID < 1) {
    $ID isn't defined. But i assume you are using register_globals so ID is sent in get/post.

    on this line:
    Code:
    if ($content = "laughables.php")
    should be == instead of = (same on all other similar lines)

    on this line:
    Code:
     $result = mysql_query("SELECT * FROM laughables WHERE ID = {$row['ID']}")
    $row['ID'] isn't defined before so it is empty

    in this code:
    Code:
    echo "{$row['TITLE']}";
    what's the point in using double quotes? it only slows down php and makes your code harder to read. use echo $row['TITLE']; instead. (same on all other similar lines)

    And you should know that variables are case-sensitive, so $ID and $id are not the same. that might also be an error in your code.

  3. #3
    Thanks, I'm gonna try changing those = to == that may be it. When you say $ID isn't defined, that is true for the line $ID < 1, but in the other parts ID should be defined in the url content.php?content=laughables.php&ID=3 for example.

    Thanks for the help I'm gonna try your suggestions and let you know.

  4. #4
    Its still doing the same thing. I've made all changed you've recommended. If a link would point to one of two options:

    content.php?content=something.php

    OR

    content.php?content=somethingelse.php&ID=5 (or some other number)

    Is there something I need to do in the code I oroiginally posted to make it work?


    EDIT ADDON: I also use the rewrite_mod (I think thats it) to rewrite how the browser sees dynamic links to make it easier for search engines to index the site. Would the fact that a link like:

    epasture.com/content.php?content=laughables.php&ID=28

    would show up in the browser as:

    epasture.com/laughables28.html

    make any difference?
    Last edited by Jeanco; 03-27-2004 at 07:48 PM.

  5. #5
    Join Date
    Mar 2004
    Posts
    1,301
    I am not good at PHP, but you may try to use:

    $ID = $_REQUEST['ID'];

    have this line before the rest of the above code.
    this will get the value of ID from the link.

  6. #6
    I tried your idea orbitz and no luck, sorry.

    I found a clue... When I look at the source code the the blank white page I get (this is in the area relevant to the code above):
    Code:
    <TITLE>ePasture.com - Bored? You're in the right spot
    
    Invalid query: You have an error in your SQL syntax.  Check the
     manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
    Here is the PHP code that appears around line one. It has to do
    with rewriting the url for search engines. If you need to see the .htaccess code that goes along with this then let me know:
    PHP Code:
    <?php 

    if ($_GET['rewrite'] <> 1) { 
            
    $url "/".ereg_replace(".php$","",$content).$ID.$op.".html"

            
    header("Location: [url]http://[/url]" $_SERVER['HTTP_HOST'] . "$url") ; 

         
    ?>

  7. #7

  8. #8
    Join Date
    Jul 2003
    Location
    France
    Posts
    44
    The error is in line 1 but on your mysql query

    I will try something like this:

    mysql_query("SELECT * FROM laughables WHERE ID = '$ID' ")
    Web Design, logo, Flash, banner
    Orange Dream Studio
    Free game under the GPL licence:
    Old school game

  9. #9
    Join Date
    Mar 2004
    Location
    california
    Posts
    162

    Re: Can you find the bug? (Easy Script)

    Try this:

    Here is the code I'm using:
    PHP Code:
    <TITLE>ePasture.com - 

        <?php /* IF NO TITLE IS DEFINED */
        
    if ($ID 1) {

             echo 
    "Laughables, Brainteasers, Ridiculous Products, Tutorials";
        
         } else { 
    //$ID has a value
         
            
    if ($content == "laughables.php") { //if we are in the laughables section
                
    $result mysql_query("SELECT * FROM laughables WHERE ID =" .$ID
                   or die(
    "Invalid query: " mysql_error()); //then select the appropriate laughable

                
    while ($row mysql_fetch_array($result)) {
                    echo 
    "{$row['TITLE']}"// and out put the title
                
    }
            } elseif (
    $content == "brainteasers.php") { //if we are in the brainteasers section 
                
    $result mysql_query("SELECT * FROM brainteasers WHERE ID ="$ID
                   or die(
    "Invalid query: " mysql_error()); //then select the appropriate brainteaser

                
    while ($row mysql_fetch_array($result)) {
                    echo 
    "{$row['TITLE']}"// and out put the title
                
    }
            } elseif (
    $content == "products.php") { //if we are in the products section 
                
    $result mysql_query("SELECT * FROM products WHERE ID = "$ID
                  or die(
    "Invalid query: " mysql_error()); //then select the appropriate product

                
    while ($row mysql_fetch_array($result)) {
                    echo 
    "{$row['TITLE']}"// and out put the title
                
    }
            } elseif (
    $content == "tutorials.php") { //if we are in the tutorials section 
                
    $result mysql_query("SELECT * FROM tutorials WHERE ID = "$ID
                   or die(
    "Invalid query: " mysql_error()); //then select the appropriate tutorial

                
    while ($row mysql_fetch_array($result)) {
                    echo 
    "{$row['TITLE']}"// and out put the title
                
    }
            } else {
                echo 
    "Laughables, Brainteasers, Ridiculous Products, Tutorials";
            }
        }
    ?>


    </TITLE>
    Let me know what happens.

  10. #10
    Thanks everyone I got it working with a little help from someone here who was nice enough to assist me via email. Here is the solution in case someone can use it on their sites later:

    PHP Code:
    <?php
    if (!isset($_GET['ID'])) {
      
    $title="Laughables, Brainteasers, Ridiculous Products, Tutorials";
    } else {
      
    $curid=$_GET['ID'];
      
    $content=$_GET['content'];
      if (
    $content == "laughables.php") {
        
    $result mysql_query("SELECT * FROM laughables WHERE ID = $curid"
          or die(
    "Invalid query: " mysql_error()); 
        while (
    $row mysql_fetch_array($result)) {
          
    $title=$row['TITLE'];
        }
      } elseif (
    $content == "brainteasers.php") {
        
    $result mysql_query("SELECT * FROM brainteasers WHERE ID = $curid"
          or die(
    "Invalid query: " mysql_error());
        while (
    $row mysql_fetch_array($result)) {
          
    $title=$row['TITLE'];
        }
      } elseif (
    $content == "products.php") {
        
    $result mysql_query("SELECT * FROM products WHERE ID = $curid"
          or die(
    "Invalid query: " mysql_error());
        while (
    $row mysql_fetch_array($result)) {
          
    $title=$row['TITLE'];
        }
      } elseif (
    $content == "tutorials.php") {
        
    $result mysql_query("SELECT * FROM tutorials WHERE ID = $curid"
          or die(
    "Invalid query: " mysql_error());
        while (
    $row mysql_fetch_array($result)) {
          
    $title=$row['TITLE'];
        }
      } else {
        
    $title="Laughables, Brainteasers, Ridiculous Products, Tutorialsxxxxx";
      }
    }

    echo 
    $title;

    ?>

  11. #11
    Join Date
    Feb 2004
    Location
    India
    Posts
    1
    Hi Jeanco,
    Contact me on MSN [email protected] or aim - pmsrini.
    Thanks and looking forward to hear from you...Srinivas
    URL : www.jinis.com
    Mail[email protected]

Posting Permissions

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