Jump to content

Problem with GET (I think)


Joseph Witchard

Recommended Posts

<?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("../includes/S_conn.php");
  
  // set up the access
  
  $conn = sAccess();
  
  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`.`info` FROM `posts` `a` WHERE `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 %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; } $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

  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.

Link to comment
https://forums.phpfreaks.com/topic/135751-problem-with-get-i-think/
Share on other sites

Where are you actually running this query at?

 

$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";

 

something along the lines of

 

mysql_query($query);

 

also in your if statement in the first set of codes, I believe you want to check if it is not set with isset.  With something along these lines.

 

if (!isset($_GET['postID'])) {
  //  CODE GOES HERE
}

Where are you actually running this query at? something along the lines of

 

I'm using MySQL Improved. That's how MySQL Improved works. I made a couple of changes to the script, and it's fixed part of it. At least now, $noData is output to the page if you go to the script without any GET information. However, I just made the suggested isset() edits, and still, nothing is output from the database if you go to it with the GET information.

 

 

Nope, no output without GET :'(

 

Current script:

 

<?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
    
    $noData = true;
    
    
    
  }*/
  
  // require the connection settings
  
  require_once("path");
  
  // set up the access
  
  $conn = Access();
  
// var_dump($conn);
  
  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`, `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 = 1;
    $newTitle1 = 'frtgd';
    
    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>
        
  
    


  
    

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.