Jump to content

What am I doing wrong


Seitan

Recommended Posts

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">&nbsp;</p>
</div>

<?
include ('../php/footer.php');
?>[/code]
Link to comment
https://forums.phpfreaks.com/topic/29749-what-am-i-doing-wrong/
Share on other sites

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.
Link to comment
https://forums.phpfreaks.com/topic/29749-what-am-i-doing-wrong/#findComment-136586
Share on other sites

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">&nbsp;</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">&nbsp;</p>
</div>";
[/code]
^^ not a real example as the above wont pharse.
Link to comment
https://forums.phpfreaks.com/topic/29749-what-am-i-doing-wrong/#findComment-136590
Share on other sites

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]
Link to comment
https://forums.phpfreaks.com/topic/29749-what-am-i-doing-wrong/#findComment-136597
Share on other sites

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">&nbsp;</p>
</div>[/code]
Link to comment
https://forums.phpfreaks.com/topic/29749-what-am-i-doing-wrong/#findComment-136604
Share on other sites

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.