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 7 of 7

Thread: Help With GET

  1. #1
    Regular Coder
    Join Date
    Oct 2008
    Posts
    255
    Thanks
    113
    Thanked 0 Times in 0 Posts

    Help With GET

    PHP Code:
    <?php // let's go!

      // get the news!
      
      
    $postID $_GET['postID'];
      
    $title $_GET['title'];
      
      
    // make sure that GET is set
      
      
    if ($_GET == 0)
      {
      
        
    // if not, display an error
        
        
    $noData true;
        
        
        
      }
      
      
    // require the connection settings
      
      
    require_once("path);
      
      // set up the access
      
      $conn = access();
      
      if ($conn->error)
      {
      
        echo "
    There is an error with conn" . $conn->errno . "Reason" . $conn->error;
        
      }
      
      
      $query1 = "
    SELECT `a`.`post_id`, `a`.`user_id`, `a`.`author_id`, `a`.`author_name`, `a`.`date_posted`, `a`.`author_email`, `a`.`category_id`,  `a`.`title`, `a`.`post_body`, `a`.`tags`, `a`.`infoFROM `posts` `aWHERE `a`.`post_id` = ? AND `a`.`title` = ? LIMIT 1";
      
      if ($stmt1 = $conn->prepare($query1))
      {
      
        // bind the parameters
        
        $stmt1->bind_param('is', $newID1, $newTitle1);
        
        $newID1 = $postID;
        $newTitle1 = $title;
        
        if ($stmt1->execute())
        {
        
          // bind the result
          
          $stmt1->bind_result($postIDNULL, $userIDNULL, $authorIDNULL, $authorNULL, $dateNULL, $emailNULL, $catIDNULL,  $newsTitle, $bodyNULL, $newsTags, $newsInfo);
          
          $stmt1->fetch();
          
         // printf ("
    Errors on the first statement %sn", $stmt->error);
          
        
        
      
      
      
        
     ?>
     
    <!DOCTYPE HTML PUBLIC "
    -//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>

      <
    head>
      
        <
    title><?php echo $newsTitle " -- Ultimate Hogwarts: The Rebirth"?></title>
        
        <link href="/css/general2.css" rel="stylesheet" type="text/css">
        <link href="/css/uslists.css" rel="stylesheet" type="text/css">
        <link href="/css/test.css" rel="stylesheet" type="text/css">
        
        <meta name="keywords" content="<?php echo $newsTags?>">
        <meta name="description" content="<?php echo $newsInfo; } $stmt1->close(); } ?>">
        <?php // include the remaining meta information
        
    include_once("../includes/meta_info.html");
        
    ?>
        
      </head>
      
      <body>
      
      <div id="wrapper">
      
        <div id="headers">
        
          <div id="header1"></div>
          
          <div id="header2"></div>
          
        </div>
        
        <div id="navigation">
        
        <!-- Begin Navigation Menu -->
        
        <?php // include the navigation menu
        
          
    include_once("../includes/navigation2.html"); ?>
          
        <!-- End Navigation Menu -->
        
        </div>
        
        <div id="right">
        
          <p>Hello!</p>
          
        </div>
        
        <div align="center" id="center">
        
          <table>
        
          <?php
          
          
    // write the query
      
      // REMEMBER JEFFREY: WHEN USING INNER JOIN IN A SQL QUERY, BOTH THE MYSQL FIELD AND PREFIX NEED TO BE TICKED AND DOTTED, AS SO: `a`.`username`
      
           
    $query2 "SELECT `a`.`post_id`, `a`.`author_id`, `a`.`author_name`, DATE_FORMAT(`a`.`date_posted`, '%W, %M %d %Y %l:%i %p'), `a`.`author_email`, `a`.`category_id`, `c`.`category_name`, `a`.`title`, `a`.`post_body` FROM `posts` `a` WHERE `a`.`post_id` = ? AND `a`.`title` = ? INNER JOIN  `categories` `c` ON `a`.`category_id` = `c`.`category_id` LIMIT 1";
           
           if (
    $stmt2 $conn->prepare($query2))
           {
           
             
    // bind the parameters
             
             
    $stmt2->bind_param('is'$newID2$newTitle2);
             
             
    $newID2 $postID;
             
    $newTitle2 $title;
             
             if (
    $stmt2->execute())
             {
             
               
    // bind the results
               
               
    $stmt2->bind_result($post_id$author_id$author$date$email$catID$category$newNewsTitle$body);
               
               
    printf("Errors on the second statement %s\n:"$stmt2->error);
               
               while (
    $stmt2->fetch())
               {
               
                 echo 
    "<tr><td><b>$newNewsTitle</b></td></tr>";
                 echo 
    "<tr><td><b>Posted By:</b> $author on $date in $category</td></tr>";
                 echo 
    "<tr><td>$body</td></tr>";
                 
               }
               
             }
             
           
    $stmt2->close();
           
           }
           
           
    $conn->commit();
           
           
    $conn->close();
           
         
    ?>
               
           
           
            
          </table>
          
          <?php if ($noData == true) { echo "<p align='center' class='warning'>There is no data.</p>"; } ?>
          
        </div>
        
      </div>
      
      </body>
      
    </html>
    PHP Code:
    <?php

      
    require_once("path");
      
      require_once(
    "path");
      
      require_once(
    "path");
      
      
    $conn access;
      
      
    $query "SELECT `a`.`post_id`, `a`.`author_id`, `a`.`author_name`, DATE_FORMAT(`a`.`date_posted`, '%W, %M %d %Y %l:%i %p'), `a`.`author_email`, `a`.`category_id`, `c`.`category_name`, `a`.`title`, `a`.`post_body` FROM `posts` `a` INNER JOIN  `categories` `c` ON `a`.`category_id` = `c`.`category_id` ORDER BY `a`.`date_posted` DESC LIMIT 4";
      

      
     
    ?>
      

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>

     <head>
     
       <title>Rebirth Test Page</title>
     
       <meta name="keywords" content="harry potter,hogwarts,hogwarts rpg,hogwarts online,jk rowling">
       <meta http-equiv="content-type" content="text/html; charset=utf-8">
       <meta http-equiv="cache-control" content="no-cache">
       
       <link href="/css/test.css" rel="stylesheet" type="text/css">
       
       <style type="text/css">
       
         #news
         { margin-bottom: 20px;
         }
         
         div.extra 
         { margin-bottom: 20px;
         }
         

         
       </style>
         
           
       
       
       
     </head>
     
     <body>
     
       <div id="wrapper">
       
         <div id="headers">
         
           <div id="header1"></div>
         
           <div id="header2">
           
           
           
           </div>
           
         </div>
       
       
       <div id="navigation">
      
         <!-- Begin Navigation Menu -->
         
         
         
         <?php // include the navigation menu
         
           
    include("../includes/navigation2.html"); ?>
           
         <!-- End Navigation Menu -->
       
       </div>
       
       

       
       
       <div id="right">
       
       <p>Hello!</p>
         
         
         
       </div>
       
       <div align="center" id="center">
       
         <div id="welcome">
         
           <p>Welcome to Ultimate Hogwarts: The Rebirth! Ultimate Hogwarts is an online Hogwarts Role Playing Game where fans
           of the Harry Potter books can create their own character, attend Hogwarts, visit the Ministry of Magic, or just 
           interact with other characters in our story! If you would like to know more about this site, please visit the Rules
           page and FAQ page. Once you're ready to enroll, you can go to the Character Applications forum at our message board
           and begin getting your character approved.</p>
           
         </div>
           
           <table id="news">
           
           <?php

      
      
    if ($stmt $conn->prepare($query))
      {
      
          
        if (
    $stmt->execute()) {
        
        
    $stmt->bind_result($postID$authorID$author$date$email$catID$category$title$body);
        
      
      
     
           
             while (
    $stmt->fetch())
             {
             
               echo 
    "<div class='extra'>";
             
               echo 
    "<tr class='title'><td><a href='/test/show_news.php?postID={$postID}&title={$title}'>" strip_tags($title'<p><br><a><b><i>') . "</a></td></tr>";
               echo 
    "<tr><td><b>Posted By: " strip_tags($author'<p><br><a><b><i>') . " on " $date " in " strip_tags($category'<p><br><a><b><i>') . "</b></td></tr>";
               echo 
    "<tr><td>" BBCODE(truncate(strip_tags($body'<p><br><a><b><i>'))) . "</td></tr></div>"; }  $stmt->close(); }  else { echo "Statement doesn't execute"; } } else { echo "Statement isn't prepared."; }   $conn->close(); 
               
               
    /*var_dump($query);*/   ?>
               
            </table>
             
           

           
         </div>
       
       </div>
       
       </div>
       
       
       
      </body>
      
    </html>
    Okay. The top script is the page that should be getting the the information, and the bottom script contains the URL that supplies the information. However, for some reason, whether you visit the top script alone or via the URL, nothing is output. Not even the errors from the debugging IF statements output. I think it's a problem with $_GET, but I'm not sure.

    Also, in the top script: The reason I have two queries is because I need some of the data out of MySQL before the other data. I would just use one query, however, I was unsure as to how to do that without echoing out a new HTML document with each time the loop goes through, or else only if the IF statement results to true. If you have any advice as to how to remedy this, I'd appreciate it.

  • #2
    Regular Coder FWDrew's Avatar
    Join Date
    Apr 2008
    Location
    Missouri
    Posts
    380
    Thanks
    38
    Thanked 45 Times in 43 Posts
    Just from a quick glance and thanks to the syntax highlighting of the forum, I noticed:
    Code:
     require_once("path);
    In which you missed a quotation mark, see if that helps at all.

    If not I am sure some of the more experienced php members can weigh in.

    Best Regards,

    Drew
    Dev-Tips.com || Employee at the Envato Network || My Portfolio

  • #3
    Senior Coder
    Join Date
    Apr 2007
    Location
    Quakertown PA USA
    Posts
    1,028
    Thanks
    1
    Thanked 125 Times in 123 Posts
    In addition to what FWDrew mentioned, you are missing a closing curly bracket:

    Code:
        if ($stmt1->execute())
        {
        
          // bind the result
          
          $stmt1->bind_result($postIDNULL, $userIDNULL, $authorIDNULL, $authorNULL, $dateNULL, $emailNULL, $catIDNULL,  $newsTitle, $bodyNULL, $newsTags, $newsInfo);
          
          $stmt1->fetch();
          
         // printf ("Errors on the first statement %s\n", $stmt->error);
          
        
        }
      
      
      
        
     ?>
     
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    Also, I believe you mean:
    PHP Code:
    if (count($_GET) == 0

  • #4
    Regular Coder
    Join Date
    Oct 2008
    Posts
    255
    Thanks
    113
    Thanked 0 Times in 0 Posts
    That fixed part of it It's now echoing out $noData if you go to the page without supplying the GET information. However, if you do supply the GET information, nothing is output. Thanks for the help What should I do next?

  • #5
    Senior Coder
    Join Date
    Apr 2007
    Location
    Quakertown PA USA
    Posts
    1,028
    Thanks
    1
    Thanked 125 Times in 123 Posts
    Post your code with the changes you've made.

  • #6
    Regular Coder
    Join Date
    Oct 2008
    Posts
    255
    Thanks
    113
    Thanked 0 Times in 0 Posts
    PHP Code:
    <?php // let's go!

      // get the news!
      
      
    $postID $_GET['postID'];
      
    $title $_GET['title'];
      
      
    // make sure that GET is set
      
      
    if (!isset($_GET['postID']) || !isset($_GET['title']))
      {
      
        
    // if not, display an error
        
        
    die('There is no data.');
        
        
        
      }
      
      
    // require the connection settings
      
      
    require_once("../includes/S_conn.php");
      
      
    // set up the access
      
      
    $conn sAccess();
      
     
    // var_dump($conn);
      
      
    if ($conn->connect_error)
      {
      
        echo 
    "There is an error with conn: " $conn->connect_errno "Reason: " $conn->connect_error;
        
        die();
        
      }
      
      
      
    $query1 "SELECT `a`.`post_id`, `a`.`user_id`, `a`.`author_id`, `a`.`author_name`, `a`.`date_posted`, `a`.`author_email`, `a`.`category_id`, `c`.`category_name`,  `a`.`title`, `a`.`post_body`, `a`.`tags`, `a`.`info` FROM `posts` `a` INNER JOIN `categories` `c` ON `a`.`category_id` = `c`.`category_id` WHERE `a`.`post_id` = ? AND `a`.`title` = ? LIMIT 1";
      
      if (
    $stmt1 $conn->prepare($query1))
      {
      
      
    //  var_dump($query1);
      
        // bind the parameters
        
        
    $stmt1->bind_param('is'$newID1$newTitle1);
        
        
    $newID1 $postID;
        
    $newTitle1 $title;
        
        if (
    $stmt1->execute())
        {
        
          
    // bind the result
          
          
    $stmt1->bind_result($postIDNULL$userIDNULL$authorIDNULL$authorNULL$dateNULL$emailNULL$catIDNULL$category$newsTitle$bodyNULL$newsTags$newsInfo);
          
          
    $stmt1->fetch();
          
         
    // printf ("Errors on the first statement %s\n", $stmt->error);
          
        
        
      
      
      
        
     
    ?>
     
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>

      <head>
      
        <title><?php echo $newsTitle " -- Ultimate Hogwarts: The Rebirth"?></title>
        
        <link href="/css/general2.css" rel="stylesheet" type="text/css">
        <link href="/css/uslists.css" rel="stylesheet" type="text/css">
        <link href="/css/test.css" rel="stylesheet" type="text/css">
        
        <meta name="keywords" content="<?php echo $newsTags?>">
        <meta name="description" content="<?php echo $newsInfo; } else { echo "No execute"; } $stmt1->close(); } else { echo "No query"$stmt1->close(); }  ?>">
        <?php // include the remaining meta information
        
    include_once("../includes/meta_info.html");
        
    ?>
        
      </head>
      
      <body>
      
      <div id="wrapper">
      
        <div id="headers">
        
          <div id="header1"></div>
          
          <div id="header2"></div>
          
        </div>
        
        <div id="navigation">
        
        <!-- Begin Navigation Menu -->
        
        <?php // include the navigation menu
        
          
    include_once("../includes/navigation2.html"); ?>
          
        <!-- End Navigation Menu -->
        
        </div>
        
        <div id="right">
        
          <p>Hello!</p>
          
        </div>
        
        <div align="center" id="center">
        
          <table>
        
          <?php
          
          
    // write the query
      
      // REMEMBER JEFFREY: WHEN USING INNER JOIN IN A SQL QUERY, BOTH THE MYSQL FIELD AND PREFIX NEED TO BE TICKED AND DOTTED, AS SO: `a`.`username`
      
           
    $query2 "SELECT `a`.`post_id`, `a`.`author_id`, `a`.`author_name`, DATE_FORMAT(`a`.`date_posted`, '%W, %M %d %Y %l:%i %p'), `a`.`author_email`, `a`.`category_id`, `c`.`category_name`, `a`.`title`, `a`.`post_body` FROM `posts` `a` WHERE `a`.`post_id` = ? AND `a`.`title` = ? INNER JOIN  `categories` `c` ON `a`.`category_id` = `c`.`category_id` LIMIT 1";
           
           
    //var_dump($query2);
           
           
    if ($stmt2 $conn->prepare($query2))
           {
           
             
    // bind the parameters
             
             
    $stmt2->bind_param('is'$newID2$newTitle2);
             
             
    $newID2 $postID;
             
    $newTitle2 $title;
             
             if (
    $stmt2->execute())
             {
             
               
    // bind the results
               
               
    $stmt2->bind_result($post_id$author_id$author$date$email$catID$category$newNewsTitle$body);
               
              
    // printf("Errors on the second statement %s\n:", $stmt2->error);
               
               
    while ($stmt2->fetch())
               {
               
                 echo 
    "<tr><td><b>$newNewsTitle</b></td></tr>";
                 echo 
    "<tr><td><b>Posted By:</b> $author on $date in $category</td></tr>";
                 echo 
    "<tr><td>$body</td></tr>";
                 
               }
               
             }
             
            
             
    //var_dump($stmt2);
             
             
           
    $stmt2->close();
           
           }
           
           
    $conn->commit();
           
           
    $conn->close();
           
         
    ?>
               
           
           
            
          </table>
          
          <?php if ($noData == true) { echo "<p align='center' class='warning'>There is no data.</p>"; } ?>
          
        </div>
        
      </div>
      
      </body>
      
    </html>
    My latest script. I get take to the die('No Data.') page if I go to the script directly. However, if I go to the script with the GET information, I do get taken to the HTML page, but nothing is output

  • #7
    Senior Coder
    Join Date
    Apr 2007
    Location
    Quakertown PA USA
    Posts
    1,028
    Thanks
    1
    Thanked 125 Times in 123 Posts
    If you follow the logic here:
    PHP Code:
    if ($stmt1 $conn->prepare($query1))
      {
      
    //  var_dump($query1);
      
        // bind the parameters
        
        
    $stmt1->bind_param('is'$newID1$newTitle1);
        
        
    $newID1 $postID;
        
    $newTitle1 $title;
        
        if (
    $stmt1->execute())
        {
          
    // bind the result
          
          
    $stmt1->bind_result($postIDNULL$userIDNULL$authorIDNULL$authorNULL$dateNULL$emailNULL$catIDNULL$category$newsTitle$bodyNULL$newsTags$newsInfo);
          
          
    $stmt1->fetch();
          
         
    // printf ("Errors on the first statement %s\n", $stmt->error);
          
     
    ?>
     
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html> 
    It is saying:

    1. if $stmt1 = $conn->prepare($query1) execute the remaining code, which includes
    2. if ($stmt1->execute()). If $stmt1->execute() returns true, execute the remaining code which includes the html page.

    So, if either $conn->prepare($query1) returns false or $stmt1->execute() returns false, the html page will not be displayed.

    The problem could be in either of those functions returning false, or the fact that both of those if statements are missing closing } (which may or may not be by design).

    HTH


  •  

    Posting Permissions

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