Jump to content

mal14

Members
  • Posts

    29
  • Joined

  • Last visited

Everything posted by mal14

  1. Just gave that a shot! Unfortunately, the progress bar disappears when I do that
  2. I'm in the middle of producing a calories tracker. My users can set weight loss goals and then use the exercise calorie calculator to find out how many calories they've lost from particular exercises. I've produced a progress bar to show users their progress, however the progress bar does this for all of the users goals combined, not the most recent goal set. How could I set my progress bar to focus on just the most recent goal set by the user? This is what I have so far <?php $con=mysqli_connect("localhost","root","password","registration"); if (mysqli_connect_errno()) { die("Failed to connect to MySQL: " . mysqli_connect_error()); } $bar_length = 500; $bar_height = 40; $sql = "SELECT SUM(calories) as calories , CASE g.weightunit WHEN 'lbs' THEN 3500 ELSE 7700 END * weightlost as target_calories FROM goal g INNER JOIN tracklog t USING (userid) WHERE userid = ?"; $stmt = $con->prepare($sql); $stmt->bind_param('i', $_SESSION['userid']); $stmt->execute(); $stmt->bind_result($calories, $target); $res = $stmt->fetch(); function progress_bar($width, $height, $calories, $target) { $bar = "<p style='padding-left: 30px'>"."<svg width='$width' height='$height' align='center' view_box='0 0 $width $height'>\n <rect x='0' y='0' width='$width' height='$height' align='right' fill='#CCC' />\n"; // calc width of bar for calories already burned if ($target==0) { $target = 1; } if ($calories > 0) { $cal_width = $calories * $width / $target; $bar .= "<rect x='0' y='0' align='center' width='$cal_width' height='$height' stroke='#ccc' fill='#55d5e7' />\n"; } else { $bar .= "<text x='5' y='16' align='center' font-size='9pt'>No data for user</text>\n"; } $bar .= "</svg>\n"; return $bar; } mysqli_close($con); ?> <p align="center" class="font-3" style="font-size: 16px"><br><br >Calories burned to date : <?=$calories?><br> Target calories : <?=$target?><br> <?= progress_bar($bar_length, $bar_height, $calories, $target) ?>
  3. Thank a lot for the advice! It's helped a lot!
  4. I'm trying to allow my users to edit their profile information. I've made an attempt at it and have this code so far... edit.html page <?php session_start(); ?> <!DOCTYPE html> <html> <head> <title>Login</title> <link rel="stylesheet" type="text/css" href="style.css"> </head> <body> <div class="header"> </div> <section id="edit" > <div id="edit"> <b>Edit your Profile</b> <br><br> Please enter your details below to update your profile. <br><br> <form method="post" action="editprofile.php" name="editform" id="editform"> <table width=700px border=0 cellspacing=10><tr><td valign=top><table border=0> <b>Required Information:</b><br><br> <tr><td> <b>Username:</b> </td><td> <?php echo($_SESSION["username"]); ?> </td></tr><tr><td> <b>Email Address:</b> </td><td> <input type="text" name="email" value="<?php echo $email; ?>"> </td></tr></table></td><td valign=top> <table border=0> <b>Optional Information:</b><br><br> <tr><td> <b>Gender:</b> </td><td> <input type="text" name="gender" id="gender" value="<?php echo $gender; ?>"> </td></tr><tr><td> <b>dob:</b> </td><td> <input type="text" name="dob" id="dob" value="<?php echo $dob; ?>"> </tr></td><tr><td valign=top> <b>height:</b> </td><td> <input type="text" name="height" id="height" value="<?php echo $height; ?>"> </td></tr></td> </table> </td></tr> </table> <input type="submit" name="register" id="register" value="Update" class=btn /> </form> </div> </form> </body> </html> editprofile.php page <?php if(!empty($_SESSION['LoggedIn']) && !empty($_SESSION['userid'])) { $nameuser = $_SESSION['userid']; $checkinfo = query("SELECT * FROM users WHERE id = $_SESSION[userid]"); $result = mysqli_query($con, $query); while($results = mysql_fetch_array($checkinfo,MYSQL_ASSOC)){ $id = $results['userid']; $username = $results['username']; $email = $results['email']; $gender = $results['gender']; $dob = $results['dob']; $height = $results['height']; } if ($_SERVER['REQUEST_METHOD'] == 'POST') { $editEMAIL=$_POST['email']; $editgender=$_POST['gender']; $editdob=$_POST['dob']; $editheight=$_POST['height']; $editusername=$_POST['username']; $editquery = mysql_query("UPDATE users SET Email='$editEMAIL' , gender='$editgender', dob='$editdob', height='$editheight' WHERE username='$editusername'"); if($editquery == true) { echo "<b>Success!</b>"; echo "Your profile was successfully updated. Please click<a href=\"viewprofile.php\"> here </a>to view."; } else { echo "<b>Error</b>"; echo "<p>Sorry, your profile update failed. Please go back and try again.</p>"; } } } ?> However, I keep getting these errors but I'm not sure why PHP Notice: Undefined variable: email in /Applications/MAMP/htdocs/FitFab/edit.html on line 65 PHP Notice: Undefined index: gender in /Applications/MAMP/htdocs/FitFab/edit.html on line 72 PHP Notice: Undefined variable: dob in /Applications/MAMP/htdocs/FitFab/edit.html on line 76 PHP Notice: Undefined variable: height in /Applications/MAMP/htdocs/FitFab/edit.html on line 80
  5. I've tried doing this however, it doesn't allow me to store any data into my database anymore
  6. Ohhh I see! So how could we get the calories burned to be against just the latest goal?
  7. The bar now works! This comes up... Calories burned to date : 4218 Target calories : 154000
  8. I would like the latest goal set to be the one the user tracks their calories burned against, considering that their previous goal had been met already.
  9. So I changed the each $target to $target_calories. These are the calories the user has burned: Calories Burned: 876 Calories Burned: 530 And this is the total: Calories burned to date : 4218 So I think the sum calculation may be wrong?
  10. There is a target "weightlost" for that user. I inputted another just to make sure.
  11. This error pops up... Division by zero in /Applications/MAMP/htdocs/FitFab/track.html on line 254 $cal_width = $calories * $width / $target;
  12. I've just tried that So the bar comes up and when I enter an activity to find out how many calories are burned(530) and save it to the database... Calories burned to date : Target calories : ^^this comes up and the bar stays blank
  13. When I do that these errors come up... PHP Warning: mysqli_stmt::bind_param(): Number of variables doesn't match number of parameters in prepared statement in /Applications/MAMP/htdocs/FitFab/track.html on line 244 PHP Fatal error: Uncaught Error: Call to undefined function progress_bar() in /Applications/MAMP/htdocs/FitFab/track.html:249 Stack trace: #0 {main} thrown in /Applications/MAMP/htdocs/FitFab/track.html on line 249 Line 249: echo progress_bar($bar_length, $bar_height, $calories, $target);
  14. Because I was getting this error before... PHP Notice: Use of undefined constant userid - assumed 'userid' in /Applications/MAMP/htdocs/FitFab/track.html on line 244 When I added the quotes the error didn't show up again
  15. This error comes up... PHP Fatal error: Uncaught Error: Cannot pass parameter 2 by reference in /Applications/MAMP/htdocs/FitFab/track.html:244 Stack trace: #0 {main} thrown in /Applications/MAMP/htdocs/FitFab/track.html on line 244 That refers to this line: $stmt->bind_param('i', '$_SESSION[userid]');
  16. I've just tried this but nothing is being output to my browser again. Is there something missing?
  17. <?php $con=mysqli_connect("localhost","root","password","registration"); if (mysqli_connect_errno()) { die("Failed to connect to MySQL: " . mysqli_connect_error()); } $userid = $_SESSION[userid]; $bar_length = 400; $bar_height = 20; $sql = "SELECT SUM(caloriesburned) as calories_burned , CASE g.weightunit WHEN 'lbs' THEN 3500 ELSE 7700 END * weightlost as target_calories FROM goal g INNER JOIN tracklog t USING (userid) WHERE userid = $_SESSION[userid]"; $stmt = $pdo->prepare($sql); $stmt->execute( [$userid] ); $res = $stmt->fetch(); echo progress_bar($bar_length, $bar_height, $res['calories'], $res['target_calories']); mysqli_close($con); ?>
  18. I really appreciate you taking out time to help me! I've tried applying this, however nothing comes up in my browser :/
  19. Database: registration Tables... users: - id - firstname - surname - dob - height - username - email - password goal: - id - weightlost - weightunit - whenby - userid tracklog: - id - currentweight - weightunit - activitytime - timeunit - activity -caloriesburned - userid
  20. Thank you for this! How would I get the calories and the target (from lbs/kg into calorie form) from my sql database?
  21. When I said the blank part to show the lbs or kg, I meant for them to be converted into the total number of calories needed to be burned off. I don't, requinix :/ I'm very new to this
  22. Well, I'm planning to set the weight units, as: 1 lb = 3,500 calories 1 kg = 7,700 calories (^^ I'm unsure how to set these values) From the activity and the time the user enters, the number of calories burned from that activity will be calculated. Then I can take this value away from their set goal.
  23. Yeah that's right! I want the progress bar to show the shaded part to be the calories burned and the rest of the bar to be blank which represents the total lbs or kgs wanted to be worked off by the user. I have all the data stored on my database - so the calories burned after each exercise and the weight wanting to be lost by each user in either lbs or kg.
  24. I'm making a calories burned calculator which links to goals the user has made. I want to create a progress bar that updates when the user clicks a button that shows how many calories the user has yet to burn in order for them to reach their goal. I've stored the amount of calories burned for each activity the user inputs. The users goals are set in either lbs or kg, so I'm not sure how I can set a value for these units. Also, I'm not sure how I should calculate the calories left to burn. I've looked online, however can't find anything that relates to how to made a progress bar with data from an sql database. Database: 'registration' Table: 'tracklog' and 'goal' Any help would be much appreciated!!!
×
×
  • 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.