2012-04-15 9 views
1

enter code here Anfänger zu PHP und brauchen Hilfe. Ich habe die Produkte über einen Admin-Abschnitt hinzugefügt, der zwar erstellt wird, aber nicht auf der Seite reflektiert. Ich bekomme die Angabe aus dem Code: "echo" Daten zum Rendern dieser Seite fehlen. Get ID Variable ist nicht gesetzt. Bitte kontaktieren Sie uns.";". Bitte helfenDaten zum Rendern dieser Seite fehlen

Code:

<?php 

// Script Error Reporting 
error_reporting(E_ALL); 
ini_set('display_errors', '1'); 
?> 
<?php 
// Check to see the URL variable is set and that it exists in the database 
if (isset($_GET['?id=1'])) { 
    // Connect to the MySQL database 
    include "..storescripts/connect_to_mysql.php"; 
    $id = preg_replace('#[^0-9]#i', '', $_GET['?id=1']); 
    // Use this var to check to see if this ID exists, if yes then get the product 
    // details, if no then exit this script and give message why 
    $sql = mysql_query("SELECT * FROM products WHERE id='$id' LIMIT 1"); 
    $productsCount = mysql_num_rows($sql); // count the output amount 
    if ($productsCount > 0) { 
     // get all the product details 
     while($row = mysql_fetch_array($sql)){ 
      $product_name = $row["product_name"]; 
      $price = $row["price"]; 
      $shippingprice = $row["shippingprice"]; 
      $details = $row["details"]; 
      $category = $row["category"]; 
      $date_added = strftime("%b %d, %Y", strtotime($row["date_added"])); 
      //product_name, price, shippingprice, details, category, date_added 
     } 

    } else 
    { 
     echo "No product in the system with that ID."; 
     exit(); 
    } 

} else 
{ 
    echo "Data to render this page is missing.Get ID variable is not set. Please contact us."; 
    exit(); 
} 
mysql_close(); 
?> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
<title><?php echo $product_name; ?></title> 
<link rel="stylesheet" href="style/style.css" type="text/css" media="screen" /> 
</head> 
<body> 
<div align="center" id="mainWrapper"> 
    <?php include_once("template_header.php");?> 
    <div id="pageContent"> 
    <table width="100%" border="0" cellspacing="0" cellpadding="15"> 
    <tr> 
    <td width="19%" valign="top"><img src="inventory_images/<?php echo $id; ?>.png" width="142" height="188" alt="<?php echo $product_name; ?>" /><br /> 
     <a href="inventory_images/<?php echo $id; ?>.jpg">View Full Size Image</a></td> 
    <td width="81%" valign="top"><h3><?php echo $product_name; ?></h3> 
     <p><?php echo "£".$price; ?><br /> 
     <br /> 
     <?php echo "£".$shippingprice; ?> <br /> 
<br /> 
     <?php echo $details; ?> 
<br /> 
     </p> 
     <form id="form1" name="form1" method="post" action="cart.php"> 
     <input type="hidden" name="pid" id="pid" value="<?php echo $id; ?>" /> 
     <input type="submit" name="button" id="button" value="Add to Shopping Cart" /> 
     </form> 
     </td> 
    </tr> 
</table> 
    </div> 
    <?php include_once("template_footer.php");?> 
</div> 
</body> 
/html> 
+0

Wenn Sie "Echo" Daten zum Rendern dieser Seite fehlt.Get ID Variable ist nicht festgelegt. Bitte kontaktiere uns. ";" Dann heißt das, dass dein 'isset ($ _GET ['? Id = 1'])' zu false auswertet. Dies deutet darauf hin, dass '$ _GET ['? Id = 1']' nicht gesetzt ist. – Jack

Antwort

0

Änderung dieser Linie

$id = preg_replace('#[^0-9]#i', '', $_GET['?id=1']); 

zu

$id = preg_replace('#[^0-9]#i', '', $_GET['id']); 
+0

Ich änderte die Zeile wie erwähnt mit dem gleichen Ergebnis. – user1334267

0

Die $ _GET Superglobal ist ein Name-Wert-Array. Also, wenn Ihre Abfrage-String ist? Id = 1, wird $ _GET enthält

array('id' => 1) 

Und so können Sie den Wert von id $ _GET [ 'id'] mit zurückzuholen. Sie können dies bei Bedarf gegen den erwarteten Wert überprüfen.

+0

Wie setze ich $ _get ['id = 1']? Entschuldigung, ich bin neu in all dem – user1334267

+0

@ user1334267 http://www.php.net/manual/en/language.variables.external.php Ernsthaft, das ist grundlegende Dinge. Mit solchen Fragen wird man SO kaum helfen können. Ich würde empfehlen, einige Tutorials/Bücher zu PHP zu lesen. – liquorvicar

Verwandte Themen