Jump to content

Icewolf

Members
  • Posts

    59
  • Joined

  • Last visited

Posts posted by Icewolf

  1. Hi

    Can you please help me with an issue I am having? I have three description fields that I am pulling from a database. I did this so when it displays it isn't one long string. However the issue I am running into is if the 3rd description box is empty I do not what to display it. I cant figure out why it is only hitting the first display option. I created this variable $dishdesc3 = $_POST["dish_desc_3"]. I would like to say when it is NULL display the only the first 2 description boxes. Otherwise have it display all three description boxes. Is there  a way to do that?

     

    <?php
    // Include the database configuration file  
    require_once 'con_php.php'; 
    
    //check connection
    if ($con -> connect_error){
    	die ("connection failed: " . $con -> connect_error);
    }
    
    
    $chsql = "SELECT * FROM dish_pic where cat_name = 'Chicken'";
    
    $chresult = $con ->query($chsql);
    $dishdesc3 = $_POST["dish_desc_3"];
    
    if ($chresult-> num_rows >0){
    	
    	
    	while ($row = $chresult -> fetch_assoc()){
    		
    		
    	if ($dishdesc3 = "3")
    	{
    		echo"<table border='0' cellpadding='4' cellspacing='0' width='100%'>";
    		echo" <tr><td class='style1' align='center'  colspan='3' valign='top'>". $row["dish_name"] .".........................$" . $row["price"] . "<br><td></tr>
    		<tr>
    		<td class='style2' align='center' >" . $row["dish_desc"] . "<br>
    		" . $row["dish_desc_2"] . "<br>
    		<tr><td class='style3' align='center' >Serving " . $row["dish_size"] . " Calories " . $row["dish_cal"] . " Total Carbs " . $row["dish_tot_carbs"] . " Net Carbs " . $row["dish_net_carbs"] . " Fat " . $row["dish_fat"] . " Fiber " . $row["dish_fiber"] ." Protein " . $row["dish_protein"] . "<br></td></tr>
    	  	<tr><td class='style2' align='center' >Recommend Side " . $row["dish_recommend"] . "</td></tr>
    		<br>
    		";
    	echo"</table>";
    	}
    	  
    Else
    {
    		echo"<table border='0' cellpadding='4' cellspacing='0' width='100%'>";
    		echo" <tr><td class='style1' align='center'  colspan='3' valign='top'>". $row["dish_name"] .".........................$" . $row["price"] . "<br><td></tr>
    		<tr>
    		<td class='style2' align='center' >" . $row["dish_desc"] . "<br>
    		" . $row["dish_desc_2"] . "<br>
    		" . $row["dish_desc_3"] . "<br></td></tr>
    		<tr><td class='style3' align='center' >Serving " . $row["dish_size"] . " Calories " . $row["dish_cal"] . " Total Carbs " . $row["dish_tot_carbs"] . " Net Carbs " . $row["dish_net_carbs"] . " Fat " . $row["dish_fat"] . " Fiber " . $row["dish_fiber"] ." Protein " . $row["dish_protein"] . "<br></td></tr>
    	  	<tr><td class='style2' align='center' >Recommend Side " . $row["dish_recommend"] . "</td></tr>
    		<br>
    		";
    	  echo"</table>";
    	}
    	}
    }
    
    $con->close();
    ?>

     

  2. Hi

    I need some advice on what I have coded is correct. I created a shoping cart. I have the screen where the user selects the item, from there it goes to their shopping cart. From here is where I am struggling. They don't use money to make purchases the items. There is a reward system that they use to purchase the item. The first thing I need to do is validate that they have enough points to buy the item. Here is the first part of the code.

    <?php
    include 'connect.php';
    include 'timeout.php';
    include 'header_signin.php';
    
    	//check for sign in status
    	if(!$_SESSION['signed_in'])
    	{
    		echo 'You must be signed in to view cart.';
    	}
    	else
    {
    $sql ="SELECT point_earn, prod_price from rewards, shp_order_items, shp_products
    	   where user_id = member_id
    	   and product_id = prod_id
    	   and user_id = '" . mysql_real_escape_string($_SESSION['user_id']) . "'
    	   and ordr_item_id = '{$_GET['id']}'";
     $result = mysql_query($sql);
     
    	if(!$result)
    
    	while($row = mysql_fetch_assoc($result))
    {
                   
    			$pe = $row['point_earn'];
    			$pp = $row['prod_price'];
    			 
    			
    }
    
    if ($pe >= $pp)
    
    

    from here I need a couple of things to happen. I need to move these items from one table to the next to show the items have been purchased. From there I need to subtract the price from the rewards they already have. Then finally update that row so it will no longer show in their cart. I know the first part and the last part work. But the update the rewards is not working. Here is the rest of the code.

    $sqlint = "INSERT INTO `shp_orders`(`ordr_item_id`, `order_date`, `order_status`) VALUES ('{$_GET['id']}',Now(),'Processing')";
       
       $results = mysql_query($sqlint);
       
       $sqlup = sprintf ("UPDATE `rewards` SET `point_earn` = `point_earn` - $pp 
       WHERE member_id = '" . mysql_real_escape_string($_SESSION['user_id']) . "'");
       
       $resultup = mysql_query($sqlup);
       
       $sqloup = "UPDATE `shp_order_items` SET `item_ordered`= -1 WHERE ordr_item_id = '{$_GET['id']}'";
       
       $resultoup = mysql_query($sqloup);
       
       echo 'Item has been ordered';
       //header('Refresh: 3;url=getitemsshp.php');
       echo '<br>' . $sqlup . '<br>' . mysql_error();
    }
    
    else
    {
       echo 'There are not enough bank points to purchase item.';
        header('Refresh: 3;url=getitemsshp.php');
    }
    }
    
    include 'footer.php';
    ?>
    

    When I run the debugger code here is what I am getting. What I am not sure of is if I have the multipule queries are correct.

    Item has been ordered
    UPDATE `rewards` SET `point_earn` = `point_earn` - WHERE member_id = '3'

  3. I guess I am not understanding what I am missing. Because isn't this creating a local variable

    $rp = $row['redeem_points'];
    

    Shouldn't I be able to use this later on?

    UPDATE `rewards` 
                           SET `point_earn`= `point_earn` +  $_POST['rp']
                            WHERE member = '" . mysql_real_escape_string($_SESSION['user_name']) . "' 
    						AND cat_name = 'bank'");
    

    From what I can tell it is not recognizing it. From what I can tell it is not bringing over the value from the select query.

  4. Thank you for looking but when I add echo

    echo '<td><a href="addtobasket.php?acion&id={$row['product_id']}">Select Item</a></td>';
    

    I get this error now

    Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in /home/pdogclan/public_html/community/shop.php on line 40

  5. Hi

    I need to pull a value from the database when a user enters in a code and add it to another table. The select query is working I have it displayed on the screen. It even says that the database has been updated. However when I go and look in the database the value has not been updated. I think it has to do with the $post but I am not sure.

     

    Thanks

    <!DOCTYPE html>
    <?php
    
    include 'connect.php';
    include 'header_signin.php';
    include 'timeout.php';
    
    if($_SERVER['REQUEST_METHOD'] != 'POST')
    {
    	//someone is calling the file directly, which we don't want
    	echo 'This file cannot be called directly.';
    }
    else
    {
    	//check for sign in status
    	if(!$_SESSION['signed_in'])
    	{
    		echo 'You must be signed in to post a reply.';
    	}
    	else
    	{
    	
    	$sql = " Select * from redeemer
    		 where redeem_code = '".$_POST['redeem_code']."'";
    		 $result = mysql_query($sql);
    	
    	
    	if(!$result)
    		{
    			echo 'Redeemer code is not valid, please try again.';
    		}
    		else 
       {
         echo '<table border="1">
    			  <tr>
    				<th>Code</th>
    				<th>points</th>
    				
    			  </tr>';	
    			
    
    while($row = mysql_fetch_assoc($result))
    {
            echo '<tr>';
    			echo '<td>' . $row['redeem_code'] . '</td>';
    			echo '<td>'. $row['redeem_points']. '</td>';
    			
    		 echo '</tr>';
            
    			$_SESSION['redeem_points'] 	= $row['redeem_points'];
    }
    		
    		//a real user posted a real reply
              
    		  		  $sql = sprintf("UPDATE `rewards` 
                            SET `point_earn`= `point_earn` + '". mysql_real_escape_string($_POST['redeem_points'])."' 
                            WHERE member = '" . mysql_real_escape_string($_SESSION['user_name']) . "' AND cat_name = 'bank'");
    						
    		$result = mysql_query($sql);
    						
    		if(!$result)
    		{
    			echo 'Redeemer code is not valid, please try again.';
    		}
    		else
    		{
    			echo 'Bank Points have been updated.';
    	    }
          }
    	}
    }
    
    include 'footer.php';
    ?>
    	
    	
    
  6. Thank you Ch0cu3r. That was it.Now I just need to figure out why it is pulling the wrong product id.

     

    I need to figure out how to pull the product id of the line they are on now. Here is what I have.

    include 'connect.php';
    include 'timeout.php';
    include 'header_signin.php';
    
    echo '<a class="item" href="redeemer.php">Redeemer</a>';
    
        $sql = "SELECT * FROM shp_products";
    	 
    	$result = mysql_query($sql);
     
    	if(!$result)
    	 
    {	 
    	
    	echo "There are no products.";
    	 
    }
    	 
    	else{
    	 
    	echo '<table border="1">
    			  <tr>
    			    <th>Image</th>
    				<th>Product</th>
    				<th>Description</th>
    				<th># of Bank Points</th>
    				
    			  </tr>';	
    			
    
    while($row = mysql_fetch_assoc($result))
    {
            echo '<tr>';
    			echo "<td><img src='images/".$row['prod_image']."'></td>";
    			echo '<td>'. $row['prod_name']. '</td>';
    			echo '<td>' . $row['prod_desc']. '</td>';
    			echo '<td>' . $row['prod_price']. '</td>';
    			echo '<td><a href="addtobasket.php?acion&id=1">Select Item</a></td>';
    			
    		 echo '</tr>'; 
    	
    						$_SESSION['prod_id'] 	= $row['prod_id'];
    
  7. Hi

    I am trying to create a insert query that stores some session values. However I am getting an error and can't figure out what is causing it. I have tried to search for the error but can't find the answer.

     

    Here is the error.

    Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/pdogclan/public_html/community/addtobasket.php on line 6

     

    Here is the code

    <?php
    include 'connect.php';
    include 'timeout.php';
    include 'header_signin.php';
    
    $sql = ("INSERT INTO `shp_order_items`(`product_id`, `user_id`) VALUES ('.$_SESSION['prod_id'].' , '.$_SESSION['user_id'].')");
    
    ?>
    
  8. Thank you for that information I didn't know what the == was for but I changed it to this. I was having problems when a user wasn't signed in they saw the admin header.

     if($_SESSION['signed_in'] == false | $_SESSION['user_level'] != 1 )
    
  9. Sorry this part is new to me. I have never really tried anything like this. I am not understanding what you are saying. I mean if we need to create something that is cool.

    Here is the select statment I would want to use. I would be using the max_point and point_earn.

    $sql = "SELECT
    			cat_name,
    			max_point,
    			point_earn
    		FROM rewards
    		where member =  '" . mysql_real_escape_string($_SESSION['user_name']) . "'";
    
×
×
  • 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.