Seitan Posted December 7, 2006 Share Posted December 7, 2006 Im pretty new at this thing so I don't know what I'm doing wrong, I'm trying to make the fields in my table show up on my page. I can't get them to show up tho.....what am I doing wrong?[code]<? #recipes.php// Check for a valid user ID, through GET or POST.if ( (isset($_GET['id'])) ) { // Accessed through view_users.php $id = $_GET['id'];} elseif ( (isset($_POST['id'])) ) { // Form has been submitted. $id = $_POST['id'];} else { // No valid ID, kill the script. include ('../php/header.php'); echo '<h1 id="mainhead">Page Error</h1> <p class="error">This page has been accessed in error.</p><p><br /><br /></p>'; include ('../php/footer.php'); exit();}require_once ('../Can't tell!!/mysql_connect.php'); $query = "SELECT * FROM Recipes WHERE 'Recipe Number' = '$id'"; $result = @mysql_query ($query); $page_title = "Our Vegan Kitchen " . $result['Recipe Name']; $header = 'Category'; include ('../php/header.php'); ?> <div align="center"> <? echo 'Recipe Name'; ?></p> <p align="right">Submitted by<br> <?echo $result['Submitted_by'];?></p> <p align="left"> Ingredients:</p> <? while ($row = mysql_fetch_array ($result, MYSQL_ASSOC)) { echo $row['Ingredient 1'] ;?><br><? } ?><P><? echo 'Directions'; ?></p> <p align="left"> </p></div> <? include ('../php/footer.php'); ?>[/code] Quote Link to comment Share on other sites More sharing options...
papaface Posted December 7, 2006 Share Posted December 7, 2006 [code] include ('../php/footer.php'); exit();}[/code]You are telling php to stop processing. So it never reaches the html. Quote Link to comment Share on other sites More sharing options...
Seitan Posted December 7, 2006 Author Share Posted December 7, 2006 that only happens if you access the page the wrong way, hence the if statement at the top Quote Link to comment Share on other sites More sharing options...
papaface Posted December 7, 2006 Share Posted December 7, 2006 Ah yes. So what do you actually get on the page when you run this? Quote Link to comment Share on other sites More sharing options...
Seitan Posted December 7, 2006 Author Share Posted December 7, 2006 I get [center]Recipe Name[/center]Submitted bySubmitted_byIngredients:Directions Quote Link to comment Share on other sites More sharing options...
btherl Posted December 7, 2006 Share Posted December 7, 2006 As a first step, replace [code=php:0]$result = @mysql_query ($query);[/code] with [code=php:0]$result = mysql_query ($query) or die("Query failed: $query with error " . mysql_error());[/code]Then you can see if the query failed."@" means "suppress errors", which also means you don't know what's going wrong with your script. It's usually a bad idea, and should only be used with a good reason. Quote Link to comment Share on other sites More sharing options...
Seitan Posted December 7, 2006 Author Share Posted December 7, 2006 I put that line in and it worked fine, so the query definitely worked. Quote Link to comment Share on other sites More sharing options...
papaface Posted December 7, 2006 Share Posted December 7, 2006 You should really keep this part:[code]<div align="center"> <? echo 'Recipe Name'; ?></p> <p align="right">Submitted by<br> <?echo $result['Submitted_by'];?></p> <p align="left"> Ingredients:</p> <? while ($row = mysql_fetch_array ($result, MYSQL_ASSOC)) { echo $row['Ingredient 1'] ;?><br><? } ?><P><? echo 'Directions'; ?></p> <p align="left"> </p></div>[/code]in php and echo the HTML out. The way you have done it above is confusing.e.g.[code]echo "<div align="center"> <? echo 'Recipe Name'; ?></p> <p align="right">Submitted by<br> <?echo $result['Submitted_by'];?></p> <p align="left"> Ingredients:</p> <? while ($row = mysql_fetch_array ($result, MYSQL_ASSOC)) { echo $row['Ingredient 1'] ;?><br><? } ?><P><? echo 'Directions'; ?></p> <p align="left"> </p></div>";[/code]^^ not a real example as the above wont pharse. Quote Link to comment Share on other sites More sharing options...
btherl Posted December 7, 2006 Share Posted December 7, 2006 Can you post your database structure? How do you list the ingredients in the database?You can't access [code=php:0]$result['Submitted_by'][/code]. Instead you need to fetch the [code=php:0]$row[/code] as you do later on, and use [code=php:0]$row['Submitted_by'][/code] Quote Link to comment Share on other sites More sharing options...
Seitan Posted December 7, 2006 Author Share Posted December 7, 2006 Here is my new SQL statement, I tried picking every field individually[code]$query = "SELECT `Recipe Number`,`Recipe Name`,`Submitted By`,`Ingredient 1`,`Ingredient 2`,`Ingredient 3`,`Ingredient 4`,`Ingredient 5`,`Ingredient 6`,`Ingredient 7`,`Ingredient 8`,`Ingredient 9`,`Ingredient 10`,`Ingredient 11`,`Ingredient 12`,`Ingredient 13`,`Ingredient 14`,`Ingredient 15`,`Ingredient 16`,`Ingredient 17`,`Directions`,`Category`,`email`,`source_from` FROM `Recipes` WHERE `Recipe Number` = '$id'";[/code]and here is what I have for my output part now[code]<div align="center"><? echo 'Recipe Name'; ?></p> <p align="right">Submitted by<br> <?echo 'Submitted_by';?></p> <p align="left"> Ingredients:</p> <?while ($row = mysql_fetch_array ($result, MYSQL_ASSOC)) { echo $row['Ingredient []'] ;?><br><? } ?><P><? echo 'Directions'; ?> <p align="left"> </p></div>[/code] Quote Link to comment Share on other sites More sharing options...
corbin Posted December 7, 2006 Share Posted December 7, 2006 try replaceing the [] in row['Ingredient []'] with an actual number to see if it works. Quote Link to comment Share on other sites More sharing options...
Seitan Posted December 7, 2006 Author Share Posted December 7, 2006 yep that works, I replaced it with the number one, and I got the first ingredient, but I only get the first ingredient Quote Link to comment Share on other sites More sharing options...
corbin Posted December 7, 2006 Share Posted December 7, 2006 replace echo $row['Ingredient []'] ; with $i = 1;while($i <= 17) {echo $row['Ingredient {$i}'];$i++;} Quote Link to comment Share on other sites More sharing options...
Seitan Posted December 7, 2006 Author Share Posted December 7, 2006 it doesn't work...I don't get anything now Quote Link to comment Share on other sites More sharing options...
Seitan Posted December 7, 2006 Author Share Posted December 7, 2006 Actually I got it working, but you guys helped......I put the while statement at the beginning and then just put everything like [font=Verdana]$row['Submitted by'] or $row['Directions'][/font] So thank you for your help. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.