Jump to content

mal14

Members
  • Posts

    29
  • Joined

  • Last visited

Profile Information

  • Gender
    Not Telling

mal14's Achievements

Member

Member (2/5)

0

Reputation

  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
×
×
  • 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.