Jump to content

davidjones1990

Members
  • Posts

    20
  • Joined

  • Last visited

    Never

Everything posted by davidjones1990

  1. Thanks for your input, I cant believe I didn't think of that, my method was so long winded
  2. Hello everybody, I have a script that allows a user to set themselves a target and a script that allows them to edit the target if they decide to. Now everything works as it should until the data from the form (on the edit target page) should be updated in the database. I require that the user must update at least one field. For example they may want to extend the completion date so I would only want to update the completion date field in the database and the fields the user left blank should not be updated in the database. The problem I am having is regardless of if the user enter a value into the field it updates the database so if the user leaves a field blank it updates the database will a blank value. Here is my code: //If the user clicks the update button on a WEIGHT LOSS target run the following code to update the database if(isset($_POST['target_weight_loss_update'])){ $target_weight_loss_update = $_POST['target_weight_loss_update']; $weight_loss_complete_update = $_POST['weight_loss_complete_update']; $weight_loss_comment_update = $_POST['weight_loss_comment_update']; $weight_loss_user_id_update = $_POST['weight_loss_user_id_update']; //Check that at least one value has been entered into the form if(empty($target_weight_loss_update) && empty($weight_loss_complete_update) && empty($weight_loss_comment_update)){ $error_msg = 'Please enter at least one value to update your '.$target_type.' target'; } //Check to see what variables have values in them so we know what fields to update in datebase //If the user has entered a value for their TARGET WEIGHT LOSS update that value in the database if(isset($target_weight_loss_update) || !empty($target_weight_loss_update)){ $target_weight_loss_update_sql = mysql_query("UPDATE user_targets SET target_weight='$target_weight_loss_update' WHERE id='$target_id' LIMIT 1") or die (mysql_error()); //Check that the update was successful if($target_weight_loss_update_sql){ $error_msg = 'Target '.$target_type.' updated successfully'; } else { $error_msg = 'Could not update target. Please try again.'; } } //If the user has entered a value for their TARTGET WEIGHT LOSS DATE update that value in the database if(isset($weight_loss_complete_update) || !empty($weight_loss_complete_update)){ $weight_loss_completion_date_sql = mysql_query("UPDATE user_targets SET target_date='$weight_loss_complete_update' WHERE id='$target_id' LIMIT 1") or die (mysql_error()); //Check that the update was successful if($weight_loss_completion_date_sql){ $error_msg = 'Target '.$target_type.' updated successfully'; } else { $error_msg = 'Could not update target. Please try again.'; } } //If the user has entered a value for their TARGET WEIGHT LOSS COMMENT update that value in the database if(isset($weight_loss_comment_update) || !empty($weight_loss_comment_update)){ $weight_loss_comment_update_sql = mysql_query("UPDATE user_targets SET extra_info='$weight_loss_comment_update' WHERE id='$target_id' LIMIT 1") or die (mysql_error()); //Check that the update was successful if($weight_loss_comment_update_sql){ $error_msg = 'Target '.$target_type.' updated successfully'; } else { $error_msg = 'Could not update target. Please try again.'; } } } So the question I ask is how can I stop entering blank values into the database and only update the information the user enters into the form? Also I was thinking of having one mysql query at the end and using the IF statements to build the query. Thoughts? Thanks for any advice.
  3. Thank you, your method has cleaned the code up and sorted my ordering problem, many thanks
  4. I know now, in the first query I need to get a distinct target type I'll let you know how i get on
  5. No duplicates, that was the first thing I looked for Not sure that would sort it because the user can have more than one target set Also I noticed something strange. I used the same if statement but changed the query and variables etc. to Lower BMI instead of weight loss and again works but displays duplicate data. The new thing is if there are two targets displayed it will repeat two times and if there are three targets it will repeat three times. So here is a mock up of what the page looks like now. WEIGHT LOSS 1 WEIGHT LOSS 2 WEIGHT LOSS 1 WEIGHT LOSS 2 LOWER BMI 1 LOWER BMI 2 LOWER BMI 3 LOWER BMI 1 LOWER BMI 2 LOWER BMI 3 LOWER BMI 1 LOWER BMI 2 LOWER BMI 3 See what im getting at? Do you think maybe I should count the number of rows being returned with each target type and loop that number of times? Thanks for your responses.
  6. Yes of course sorry for not be clear. So there are two targets that should appear, so it should look like this TARGET 1 TARGET 2 Instead it displays like this TARGET 1 TARGET 2 TARGET 1 TARGET 2 Hope this answers your question.
  7. Hi everybody, I have a problem and was wondering if I could pick your brains. My situation is that I am making a fitness website and one feature is that the user can set themselves targets. Now each target has some fields that are mandatory (for example the date to be completed) and some fields that are unique to each target (for example if the target is weight loss I will need to grab the current weight/target weight fields). Just to make it clear I have all fields in the same database table. So I have written a script that displays that users current targets they have set. It grabs all the data correctly but it duplicates the display and although I am pretty new to php even I can tell the code if not best practise because I have a query inside a loop and a loop inside another loop. Here is the code I have done so far: //Get target types from database for that particular user $get_user_targets = mysql_query("SELECT target_type FROM user_targets WHERE user_id='$id'") or die (mysql_error()); while ($row = mysql_fetch_array($get_user_targets)){ $target_type_display = $row['target_type']; //If the target type is equal to Weight Loss run this script to get all the information and make a display if($target_type_display == 'Weight Loss'){ //Search the database for all weight loass goals $weight_loss_display_sql = mysql_query("SELECT current_weight, target_weight, target_date, date_set, extra_info FROM user_targets WHERE user_id='$id' AND target_type='$target_type_display'") or die (mysql_error()); //Put the data from the query into page variables while($row1 = mysql_fetch_array($weight_loss_display_sql)){ $current_weight_loss_dis = $row1['current_weight']; $target_weight_loss_dis = $row1['target_weight']; $weight_loss_date_set_dis = $row1['date_set']; $weight_loss_target_date_dis = $row1['target_date']; $weight_loss_extra_info_dis = $row1['extra_info']; //Convert date_set into ago time $convertedTime = ($myObject -> convert_datetime($weight_loss_date_set_dis)); $weight_loss_set = ($myObject -> makeAgo($convertedTime)); //Construst a display out of the collected variables $weight_loss_display .= '<div class="blackText" style="width: 475px"> <table width="475px" class="blackText"> <tr><td class="profileUsername" colspan="2">'.$target_type_display.'</td></tr> <tr><td width="250px">Current Weight:</td><td width="225px">'.$current_weight_loss_dis.'</td></tr> <tr><td>Target Weight:</td><td>'.$target_weight_loss_dis.'</td></tr> <tr><td>Date for completion:</td><td>'.$weight_loss_target_date_dis.'</td></tr> <tr><td>'.$weight_loss_extra_info_dis.'</td><td><h6>Date set: '.$weight_loss_set.'</h6></td></tr> </table> </div>'; } } } So far it just checks for a weight loss goal and I was going to expand the code with more if statements for each of the other types of target. So my questions are: 1)Can anybody see why the data is displaying twice? 2) Is there a better way of doing this? (NOTE: im not too worried that the code isn't best practise, I just want to get it functioning properly) Thanks in advance for any help
  8. Hey everyone, So here is my problem. I have some code to display the amount of views that page has got. In this case it is the thread in my forums section. I have used the same code to show how many people have views a certain persons profile page and that works fine but when I use it on my forum thread page I get this error. Here is the section of code: <?php $thread_id = preg_replace('#[^0-9]#i', '', $_GET['id']); $getThreadViews = mysql_query("SELECT view_count FROM forum_posts WHERE id='$thread_id' LIMIT 1") or die (mysql_error()); $row = mysql_fetch_assoc($getThreadViews); $counter = $row['view_count']; if($counter == 0){ $counter = 1; $startCounter = mysql_query("INSERT INTO forum_posts (view_count) VALUES ('$counter') WHERE id='$thread_id' LIMIT 1") or die (mysql_error()); } $threadViews = $counter+1; $appendCounter = mysql_query("UPDATE forum_posts SET view_count='$view_count' WHERE id='$thread_id'") or die (mysql_error()); ?> I have checked that there are no spelling errors so just wanted to show it to a fresh pair of eyes because its really starting to annoy me. Thanks in advance for any help.
  9. Hi thanks for the feedback, I know my code is shockingly bad but im a beginner just trying some things out at the moment. If the time comes to put anything online i'll definitely review my code and make changes for best practise. Anyway the problem was I had the comment display too far down the page Thanks for the tip about joining that will come in handy on several of my pages.
  10. Hey, I have written a script for a very simple PHP wall and comment system. This works fine but the problem I have is displaying the comments. It seems to display the comments associated with the post as well as the comments on the posts above it. I have checked the database and the post ID's are correct. Here is my code: <?php $wallDisplay = ''; $commentDisplay = ''; $wallDisplaySql = mysql_query("SELECT * FROM wall WHERE to_id='$id' ORDER BY datetime DESC") or die (mysql_error()); while($row = mysql_fetch_array($wallDisplaySql)){ $wallPostId = $row["id"]; $to_id = $row["to_id"]; $from_id = $row["from_id"]; $message = $row["message"]; $dateTime = $row["datetime"]; $getFromData = mysql_query("SELECT username FROM members WHERE id='$from_id'") or die (mysql_error()); while($row2 = mysql_fetch_array($getFromData)){ $wallUsername = $row2['username']; } $displayComments = mysql_query("SELECT * FROM wallComments WHERE wallPostId='$wallPostId' ORDER BY datetime DESC"); while($row3 = mysql_fetch_array($displayComments)){ $wallComment = $row3['comment']; $commentFrom = $row3['from_id']; $commentDate = $row3['datetime']; $getUsername = mysql_query("SELECT username FROM members WHERE id='$commentFrom'"); while($row4 = mysql_fetch_array($getUsername)){ $commentUsername = $row4['username']; } $cheersCheck_pic = "members/$commentFrom/pic1.jpg"; $cheersDefault_pic = "members/0/defaultMemberPic.jpg"; if (file_exists($cheersCheck_pic)) { $cheers_pic = "<img src=\"$cheersCheck_pic?$cacheBuster\" width=\"40px\" />"; } else { $cheers_pic = "<img src=\"$cheersDefault_pic\" width=\"40px\" />"; } $commentDisplay .= '<table width="500px" align="right" cellpadding="4" bgcolor="#FFF"> <tr> <td width="10%" bgcolor="#FFFFFF"><a href="member_profile.php?id=' . $commentFrom . '">' . $cheers_pic . '</a><br /> </td> <td width="90%" bgcolor="#DBE4FD"><a href="member_profile.php?id=' . $commentFrom . '"><span class="blackText">' . $commentUsername . '</span></a> • <span class="blackTetx">' . $commentDate . '<br /><font size="1"></font></span><br /> <span class="blackText">' . $wallComment . '</span></td> </tr> </table>'; } $cheersCheck_pic = "members/$from_id/pic1.jpg"; $cheersDefault_pic = "members/0/defaultMemberPic.jpg"; if (file_exists($cheersCheck_pic)) { $cheers_pic = "<img src=\"$cheersCheck_pic?$cacheBuster\" width=\"40px\" />"; } else { $cheers_pic = "<img src=\"$cheersDefault_pic\" width=\"40px\" />"; } $wallDisplay .= '<table width="100%" align="center" cellpadding="4" bgcolor="#FFF"> <tr> <td width="7%" bgcolor="#FFFFFF"><a href="member_profile.php?id=' . $from_id . '">' . $cheers_pic . '</a><br /> </td> <td width="93%" bgcolor="#DBE4FD"><a href="member_profile.php?id=' . $from_id . '"><span class="blackText">' . $wallUsername . '</span></a> • <span class="blackTetx">' . $dateTime . '<br /><font size="1"></font></span><br /> <span class="blackText">' . $message . '</span></td> </tr> </table> <div id="commentList">' . $commentDisplay . '</div> <div id="comment" align="right"> <form id="comment" name="comment" method="post" action="member_profile.php?id=' .$id. '"> <textarea name="comment" id="comment" rows="1" cols="35"></textarea> <input type="hidden" name="wallPostId" id="wallPostId" value="'. $wallPostId .'" /> <input type="hidden" name="commentFrom" id="commentFrom" value="'. $_SESSION['id'] .'" /> <input type="submit" name="submitComment" id="submitComment" /> </form> </div><br /> '; } ?> I have been looking at it for ages but can think why this is happening. Thanks in advance for any help
  11. Works now, although I put this in the form instead of what you said, I know your way is better but i just want to get it working for now <input type="hidden" name ='id' value="<?php echo ("$id"); ?>"/> Thanks for your help
  12. Im getting the blog entry ID from the URL so I can use it to update that blog entry with the new posted information Is that right? or do I need to go back to basics
  13. Yep, the ID corresponds to the correct ID in the database
  14. Here is my code to update a blog entry. When submitted there is no error but the database is not updated with the new info. I have a similar script on a different page and it works fine so I am confused to why this is happening. I am also a PHP beginner. Here is my code: <?php include_once ("scripts/checkuserlog.php"); include_once ("scripts/connectToMysql.php"); if (!$_SESSION['idx']) { $msgToUser = '<br /><br /><font color="#FF0000">Only site members can do that</font><p><a href="register.php">Join Here</a></p>'; include_once 'msgToUser.php'; exit(); } else if ($logOptions_id != $_SESSION['id']) { $msgToUser = '<br /><br /><font color="#FF0000">Only site members can do that</font><p><a href="register.php">Join Here</a></p>'; include_once 'msgToUser.php'; exit(); } $date = date("m.d.y"); $workoutName = ''; $workoutDescription = ''; $id = $_GET['id']; if(isset($_POST['workoutName'])){ $workoutName = $_POST['workoutName']; $workoutDescription = $_POST['workoutDescription']; $blogUpdate = mysql_query("UPDATE blog SET workoutName='$workoutName', workoutDescription='$workoutDescription' WHERE id='$id' LIMIT 1") or die (mysql_error()); if ($blogUpdate){ $successMsg = 'Blog entry updated successfully'; } else { $errorMsg = 'Problems arose during the information exchange, please try again later.'; } } $sql = mysql_query("SELECT * FROM blog WHERE id='$id' LIMIT 1"); while($row = mysql_fetch_array($sql)){ $workoutName = $row['workoutName']; $workoutDescription = $row['workoutDescription']; $dateOfEntry = $row['datetime']; } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>S.F.I - Edit Blog Entry</title> <link href="style/main.css" rel="stylesheet" type="text/css" /> <link href="style/layout.css" rel="stylesheet" type="text/css" /> </head> <body> <div id="container"> <?php include_once ("bannerFiles/bannerTemplate.php"); ?> <?php include_once ("bannerFiles/bannerMenu.php"); ?> <br /><br /> <div id="content"> <table bgcolor="#DBE4FD" width="950px"> <form action="editBlogPost.php" method="post" enctype="multipart/form-data"> <tr> <td width="200px"><span class="blackText">Workout Name:</span></td><td width="650px"><input name="workoutName" type="text" id="workoutName" value="<?php echo ("$workoutName");?>"/> <span class="blackText">Date of entry: <?php echo ("$dateOfEntry"); ?></span></td></tr> <tr> <td><span class="blackText">Workout Description:</span></td><td><textarea name="workoutDescription" cols="75" rows="10" id="workoutDescription" /><?php echo ("$workoutDescription"); ?></textarea></td></tr> <tr><td><input name="submit" id="submit" type="submit" value="Update" /></td><td><span class="errorMsg"><?php echo ("$errorMsg"); ?><?php echo ("$successMsg"); ?></span></td> </tr> </form> </table> </div> <br /><br /> <?php include_once ("footerFiles/footerTemplate.php"); ?> </div> </body> </html> Thanks in advance for any help
  15. Hi im pretty new to php but I was following a tutorial for a commenting system and implemented it onto my blog page. Anyway the problem I have is that as you go down the page each blog post displays its own comments + the comments for the posts above it. I have checked the database and the data seems to link the correct comments to the correct posts so I am confused to why this is happening. I have looked over my code and cant seem to find a problem (probably because I suck!). Here is the code for the blog page... <?php include_once ("scripts/checkuserlog.php"); include_once ("scripts/connectToMysql.php"); include_once ("functions/agoTime.php"); $myObject = new convertToAgo; $username = ''; $errorMsg = ''; $successMsg = ''; $date = date("m.d.y"); if (isset($_GET['id'])) { $id = preg_replace('#[^0-9]#i', '', $_GET['id']); } else if (isset($_SESSION['idx'])) { $id = $logOptions_id; } else { header("location: index.php"); exit(); } $id = preg_replace('#[^0-9]#i', '', $id); $sql = mysql_query("SELECT * FROM members WHERE id='$id' LIMIT 1"); $existCount = mysql_num_rows($sql); if ($existCount == 0) { header("location: index.php?msg=user_does_not_exist"); exit(); } while($row = mysql_fetch_array($sql)){ $username = $row["username"]; } if(isset($_POST['workoutName'])){ $workoutName = $_POST['workoutName']; $workoutDescription = $_POST['workoutDescription']; if ((!$workoutName) || (!$workoutDescription)) { $errorMsg = 'Please fill in both fields'; } else { $insertBlog = mysql_query("INSERT INTO blog (userid, workoutName, workoutDescription, datetime) VALUES ('$id', '$workoutName', '$workoutDescription', now())") or die(mysql_error()); if ($insertBlog){ $successMsg = '<span class="errorMsg">Workout blogged successfully</span>'; } else { $errorMsg = '<span class="errorMsg">Problems arose during the information exchange, please try again later.</span>'; } } } $getBlog = mysql_query("SELECT * FROM blog WHERE userid='$id' ORDER BY id DESC"); $blogEntries = mysql_num_rows($getBlog); if($blogEntries < 1){ $blogDisplay = '<span class="blogName">' .$username. ' has not blogged a workout yet</span>'; } else { while($row = mysql_fetch_array($getBlog)){ $blogEntryId = $row["id"]; $sql_comment = mysql_query("SELECT * FROM blog_comments WHERE post_id='$blogEntryId' ORDER BY id ASC"); $countComment = mysql_num_rows($sql_comment); if($countComment > 0){ while($row2 = mysql_fetch_array($sql_comment)){ $comment_user_id = $row2["comment_user_id"]; $sql_comment_username = mysql_query("SELECT username FROM members WHERE id='$comment_user_id' LIMIT 1"); while($row3 = mysql_fetch_array($sql_comment_username)){ $comment_username = $row3["username"];} $post_id = $row2["post_id"]; $commentBody = $row2["comment_body"]; $commentDate = $row2["comment_date"]; $displayCommentList .= '<div>' .$comment_username. ' - ' .$commentBody. ' - ' .$commentDate. '</div>'; } } else { $displayCommentList = ''; } $workoutName = $row["workoutName"]; $workoutDescription = $row["workoutDescription"]; $blogDate = $row["datetime"]; $convertedTime = ($myObject -> convert_datetime($blogDate)); $blogDate = ($myObject -> makeAgo($convertedTime)); $blogDisplay .= '<table width="950px"><tr bgcolor="#DBE4FD"><td><span class="blogName">' .$workoutName. '</span> » <span class="blogDate">' .$blogDate. '</span></td></tr> <tr bgcolor="#F1F4FE"><td><span class="blackText">' .$workoutDescription. '</span></td></tr> <tr bgcolor="#DBE4FD" valign="top"><td>' .$displayCommentList. '</td></tr> <div id="new_comment' .$blogEntryId. '" style="display:none"></div> <tr><td><textarea id="comment' .$blogEntryId. '"></textarea><input type="submit" value="Comment" onclick="javascript:SendComment(\''.$blogEntryId.'\');" /></td></tr>'; if(isset($_SESSION['id'])&&$_SESSION['id']==$id){ $blogDisplay .= '<tr bgcolor="#DBE4FD"><td><a href="editBlogPost.php?id=' .$blogEntryId. '"><span class="blackText">Edit Post</span></a> &#8211; <span class="blackText">Delete Post</span></td></tr></table><br /><br />'; } } } if(isset($_POST['deleteButton'])){ $deleteBlog = mysql_query("DELETE FROM blog WHERE id='$blogEntryId'"); if($deleteBlog){ $successMsg = 'Blog entry deleted successfully'; } else { $errorMsg = 'Could not process your request, please try again later'; } } ?> <?php if (isset($_SESSION['id'])&&$_SESSION['id']==$id) { $blogForm = '<table bgcolor="#DBE4FD" width="950px"> <form action="member_blog.php" method="post" enctype="multipart/form-data"> <tr> <td width="200px"><span class="blackText">Workout Name:</span></td><td width="650px"><input name="workoutName" type="text" id="workoutName" /> <span class="blackText">Date: ' .$date. '</span></td></tr> <tr> <td><span class="blackText">Workout Description:</span></td><td><textarea name="workoutDescription" cols="75" rows="10" id="workoutDescription" /></textarea></td></tr> <tr><td><input name="submitBlog" id="submit" type="submit" value="Blog!" /></td><td><span class="errorMsg">' .$errorMsg. '' .$successMsg. '</span></td> </tr> </form> </table>'; } else { $blogForm = ''; } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title><?php echo ("$username"); ?>'s Blog</title> <link href="style/layout.css" rel="stylesheet" type="text/css" /> <link href="style/main.css" rel="stylesheet" type="text/css" /> <script src="js/jquery-1.4.2.js" type="text/javascript"></script> <script language="javascript" type="text/javascript"> function SendComment(blogEntryId){ var comment_txt = $("#comment"+blogEntryId).val(); if(comment_txt == ""){ alert("Please enter a comment"); } else { $.post("scripts/blogComment.php", {comment: comment_txt, blogId: blogEntryId} ,function(data){ $("#new_comment"+blogEntryId).html(data); $("#new_comment"+blogEntryId).slideDown(300); }); } } </script> </head> <body> <div id="container"> <?php include_once ("bannerFiles/bannerTemplate.php"); ?> <?php include_once ("bannerFiles/bannerMenu.php"); ?><br /> <div id="content"> <span class="profileUsername"><?php echo ("$username"); ?>'s Workout Blog</span><br /><br /> <?php echo ("$blogDisplay"); ?><br /><br /> <?php echo ("$blogForm"); ?> </div><br /><br /> <?php include_once ("footerFiles/footerTemplate.php"); ?> </div> </body> </html> ...and here is the code for the blogComment.php page <?php session_start(); include_once ("connectToMysql.php"); if(isset($_POST['comment'])){ $comment = $_POST['comment']; $blogId = $_POST['blogId']; $comment_user_id = $_SESSION['id']; $username = $_SESSION['username']; $sql = mysql_query("INSERT INTO blog_comments (comment_body, post_id, comment_user_id, comment_date) VALUES ('$comment', '$blogId', '$comment_user_id', now())"); echo '<div>' .$username. ' - ' .$comment. ' - Just Now</div>'; } else { echo "Failure"; } ?> Thanks in advance for any help
  16. Sorry, here it is <?php include_once ("scripts/checkuserlog.php"); ?> <?php include_once ("scripts/connectToMysql.php"); $height = ''; $weight = ''; $heightSq = ''; $bmi = ''; $correctingFactor = ''; $bmiAlt = ''; $bmiResult = ''; $errorMsg = ''; $error_msg = ''; $id = $logOptions_id; if(isset($_POST['height'])){ $height = $_POST['height']; $weight = $_POST['weight']; if(!$height){ $errorMsg .= 'Please enter your height</br>'; } if(!$weight){ $errorMsg .= 'Please enter your weight</br>'; } else { $heightSq = pow($height,2); $bmi = $weight/$heightSq; $correctingFactor = '703'; $bmiCalc = $bmi*$correctingFactor; $bmiAlt = round($bmiCalc,1); $bmiResult = '<span class="profileUsername">Your BMI is: ' . $bmiAlt . '</span><br />'; if(isset($_SESSION['idx'])){ $bmiResult .= '<span class="blackText">Add your BMI result to your profile?</span><form action="calculate_bmi.php" method="post" enctype="multipart/form-data"><input name="postBmi" type="submit" id="postBmi" value="Yes Please!" /></form>'; } } } if(isset($_POST['postBmi'])){ $update = $bmiAlt; $bmiUpdate = mysql_query("UPDATE members SET bodyMassIndex='$update' WHERE id='$id' LIMIT 1") or die (mysql_error()); if ($bmiUpdate){ $successMsg = '<span class="errorMsg">BMI has been updated successfully.</span>'; } else { $error_msg = '<span class="errorMsg">Problems arose during the information exchange, please try again later.</span>'; } } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Calculate your BMI</title> <link href="style/layout.css" rel="stylesheet" type="text/css" /> <link href="style/main.css" rel="stylesheet" type="text/css" /> </head> <body> <div id="container"> <?php include_once "bannerFiles/bannerTemplate.php"; ?> <div id="content"> <div id="bmiInfo"> <p><span class="blackText">BMI stands for Body Mass Index. It is a tool used to compare a persons height against their weight to evaluate whether or not the person is under or over weight. A persons BMI is calculated by dividing their body weight by the square of their height.</span></p> <p><span class="blackText">Here is what your body mass index means:</span> <li><span class="blackText">Underweight: &#60 18.5</span></li> <li><span class="blackText">Normal Weight: 18.5-24.9</span></li> <li><span class="blackText">Overweight: 25-29.9</span></li> <li><span class="blackText">Obese: &#62 30</span></li></p> </div> <span class="errorMsg"><?php echo "$errorMsg";?></span> <table width="700px" align="center"> <form action="calculate_bmi.php" method="post" enctype="multipart/form-data"> <tr> <td align="right"><span class="blackText">Height (in inches):</span></td><td><input name="height" type="text" maxlength"5" size="50"/></td></tr> <tr><td align="right"><span class="blackText">Weight (in pounds):</span></td><td><input name="weight" type="text" maxlength"5" size="50"/></td></tr> <tr><td></td><td><input name="bmi" type="submit" id="bmi" value="Calculate" /></td></tr> </form> </table> <?php echo "$bmiResult"; ?><br /> <?php echo "$successMsg"; ?><?php echo "$error_msg"; ?><br /> <p><span class="blackText">Want to improve your BMI?<br /> Visit our <a href="forum/index.php">forums</a> for advice</span></p> </div> <?php include_once "footerFiles/footerTemplate.php";?> </div> </body> </html>
  17. Hi everyone, I have some code where you enter your height and weight and it calculates your BMI (body mass index) then if you are logged in a button appears where you can add that value to your profile. The problem I am having is the value is not being added to the database and I do not get an error message. I think the problem may be the IF statement. Oh yeh btw you've probably guessed im a beginner! Thanks in advance for any feedback [attachment deleted by admin]
×
×
  • 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.