1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

I NEED help with an INSERT form comments

Discussion in 'PHP' started by co.ador, Jul 11, 2009.

  1. co.ador

    co.ador Peon

    Messages:
    120
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #21
    you mean use echo before the query like this...
    
    
    echo $query = "INSERT INTO comments VALUES ('','$appetizers_id', NOW(), '$nickname', '$fullname' ,'$pros', '$cons')";
    PHP:
    this little '' are getting me bro... ahi!!
     
    co.ador, Jul 11, 2009 IP
  2. Goramba

    Goramba Peon

    Messages:
    128
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #22
    Noooo no no. Just echo out the query so you can post it and we can see if there are any final formatting issues. Like this:
    
    $query = "INSERT INTO comments VALUES ('','$appetizers_id', NOW(), '$nickname', '$fullname' ,'$pros', '$cons')";
    echo $query;
    
    PHP:
    Load the page and the whole "insert into..." should be printed somewhere on the page. Copy/paste it here.
     
    Goramba, Jul 11, 2009 IP
  3. co.ador

    co.ador Peon

    Messages:
    120
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #23
    <?php
    
    if(isset($_POST['submit' ])){ 
    
    $nickname = mysql_real_escape_string($_POST['nickname']);
    
    $fullname = mysql_real_escape_string($_POST['fullname']);
    
    $pros = mysql_real_escape_string($_POST['pros']);
    
    $cons = mysql_real_escape_string ($_POST['cons']);
    
    $id2 = (int) $_GET['id']; 
    $query = "INSERT INTO comments VALUES (''',$appetizers_id,' NOW(), '$nickname', '$fullname' ,'$pros', '$cons')";
    echo $query;
    $result = mysql_query($query) or die (mysql_error());
    
        echo "Thanks for your comment";
    
    }
    
    ?>
    PHP:
    when I echo the $query like in the script above it present itemdetails.php in the same manner /i don't see any differences. And when I submit the form the same only the header of the page appear and then everything in blank
     
    co.ador, Jul 11, 2009 IP
  4. Goramba

    Goramba Peon

    Messages:
    128
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #24
    Yeah you messed up the '' again....

    $query = "INSERT INTO comments VALUES ('','$appetizers_id', NOW(), '$nickname', '$fullname' ,'$pros', '$cons')";

    ^^ Copy/paste that and never change it again.





    Also, take out the "if(isset($_POST['submit' ])){" at the top and
    "}" at the bottom. Load the page again, see what happens.

    If it still doesn't show anything then it's something else on the page, you should post the whole thing.
     
    Goramba, Jul 11, 2009 IP
  5. co.ador

    co.ador Peon

    Messages:
    120
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #25
    That's qoutes " instead of two single qoutes? '' o well. It did inserted the comments finally into the database yeaaaa...

    What do you mean by that?

    When i press the bottom submit then the form appear on top instead in the same order as it was before..

    But the form should not appear after an user press submit it should appear thank you for your comment alone and it is not showing up but the form on top of the page
     
    co.ador, Jul 11, 2009 IP
  6. co.ador

    co.ador Peon

    Messages:
    120
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #26
    the time was 2009-07-12 00:48:36 instead of 12:48:36 am

    I know there are other kind of format.
     
    co.ador, Jul 11, 2009 IP
  7. co.ador

    co.ador Peon

    Messages:
    120
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #27
    If I take out the
    if(isset($_POST['submit' ])){
    }
    then an error show up


    Notice: Undefined index: cons in C:\wamp\www\shoes\stores\itemdetails.php on line 37

    Notice: Undefined variable: appetizers_id in C:\wamp\www\shoes\stores\itemdetails.php on line 40
     
    co.ador, Jul 11, 2009 IP
  8. wd_2k6

    wd_2k6 Peon

    Messages:
    1,740
    Likes Received:
    54
    Best Answers:
    0
    Trophy Points:
    0
    #28
    Don't take that out as it checks that the form has been submitted.

    So at least you got it finally to insert the comment into the database. For more on basic SQL syntax visit here.

    As for changing the time, you need to change your column type from datetime to time if you just want the time.
     
    wd_2k6, Jul 12, 2009 IP
  9. Goramba

    Goramba Peon

    Messages:
    128
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #29
    Not an error, just letting you know that $cons and $appetizers_id are not set to anything, so they'll be blank on the insert. If this is a live server you should edit your php.ini file and change the error reporting so that doesn't show up.

    I'm not sure I understand but if a form is still showing up you'll have to post all of the code so we can see how it's working. The bit you posted should work fine.

    You can't use quotes without escaping them, use tic marks.

    We got up to 2 pages to figure out why a simple insert wasn't working, I had him take that out to see if for some reason it wasn't set.
     
    Goramba, Jul 12, 2009 IP
  10. co.ador

    co.ador Peon

    Messages:
    120
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #30
    Goramba Look at the:
    <?php
    $sql = "SELECT * FROM comments ";
        $sql .= " WHERE id= '$id '"
        $sql .= " ORDER BY created ASC";
    	?>
    
    PHP:
    and the foreach loop on top of the form all the way at the bottom of the script. I have tried building the above query and the foreach loop to display the comments but nothing. Another thing is that after pressing the submit button it insert the comments and it redirect to the same page but without this part of the code. the id in here
    $query = 'SELECT * FROM menu WHERE id = '.intval($id). '  LIMIT 1 ;'; 
    PHP:
    comes from an id value on the URL which is pass from another page through the URL to itemdetails.php but when I submit the form some how this query is not able to pick up the id to display the item details or script above.

    item details

    
    $query = 'SELECT * FROM menu WHERE id = '.intval($id). '  LIMIT 1 ;'; 
    
    // execute query 
    $result = mysql_query($query) or die ("Error in query: $query. ".mysql_error()); 
    
    // see if any rows were returned 
    if (mysql_num_rows($result) > 0) { 
    $row = mysql_fetch_row($result); {
    echo '<table width="100%"  border="0" cellspacing="0" cellpadding="0" class="itemdetails">
    <tr><td width="1100" height="417" bgcolor="#FFFFFF" class="tento">
    <table class="cafe"><tr><td width="547">
    <a href="#"><h3 align="justify" style="position:relative;  height:5px;  top: 10px;">',$row[3] ,'</h3></a>
    </td>
    </tr>
    </table>
    <table width="1215" height="609" class="chencho" >
     <td class="largethumb" rowspan="8" align="center">
    <a href="#"><img src=',$row[0] ,' width="270" height="160" alt="coloe"/></a></td>
    <td width="544" rowspan="8" padding="0"  ><table width="252" style="font-size:12px; position:relative; top:-6px;">
      <td width="1">&nbsp;</td>
      <td width="54" bgcolor="#FFFFFF"><strong>Price:</strong></td>
      <td colspan="7">$<span class="style3">',$row[4] ,'</span></td>
    <tr>
      <td class="style1">&nbsp;</td>
      <td colspan="7" class="style3">&nbsp;</td>
    </tr>
    <tr><td>&nbsp;</td><td><strong>Raiting:</strong></td>
      <td width="18" class="rating2">*</td>
      <td width="18" class="rating2">*</td>
      <td width="18" class="rating2">*</td>
      <td width="18" class="rating2">*</td>
      <td width="18" class="rating2">*</td>
        <td width="71"></td>
    </tr><tr>
      <td width="12"><span class="style2">coloso</span></td>
      
    </tr>
      <tr>
      <td >&nbsp;</td>
    </tr></table>
     </td>
    <tr>
      <td width="224" height="40" rowspan="3"><strong>Details:</strong></td>
    </tr>
    <tr>
      <td width="106" height="28"><a href="#"><img src="../images/add to Car.gif" alt="df" width="99" height="28" /></a></td>
    </tr><tr>
      <td height="25"><a href="#"><img src="../images/viewcart.gif" alt="rt" width="99" height="28" /></a></td>
    </tr>
    <tr>
      <td width="224" height="29"><ul>
        <li>coloso mentiroso</li>
      </ul></td>
    </tr>
    <tr>
      <td width="224" height="29"><ul>
        <li>coloso mentiroso</li>
      </ul></td>
    </tr>
    <tr>
      <td width="224" height="21"><ul>
        <li>coloso mentiroso</li>
      </ul></td>
    </tr><tr>
      <td height="12" colspan="2"><img src="../images/line..gif" alt="as" width="300" height="7" /></td>
    </tr>
    
    <tr></tr><td rowspan="2">
    <table width="162" align="center" class="smallthumbs">
    <tr>
    
    <td width="46" height="65"><a href="#"><img src=',$row[0] ,' alt="df" width="50" height="50"/></a></td>
    <td width="36"><a href="#"><img src="../images/image1.jpg" alt="we" width="50" height="50" /></a></td>
    <td width="57"><a href="#"><img src="../images/launch.jpg" alt="bn" width="50" height="50" /></a></td>
    <td width="36"><a href="#"><img src="../images/image1.jpg" alt="we" width="50" height="50" /></a></td>
    </tr>
    </table></td> 
    <td rowspan="4">&nbsp;</td> 
    <td height="49"><strong>Rating and Review:</strong></td><td align="center"><a href="#">Add Review</a></td>
    <tr>
      <td rowspan="1" height="4" ><table style="font-size:10; position:relative; left:26px;">
      <td width="58">One star</td>
      <td width="40">*****</td>
      <td width="25">[23]</td>
      </table></td>
    </tr><td rowspan="2"></td>
    <tr><td height="4"><table style="font-size:10; position:relative; left:26px; ">
      <td width="58">One star</td>
      <td width="40">*****</td>
      <td width="25">[23]</td>
      </table></td>
    </tr>
    <td width="321" rowspan="7"></td>
    
    <td width="544" rowspan="7">&nbsp;</td>
      <td width="224" height="4"><table style="font-size:10; position:relative; left:26px;">
      <td width="58">One star</td>
      <td width="40">*****</td>
      <td width="25">[23]</td>
      </table></td>
      <tr><td width="224" height="4"><table style="font-size:10; position:relative; left:26px;">
      <td width="58">One star</td>
      <td width="40">*****</td>
      <td width="25">[23]</td>
      </table></td></tr>
    
    
    
    
      <td width="224" height="4"><table style="font-size:10; position:relative; left:26px;">
      <td width="58">One star</td>
      <td width="40">*****</td>
      <td width="25">[23]</td>
      </table></td>
      <tr>
        <td height="4" colspan="2"><img src="../images/line..gif" alt="df" width="330" height="7" /></td>
      </tr>
    
    
    
    <tr>
      <td width="224" height="52"><strong>Items Specifications:</strong></td>
    </tr>
        <td width="224" height="4" style="font-size:11;"><ul>
          <li>Lemon</li>
        </ul></td>
    <tr>
      <td width="224" height="4" style="font-size:11;"><ul>
        <li>Marincra</li>
      </ul></td>
    </tr>
      <td width="321" height="29" rowspan="5">&nbsp; </td>
    <td width="544" height="29" rowspan="5">&nbsp;</td>
    
    
    
    
    
    
    
        <td height="1" colspan="1" style="font-size:11;"><ul>
          <li>Sal</li>
        </ul></td>
        <tr>
          <td height="1" style="font-size:11;"><ul>
            <li>Tomatos</li>
          </ul></td>
        </tr> <tr>
          <td height="1" style="font-size:11;"><ul>
            <li>Plums</li>
          </ul></td>
        </tr> <tr>
          <td height="1" style="font-size:11;"><ul>
            <li>Saludos</li>
          </ul></td>
        </tr> <tr>
          <td height="1" style="font-size:11;"><ul>
            <li>Asucar</li>
          </ul></td>
        </tr>
      
    </table>	
    ';}
    }
    ?>
    PHP:
    Right now I am having a Dilema lol.. to weather display Thank you for your comments or just simply display the comments and refresh the page to update the comment list and keep displaying all the item details. I think I want to keep displaying all the items details, refresh the page and update the comment list. Now how can the id in the url could be passed to the item details script part after submiting the comment form because it seem the id is not able to pass since the submission of the comment.


    The entire script:
    
    
    <style type="text/css">
    <!--
    .style1 {color: #FF3300}
    .style2 {color: #FFFFFF}
    .style3 {color: #000000}
    -->
    </style>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js"></script>
    <script>
    $(function()
    {
      var default_image = $('td.largethumb img').attr('src');
      $('table.smallthumbs a').mouseover(function() { $('td.largethumb img').attr('src', $('img', this).attr('src')); });
    });
    </script>
    <?php require_once("../includes/initialize.php");?>
    <?php require_once("../includes/connection.php");?>
    <?php require_once("../includes/functions.php");?>
    
    <?php include("../includes/header.php");?>
    
    <?php 
    if( isset($_GET['id']))
    {
        $id = $_GET['id'];
    }
    ?>
    <?php
    
    if(isset($_POST['submit' ])){ 
    
    $nickname = mysql_real_escape_string($_POST['nickname']);
    
    $fullname = mysql_real_escape_string($_POST['fullname']);
    
    $pros = mysql_real_escape_string($_POST['pros']);
    
    $cons = mysql_real_escape_string ($_POST['cons']);
    
    $id2 = (int) $_GET['id']; 
     $query = "INSERT INTO comments VALUES ('','$appetizers_id', NOW(), '$nickname', '$fullname' ,'$pros', '$cons')";
    echo $query;
    $result = mysql_query($query) or die (mysql_error());
    
        echo "Thanks for your comment";
    
    }
    
    ?>
    
    <?php 
    
    <?php
    $sql = "SELECT * FROM comments ";
        $sql .= " WHERE id= '$id '"
        $sql .= " ORDER BY created ASC";
    	?>
    
    
    $query = 'SELECT * FROM menu WHERE id = '.intval($id). '  LIMIT 1 ;'; 
    
    // execute query 
    $result = mysql_query($query) or die ("Error in query: $query. ".mysql_error()); 
    
    // see if any rows were returned 
    if (mysql_num_rows($result) > 0) { 
    $row = mysql_fetch_row($result); {
    echo '<table width="100%"  border="0" cellspacing="0" cellpadding="0" class="itemdetails">
    <tr><td width="1100" height="417" bgcolor="#FFFFFF" class="tento">
    <table class="cafe"><tr><td width="547">
    <a href="#"><h3 align="justify" style="position:relative;  height:5px;  top: 10px;">',$row[3] ,'</h3></a>
    </td>
    </tr>
    </table>
    <table width="1215" height="609" class="chencho" >
     <td class="largethumb" rowspan="8" align="center">
    <a href="#"><img src=',$row[0] ,' width="270" height="160" alt="coloe"/></a></td>
    <td width="544" rowspan="8" padding="0"  ><table width="252" style="font-size:12px; position:relative; top:-6px;">
      <td width="1">&nbsp;</td>
      <td width="54" bgcolor="#FFFFFF"><strong>Price:</strong></td>
      <td colspan="7">$<span class="style3">',$row[4] ,'</span></td>
    <tr>
      <td class="style1">&nbsp;</td>
      <td colspan="7" class="style3">&nbsp;</td>
    </tr>
    <tr><td>&nbsp;</td><td><strong>Raiting:</strong></td>
      <td width="18" class="rating2">*</td>
      <td width="18" class="rating2">*</td>
      <td width="18" class="rating2">*</td>
      <td width="18" class="rating2">*</td>
      <td width="18" class="rating2">*</td>
        <td width="71"></td>
    </tr><tr>
      <td width="12"><span class="style2">coloso</span></td>
      
    </tr>
      <tr>
      <td >&nbsp;</td>
    </tr></table>
     </td>
    <tr>
      <td width="224" height="40" rowspan="3"><strong>Details:</strong></td>
    </tr>
    <tr>
      <td width="106" height="28"><a href="#"><img src="../images/add to Car.gif" alt="df" width="99" height="28" /></a></td>
    </tr><tr>
      <td height="25"><a href="#"><img src="../images/viewcart.gif" alt="rt" width="99" height="28" /></a></td>
    </tr>
    <tr>
      <td width="224" height="29"><ul>
        <li>coloso mentiroso</li>
      </ul></td>
    </tr>
    <tr>
      <td width="224" height="29"><ul>
        <li>coloso mentiroso</li>
      </ul></td>
    </tr>
    <tr>
      <td width="224" height="21"><ul>
        <li>coloso mentiroso</li>
      </ul></td>
    </tr><tr>
      <td height="12" colspan="2"><img src="../images/line..gif" alt="as" width="300" height="7" /></td>
    </tr>
    
    <tr></tr><td rowspan="2">
    <table width="162" align="center" class="smallthumbs">
    <tr>
    
    <td width="46" height="65"><a href="#"><img src=',$row[0] ,' alt="df" width="50" height="50"/></a></td>
    <td width="36"><a href="#"><img src="../images/image1.jpg" alt="we" width="50" height="50" /></a></td>
    <td width="57"><a href="#"><img src="../images/launch.jpg" alt="bn" width="50" height="50" /></a></td>
    <td width="36"><a href="#"><img src="../images/image1.jpg" alt="we" width="50" height="50" /></a></td>
    </tr>
    </table></td> 
    <td rowspan="4">&nbsp;</td> 
    <td height="49"><strong>Rating and Review:</strong></td><td align="center"><a href="#">Add Review</a></td>
    <tr>
      <td rowspan="1" height="4" ><table style="font-size:10; position:relative; left:26px;">
      <td width="58">One star</td>
      <td width="40">*****</td>
      <td width="25">[23]</td>
      </table></td>
    </tr><td rowspan="2"></td>
    <tr><td height="4"><table style="font-size:10; position:relative; left:26px; ">
      <td width="58">One star</td>
      <td width="40">*****</td>
      <td width="25">[23]</td>
      </table></td>
    </tr>
    <td width="321" rowspan="7"></td>
    
    <td width="544" rowspan="7">&nbsp;</td>
      <td width="224" height="4"><table style="font-size:10; position:relative; left:26px;">
      <td width="58">One star</td>
      <td width="40">*****</td>
      <td width="25">[23]</td>
      </table></td>
      <tr><td width="224" height="4"><table style="font-size:10; position:relative; left:26px;">
      <td width="58">One star</td>
      <td width="40">*****</td>
      <td width="25">[23]</td>
      </table></td></tr>
    
    
    
    
      <td width="224" height="4"><table style="font-size:10; position:relative; left:26px;">
      <td width="58">One star</td>
      <td width="40">*****</td>
      <td width="25">[23]</td>
      </table></td>
      <tr>
        <td height="4" colspan="2"><img src="../images/line..gif" alt="df" width="330" height="7" /></td>
      </tr>
    
    
    
    <tr>
      <td width="224" height="52"><strong>Items Specifications:</strong></td>
    </tr>
        <td width="224" height="4" style="font-size:11;"><ul>
          <li>Lemon</li>
        </ul></td>
    <tr>
      <td width="224" height="4" style="font-size:11;"><ul>
        <li>Marincra</li>
      </ul></td>
    </tr>
      <td width="321" height="29" rowspan="5">&nbsp; </td>
    <td width="544" height="29" rowspan="5">&nbsp;</td>
    
    
    
    
    
    
    
        <td height="1" colspan="1" style="font-size:11;"><ul>
          <li>Sal</li>
        </ul></td>
        <tr>
          <td height="1" style="font-size:11;"><ul>
            <li>Tomatos</li>
          </ul></td>
        </tr> <tr>
          <td height="1" style="font-size:11;"><ul>
            <li>Plums</li>
          </ul></td>
        </tr> <tr>
          <td height="1" style="font-size:11;"><ul>
            <li>Saludos</li>
          </ul></td>
        </tr> <tr>
          <td height="1" style="font-size:11;"><ul>
            <li>Asucar</li>
          </ul></td>
        </tr>
      
    </table>	
    ';}
    }
    ?>
    
    <div id="comments">
      <?php foreach($sql as $comment): ?>
        <div class="comment" style="margin-bottom: 2em;">
    	    <div class="author">
    	      <?php echo htmlentities($fullname); ?> wrote:
    	    </div>
          <div class="body">
    				<?php echo strip_tags($cons '<strong><em><p>'); ?>
    			</div>
    	    <div class="meta-info" style="font-size: 0.8em;">
    	      <?php echo datetime_to_text($created); ?>
    	    </div>
        </div>
      <?php endforeach; ?>
      <?php if(empty($sql)) { echo "No Comments."; } ?>
    </div>
    
    <tr><td><table width="487" style="top:850px;" class="calamar"><td width="479" style=" line-height:3;"><strong>Comments:</strong></td>
    
    <tr></tr><td style="font-family:\'Times New Roman\', Times, serif; font-size:14px;">
    
    <form id="itemcomments" action="itemdetails.php" method="post">
    
      <fieldset>
    
        <legend>Make a comment on this item</legend>
    
        <div>
    
          <label for="nickname">Nickname:</label>
    
          <input type="text" name="nickname" id="nickname" maxlength="85" />
    
        </div>
    
        <div>
    
          <label for="fullname">Full Name:</label>
    
          <input type="text" name="fullname" id="fullname" maxlength="85" />
    
        </div>
    
        <div>
    
          <label for="pros">Pros:</label>
    
          <textarea name="pros" id="pros" cols="35" rows="5"></textarea>
    
        </div>
    
        <div>
    
          <label for="cons">Cons:</label>
    
          <textarea name="cons" id="cons" cols="35" rows="5"></textarea>
    
        </div>  
    
        <input type="submit" name="submit" value="Add Comment">
    
        <input type="reset" value="Reset Fields">   
    
      </fieldset>
    
    </form>
    </table>
    </td>
    </tr>
    
    
    <?php
    echo'</td>';
    echo'</tr>';
    echo '</table>';
    ?>
    
    
    PHP:
     
    co.ador, Jul 12, 2009 IP
  11. co.ador

    co.ador Peon

    Messages:
    120
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #31
    to make things simpler for you guys I will be more specific in display of the comments. on the SELECT comments script part to display the comment will be better if I put appetizers_id instead of id so it will select the comments only if appetizers_id (a related database field in comments) matches the variable $id,

    
    <?php
    $sql = "SELECT * FROM comments ";
        $sql .= " WHERE appetizers_id= '$id '"
        $sql .= " ORDER BY created ASC";
    	?>
    PHP:
    THat id value come from items.php through the url Now that id=1 value in the url is set in here:
    
    if( isset($_GET['id']))
    {
        $id = $_GET['id'];
    }
    ?>
    PHP:
    and it is use to display the items in itemdetails.php

    <?php 
    
    
    $query = 'SELECT * FROM menu WHERE id = '.intval($id). '  LIMIT 1 ;'; 
    
    // execute query 
    $result = mysql_query($query) or die ("Error in query: $query. ".mysql_error()); 
    
    // see if any rows were returned 
    if (mysql_num_rows($result) > 0) { 
    $row = mysql_fetch_row($result); {
    echo '<table width="100%"  border="0" cellspacing="0" cellpadding="0" class="itemdetails">
    <tr><td width="1100" height="417" bgcolor="#FFFFFF" class="tento">
    <table class="cafe"><tr><td width="547">
    <a href="#"><h3 align="justify" style="position:relative;  height:5px;  top: 10px;">',$row[3] ,'</h3></a>
    </td>
    </tr>
    </table>
    <table width="1215" height="609" class="chencho" >
     <td class="largethumb" rowspan="8" align="center">
    <a href="#"><img src=',$row[0] ,' width="270" height="160" alt="coloe"/></a></td>
    <td width="544" rowspan="8" padding="0"  ><table width="252" style="font-size:12px; position:relative; top:-6px;">
      <td width="1">&nbsp;</td>
      <td width="54" bgcolor="#FFFFFF"><strong>Price:</strong></td>
      <td colspan="7">$<span class="style3">',$row[4] ,'</span></td>
    <tr>
      <td class="style1">&nbsp;</td>
      <td colspan="7" class="style3">&nbsp;</td>
    </tr>
    <tr><td>&nbsp;</td><td><strong>Raiting:</strong></td>
      <td width="18" class="rating2">*</td>
      <td width="18" class="rating2">*</td>
      <td width="18" class="rating2">*</td>
      <td width="18" class="rating2">*</td>
      <td width="18" class="rating2">*</td>
        <td width="71"></td>
    </tr><tr>
      <td width="12"><span class="style2">coloso</span></td>
      
    </tr>
      <tr>
      <td >&nbsp;</td>
    </tr></table>
     </td>
    <tr>
      <td width="224" height="40" rowspan="3"><strong>Details:</strong></td>
    </tr>
    <tr>
      <td width="106" height="28"><a href="#"><img src="../images/add to Car.gif" alt="df" width="99" height="28" /></a></td>
    </tr><tr>
      <td height="25"><a href="#"><img src="../images/viewcart.gif" alt="rt" width="99" height="28" /></a></td>
    </tr>
    <tr>
      <td width="224" height="29"><ul>
        <li>coloso mentiroso</li>
      </ul></td>
    </tr>
    <tr>
      <td width="224" height="29"><ul>
        <li>coloso mentiroso</li>
      </ul></td>
    </tr>
    <tr>
      <td width="224" height="21"><ul>
        <li>coloso mentiroso</li>
      </ul></td>
    </tr><tr>
      <td height="12" colspan="2"><img src="../images/line..gif" alt="as" width="300" height="7" /></td>
    </tr>
    
    <tr></tr><td rowspan="2">
    <table width="162" align="center" class="smallthumbs">
    <tr>
    
    <td width="46" height="65"><a href="#"><img src=',$row[0] ,' alt="df" width="50" height="50"/></a></td>
    <td width="36"><a href="#"><img src="../images/image1.jpg" alt="we" width="50" height="50" /></a></td>
    <td width="57"><a href="#"><img src="../images/launch.jpg" alt="bn" width="50" height="50" /></a></td>
    <td width="36"><a href="#"><img src="../images/image1.jpg" alt="we" width="50" height="50" /></a></td>
    </tr>
    </table></td> 
    <td rowspan="4">&nbsp;</td> 
    <td height="49"><strong>Rating and Review:</strong></td><td align="center"><a href="#">Add Review</a></td>
    <tr>
      <td rowspan="1" height="4" ><table style="font-size:10; position:relative; left:26px;">
      <td width="58">One star</td>
      <td width="40">*****</td>
      <td width="25">[23]</td>
      </table></td>
    </tr><td rowspan="2"></td>
    <tr><td height="4"><table style="font-size:10; position:relative; left:26px; ">
      <td width="58">One star</td>
      <td width="40">*****</td>
      <td width="25">[23]</td>
      </table></td>
    </tr>
    <td width="321" rowspan="7"></td>
    
    <td width="544" rowspan="7">&nbsp;</td>
      <td width="224" height="4"><table style="font-size:10; position:relative; left:26px;">
      <td width="58">One star</td>
      <td width="40">*****</td>
      <td width="25">[23]</td>
      </table></td>
      <tr><td width="224" height="4"><table style="font-size:10; position:relative; left:26px;">
      <td width="58">One star</td>
      <td width="40">*****</td>
      <td width="25">[23]</td>
      </table></td></tr>
    
    
    
    
      <td width="224" height="4"><table style="font-size:10; position:relative; left:26px;">
      <td width="58">One star</td>
      <td width="40">*****</td>
      <td width="25">[23]</td>
      </table></td>
      <tr>
        <td height="4" colspan="2"><img src="../images/line..gif" alt="df" width="330" height="7" /></td>
      </tr>
    
    
    
    <tr>
      <td width="224" height="52"><strong>Items Specifications:</strong></td>
    </tr>
        <td width="224" height="4" style="font-size:11;"><ul>
          <li>Lemon</li>
        </ul></td>
    <tr>
      <td width="224" height="4" style="font-size:11;"><ul>
        <li>Marincra</li>
      </ul></td>
    </tr>
      <td width="321" height="29" rowspan="5">&nbsp; </td>
    <td width="544" height="29" rowspan="5">&nbsp;</td>
    
    
    
    
    
    
    
        <td height="1" colspan="1" style="font-size:11;"><ul>
          <li>Sal</li>
        </ul></td>
        <tr>
          <td height="1" style="font-size:11;"><ul>
            <li>Tomatos</li>
          </ul></td>
        </tr> <tr>
          <td height="1" style="font-size:11;"><ul>
            <li>Plums</li>
          </ul></td>
        </tr> <tr>
          <td height="1" style="font-size:11;"><ul>
            <li>Saludos</li>
          </ul></td>
        </tr> <tr>
          <td height="1" style="font-size:11;"><ul>
            <li>Asucar</li>
          </ul></td>
        </tr>
      
    </table>	
    ';}
    }
    ?>
    PHP:
    My question is how can that be possible to insert the $id variable value in the appetizers_id value each time a user insert a comment. Right now the value 0 is inserted in the table field appetizers_id in:
    
    <?php
    
    if(isset($_POST['submit' ])){ 
    
    $nickname = mysql_real_escape_string($_POST['nickname']);
    
    $fullname = mysql_real_escape_string($_POST['fullname']);
    
    $pros = mysql_real_escape_string($_POST['pros']);
    
    $cons = mysql_real_escape_string ($_POST['cons']);
    
    $id2 = (int) $_GET['id']; 
     $query = "INSERT INTO comments VALUES ('','$appetizers_id', NOW(), '$nickname', '$fullname' ,'$pros', '$cons')";
    echo $query;
    $result = mysql_query($query) or die (mysql_error());
    
        echo "Thanks for your comment";
    
    }
    
    ?>
    PHP:
    would that be possible to auto insert the value in the appetizers_id as the variable $id value coming through the URL every time a user make a comment on that item..? so that in the query:

    
    <?php
    $sql = "SELECT * FROM comments ";
        $sql .= " WHERE appetizers_id= '$id '"
        $sql .= " ORDER BY created ASC";
    	?>
    PHP:
    mysql get able to select only the comments assigned to that item by displaying the comments that only match $id value through the appetizers_id field in the comments table?

    As I mentioned before about the foreach loop scripted below, used to display the comments but it is not working right now, beside the fact that I have not a related database fields with value to match the $id variable in the URL so it can print the comments or values related to the appetizers_id field.

    the foreach loop:
    <div id="comments">
      <?php foreach($sql as $comment): ?>
        <div class="comment" style="margin-bottom: 2em;">
    	    <div class="author">
    	      <?php echo htmlentities($fullname); ?> wrote:
    	    </div>
          <div class="body">
    				<?php echo strip_tags($cons '<strong><em><p>'); ?>
    			</div>
    	    <div class="meta-info" style="font-size: 0.8em;">
    	      <?php echo datetime_to_text($created); ?>
    	    </div>
        </div>
      <?php endforeach; ?>
      <?php if(empty($sql)) { echo "No Comments."; } ?>
    </div> 
    PHP:
     
    co.ador, Jul 12, 2009 IP
  12. co.ador

    co.ador Peon

    Messages:
    120
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #32
    Goramba I got the insertion of the $id variable into the appetizers_id field

    <input type="hidden" name="appetizers_id" value="<?php echo $id ?>">

    It is cool inserting each value in appetizers_id so it can pick up the comments by appetizers_id
     
    co.ador, Jul 12, 2009 IP
  13. wd_2k6

    wd_2k6 Peon

    Messages:
    1,740
    Likes Received:
    54
    Best Answers:
    0
    Trophy Points:
    0
    #33
    From what I can see you are never actually running the query to retrieve the comments.

    OK firstly, change:

    
    <?php
    $sql = "SELECT * FROM comments ";
        $sql .= " WHERE appetizers_id= '$id '"
        $sql .= " ORDER BY created ASC";
        ?>
    
    PHP:
    to:

    
    <?php
    $sql = "SELECT * FROM comments WHERE appetizers_id = '$id' ORDER BY created";
    ?>
    
    PHP:
    This just cleans the query up a bit and uses less resources.

    OK secondly change:

    
    <div id="comments">
      <?php while ?>
        <div class="comment" style="margin-bottom: 2em;">
            <div class="author">
              <?php echo htmlentities($fullname); ?> wrote:
            </div>
          <div class="body">
                    <?php echo strip_tags($cons '<strong><em><p>'); ?>
                </div>
            <div class="meta-info" style="font-size: 0.8em;">
              <?php echo datetime_to_text($created); ?>
            </div>
        </div>
      <?php endforeach; ?>
      <?php if(empty($sql)) { echo "No Comments."; } ?>
    </div>
    
    PHP:
    to:

    
    <?php $result = mysql_query($sql) or die("Error with query $sql: ".mysql_error()) ?>
    <div id="comments">
      <?php 
      if(mysql_num_rows($result) > 0){
    	  //Then we have comments to display
    	  //Use a while loop to loop through a retrieved array of comments
    	  while($row = mysql_fetch_array($result)){ 
       ?>
        <div class="comment" style="margin-bottom: 2em;">
            <div class="author">
            <?php $fullname = htmlentities($row['fullname'];
            	  echo htmlentities($fullname); ?> wrote:
            </div>
          <div class="body">
                    <?php $cons = strip_tags($row['cons'],'<strong><em><p>');
    				echo $cons; ?>
                </div>
            <div class="meta-info" style="font-size: 0.8em;">
              <?php echo datetime_to_text($row['created']); ?>
            </div>
        </div>
      <?php 
      } //End While Loop
      else {
    	  echo "There are no comments to display, or there was an error retrieving them";
      }
      ?>
    </div>
    
    PHP:
    Can I also advise you that you do not have to keep opening and closing PHP Blocks "<?php ?>", you only need to close it if you want to write some HTML.

    So for example at the top of your document you only need to open it once with <?php, then only close it when you need to write some HTML not as you have done, after every single statement and then re-opening it again.

    If you are still having problems then just post the whole file as it is currently, and what the problem is or the error on the screen.
     
    wd_2k6, Jul 12, 2009 IP