-
Posts
59 -
Joined
-
Last visited
Everything posted by Icewolf
-
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(); ?>
-
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?
-
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?
-
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'
-
how to use an output from one query in another
Icewolf replied to Icewolf's topic in PHP Coding Help
Thank you mac_gyve I was able to get it. -
how to use an output from one query in another
Icewolf replied to Icewolf's topic in PHP Coding Help
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. -
how to use an output from one query in another
Icewolf replied to Icewolf's topic in PHP Coding Help
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. -
how to use an output from one query in another
Icewolf replied to Icewolf's topic in PHP Coding Help
so in this case I will need to declare a local variable. -
how to use an output from one query in another
Icewolf replied to Icewolf's topic in PHP Coding Help
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. -
how to use an output from one query in another
Icewolf replied to Icewolf's topic in PHP Coding Help
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? -
how to use an output from one query in another
Icewolf replied to Icewolf's topic in PHP Coding Help
Barand I did use your code this is the results of putting that in the code. -
that works it was prod_id thanks for your help
-
how to use an output from one query in another
Icewolf replied to Icewolf's topic in PHP Coding Help
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' -
Thanks Aaron that worked but the product id is still not being captured from that row. Now it is just pulling 0.
-
how to use an output from one query in another
Icewolf replied to Icewolf's topic in PHP Coding Help
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? -
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
-
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'; ?>
-
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'];
-
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'].')"); ?>
-
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 )
-
Hi Sorry it has taken me a while to get back. but I was able to get it to work. I just had to remove the ! after the = Before ($_SESSION['user_level'] != 1 ) After ($_SESSION['user_level'] = 1 )
-
Thanks barand the person that is noresponse person is the guy i am helping. I sent him the code to see if that was what he wanted.
-
Yeah i am not getting it. I can see that the value is coming over after the user logs in. It is just weird I think this should work.
-
yes that would be what I am looking for
-
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']) . "'";