Jump to content

Icewolf

Members
  • Posts

    59
  • Joined

  • Last visited

Icewolf's Achievements

Member

Member (2/5)

0

Reputation

  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. Thanks for the suggestion Jixo. The PHP PDO creates the connection to the database at the time it runs the sql and then terminates the connection afterwards correct?
  3. Thanks Social I do have the open bracket in there after the if statement I must not of copied it. How else can you do the values without doing the $_GET?
  4. 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'
  5. It probably is I was using code that I know has worked in other places. I just assumd that $_post was correct but I am taking that now as when a user post a value some where is when you use that.
  6. 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.
  7. so in this case I will need to declare a local variable.
  8. Yes what I am trying to do is if a user enters a code it takes the reward that is associated with that code and adds it to their exciting rewards.
  9. No I am not sure I have been just googling on how to do these kind of things. Is there a different way of doing this?
  10. Barand I did use your code this is the results of putting that in the code.
  11. that works it was prod_id thanks for your help
  12. Thank you. I see what the issue is. it is that it is not seeing the variable being passed. Here is what I am getting when I use echo '<br>' . $sql . '<br>' . mysql_error() Bank Points have been updated. UPDATE `rewards` SET `point_earn`= `point_earn` + '' WHERE member = 'testuser' AND cat_name = 'bank'
  13. Thanks Aaron that worked but the product id is still not being captured from that row. Now it is just pulling 0.
  14. Thanks Mac_gyer yeah I am realizing that now. How would I use mysql_affected_rows()? I know the select query is working because I can see the value on the screen. I just need to figure out what the update query is doing?
×
×
  • 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.