Hey All i have an issue while updating a data in MYSQL from front end php when i click once it update data when i click again without any change it again update and bring previous data. I am beginner to php and do not know what is the problem as code have no error and no warning please help and guide thanks and appreciation for your time in Advance
My code is
<!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=iso-8859-1" />
<title>Update in PHP</title>
</head>
<body>
<?php
$servername="localhost";
$username="root";
$password="";
$conn=mysql_connect($servername,$username,$password);
if(!$conn ) {
die('Could not connect: ' . mysql_error());
}
$sq1 = 'select * from biodata';
mysql_select_db('firstdb');
$display=mysql_query($sq1,$conn);
if(!$display ) {
die('Could not get data: ' . mysql_error());
exit;
}
if (mysql_num_rows($display) == 0) {
echo "No rows found, nothing to print so am exiting";
exit;
}
?>
<table border="2" style= "background-color: #84ed86; color: #761a9b; margin: 0 auto;" >
<thead>
<tr>
<th>ID</th>
<th>Fname</th>
<th>Lname</th>
<th>Email</th>
<th>Phone</th>
<th>Message</th>
<th>Update</th>
</tr>
</thead>
<tbody>
<?php
while( $row = mysql_fetch_assoc( $display ) ){
echo
"<form method= 'post' />
<tr>
<td><input name='UID' value='{$row['ID']}' /></td>
<td><input name='upfname' value='{$row['fname']}' /></td>
<td><input name='uplname' value='{$row['lname']}' /></td>
<td><input name='upemail' value='{$row['email']}' /></td>
<td><input name='upphone' value='{$row['phone']}' /></td>
<td><input name='upmessage' value='{$row['message']}' /></td>
<td><input type='Submit' name='update' value='Update' id='".$row["ID"]."' </td>
</tr>
</form>";
}
?>
</tbody>
</table>
<?php
if(isset($_REQUEST['update']))
{
$id = $_REQUEST['UID'];
$upfn = $_REQUEST['upfname'];
$upln = $_REQUEST['uplname'];
$upem = $_REQUEST['upemail'];
$upph = $_REQUEST['upphone'];
$upms = $_REQUEST['upmessage'];
$up="UPDATE biodata
SET
fname='$upfn',
lname='$upln',
email='$upem',
phone='$upph',
message='$upms'
WHERE ID = $id";
$updbb=mysql_query($up,$conn);
}
?>
</body>
</html>
redirect the same page
header('Location: url'); like header('Location: inbox.php?u='.$log_username.'');
Related
please help me solve this problem. I want to access content of a page only when Session is activated, else redirect user to activate session first. But when I redirect user to session page, it is stuck and cannot go back to content page. I am new here so please help me out from this problem.
<?php
session_start();
if(!isset($_SESSION['username'])){
echo "cookie is not activated" ;
header('Location: http://localhost/CC/Loginsession.php');
die;
}
else {
?>
<!doctype html>
<html>
<head>
<title>Update in PHP</title>
</head>
<body>
<?php
$servername="localhost";
$username="root";
$password="";
$conn=mysql_connect($servername,$username,$password);
if(!$conn ) {
die('Could not connect: ' . mysql_error());
}
$sq1 = 'select * from biodata';
mysql_select_db('firstdb');
$display=mysql_query($sq1,$conn);
if(!$display ) {
die('Could not get data: ' . mysql_error());
exit;
}
if (mysql_num_rows($display) == 0) {
echo "No rows found, nothing to print so am exiting";
exit;
}
?>
<table border="2" style= "background-color: #84ed86; color: #761a9b; margin: 0 auto;" >
<thead>
<tr>
<th>ID</th>
<th>Fname</th>
<th>Lname</th>
<th>Email</th>
<th>Phone</th>
<th>Message</th>
<th>Update</th>
</tr>
</thead>
<tbody>
<?php
while( $row = mysql_fetch_assoc( $display ) ){
echo
"<form method= 'post' />
<tr>
<td ><input name='UID' value='{$row['ID']}' readonly/></td>
<td ><input name='upfname' value='{$row['fname']}' /></td>
<td ><input name='uplname' value='{$row['lname']}' /></td>
<td ><input name='upemail' value='{$row['email']}' /></td>
<td ><input name='upphone' value='{$row['phone']}' /></td>
<td ><input name='upmessage' value='{$row['message']}' /></td>
<td><input type='Submit' name='update' value='Update' id='".$row["ID"]."' </td>
</tr>
</form>";
}
?>
</tbody>
</table>
<?php
if(isset($_REQUEST['update']))
{
$id = $_REQUEST['UID'];
$upfn = $_REQUEST['upfname'];
$upln = $_REQUEST['uplname'];
$upem = $_REQUEST['upemail'];
$upph = $_REQUEST['upphone'];
$upms = $_REQUEST['upmessage'];
$up="UPDATE biodata
SET
fname='$upfn',
lname='$upln',
email='$upem',
phone='$upph',
message='$upms'
WHERE ID = $id";
$updbb=mysql_query($up,$conn);
if($updbb){
header('Location: http://localhost/Prac/updateinsamepage.php');
}
}
}
?>
</body>
</html>>
and My session Login form code is here
<?php
session_start();
if(isset($_SESSION['username'])){
echo "Already registered as $_SESSION[username]" ;
}
else if($_SERVER['REQUEST_METHOD'] == 'POST'){
$uname=htmlentities($_POST['username']);
$pass=htmlentities($_POST['password']);
if(!empty($uname) && !empty($pass)) {
$_SESSION['username']=$uname;
echo "Thanks<br />" . "UserName: $uname " . "Password: $pass";
}
else{
echo "Please fill out the both fields";
}
}
else {
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Loginsession</title>
</head>
<body>
<form method="post">
Username:<input type="text" id="username" name="username" /> <br /><br />
Password:<input type="password" id="password" name="password"/><br /><br />
<input type="hidden" name="hiddenvalue" value="<?php http://localhost/CC/Loginsession.php?username=overwritten ?>"/>
<input type="Submit" value="Login" name="Submit" id="submit" />
</form>
<?php }?>
<?php
session_unset();
session_destroy();
?>
</body>
</html>
You can try this script in place of header
echo '<script>window.location="localhost/CC/Loginsession.php"</script>';
I have this function and when I update the data I still have the same problem .
I don't know where is the error. By the way my connection file is true
This is the message i put it :
Site name Error
This is my code
<!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=windows-1256" />
<link href="style.css" rel="stylesheet" type="text/css" />
<title>Admin control</title>
</head>
<body>
</body>
<div class="head">Settings</div>
<?
/*
CREATE TABLE `article`.`setting` (
`name_site` VARCHAR( 300 ) NOT NULL ,
`url_site` VARCHAR( 300 ) NOT NULL ,
`email_site` VARCHAR( 150 ) NOT NULL ,
`desc_site` TEXT NOT NULL ,
`kay_site` TEXT NOT NULL ,
`oepn_site` MEDIUMINT( 2 ) NOT NULL ,
`text_close_site` TEXT NOT NULL
) ENGINE = InnoDB;
*/
include "../include/config.php";
if (isset($_POST['submit'])){
$ns = $_POST['name_site'];
$us = $_POST['url_site'];
$es = $_POST['email_site'];
$ds = $_POST['desc_site'];
$ks = $_POST['kay_site'];
$os = $_POST['oepn_site'];
$ms = $_POST['text_close_site'];
}
if (#$_POST['updatesetting']){
if(#$ns == ''){
echo "<div class='no'> Site name Error </div>";
echo '<meta http-equiv="refresh" content="2; url=setting.php"/>';
exit;
}
else {
$update = mysql_query("update setting set
name_site='$ns',
url_site = '$us',
email_site = '$es',
desc_site = '$ds',
kay_site = '$ks',
oepn_site = '$os',
text_close_site ='$ms'
") ;
if (#isset($update)){
echo "<div class='ok'> Update Done</div>";
echo '<meta http-equiv="refresh" content="2; url=setting.php"/>';
exit;
}
}
}
$sel1 = mysql_query("select * from setting ");
$row1 = mysql_fetch_assoc($sel1);
$name_site = $row1['name_site'];
$url_site = $row1['url_site'];
$email_site = $row1['email_site'];
$desc_site = $row1['desc_site'];
$kay_site = $row1['kay_site'];
$oepn_site = $row1['oepn_site'];
$text_close_site = $row1['text_close_site']
?>
<div class="bodypanel">
<form action="setting.php" method="post">
<table width="100%" border="0" dir="rtl">
<tr>
<td>Site Name</td>
<td><input type="text" name="name_site" value="<?=$name_site;?>" ></td>
</tr>
<tr>
<td>Site link</td>
<td><input type="text" name="url_site" value="<?=$url_site;?>"></td>
</tr>
<tr>
<td>Email siten</td>
<td><input type="text" name="email_site" value="<?=$email_site;?>"></td>
</tr>
<tr>
<td>Site description</td>
<td><textarea name="desc_site" rows="4" cols="25" > <?=$desc_site;?> </textarea></td>
</tr>
<tr>
<td>Key words</td>
<td><textarea name="kay_site" rows="4" cols="25" value="<?=$kay_site;?>"> <?=$kay_site;?> </textarea></td>
</tr>
<tr>
<td>Open site</td>
<td>
<select name="oepn_site" >
<?
if ($oepn_site== 1){
echo "<option value='1'>Open to visitor</option>
<option value='2'>Close to visitor</option>";
}
else {
echo "<option value='2'>Close to visitor</option>
<option value='1'>Open to visitor</option>";
}
?>
</select>
</td>
</tr>
<tr>
<td>Close message</td>
<td><textarea name="text_close_site" rows="4" cols="25"> <?=$text_close_site;?> </textarea></td>
</tr>
<tr>
<td colspan="2" class="head"><input type="submit" name="updatesetting" value="save setting"> </td>
</tr>
</table>
</form>
</div>
</body>
</html>
change the checking of submission to
if (isset($_POST['updatesetting']))
{
$ns = $_POST['name_site'];
.
.
.
}
I'm trying to setup a form that can update my product.
the code reads data ok, but $update is getting errors that prevents the update from doing anything.
The errors are :
Undefined variable: update
mysqli::query(): Empty query (after submit the form)
Please Help! Thanks.
//include database configuration file
include("config.php");
$mysqli->set_charset("utf8");
?>
<!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>Edit Page</title>
</head>
<body>
<?php
if(isset($_POST['Submit'])){//if the submit button is clicked
$updateproductname = $_POST['updateproductname'];
$updatesku = $_POST['productsku'];
$updateproductoriginal = $_POST['updateoriginalname'];
$updatedescshort = $_POST['updatedescshort'];
$update = $mysqli->query("UPDATE testproducts".
"SET product_sku=$updatesku, product_name=$updateproductname, 'product_originalname'='$updateproductoriginal', 'product_description_short='$updatedescshort' ".
"WHERE product_id = '$id' ");
$mysqli->query($update) or die("Cannot update");//update or error
}
?>
<?php
//Create a query
$sql = "SELECT * FROM testproducts WHERE product_id = $id";
//submit the query and capture the result
$result = $mysqli->query($sql) or die(mysql_error());
?>
<h2>Update Record <?php echo $id;?></h2>
<form action="" method="post">
<?php
while ($row = $result->fetch_assoc()) {?>
<table border="0" cellspacing="10">
<tr>
<td>Product Name:</td> <td><input type="text" name="updateproductname" value="<?php echo $row['product_name']; ?>"></td>
</tr>
<tr>
<td>Product Original Name:</td> <td><input type="text" name="updateoriginalname" value="<?php echo $row['product_originalname']; ?>"></td>
</tr>
<tr>
<td>Product SKU:</td> <td><input type="text" name="productsku" value="<?php echo $row['product_sku']; ?>"></td>
</tr>
<tr>
<td>ShortDescription:</td> <td><input type="text" name="updatedescshort" size="100" value="<?php echo $row['product_description_short']; ?>"></td>
</tr>
<tr>
<td><INPUT TYPE="Submit" VALUE="Update the Record" NAME="Submit"></td>
</tr>
</table>
<?php
}
?>
</form>
<?php
if($update){//if the update worked
echo "<b>Update successful!</b>";
}
?>
</body>
</html>
a) You are vulnerable to SQL injection attacks
b) Read the docs for mysqli_query(). The function takes a query STRING, and returns a RESULT HANDLE. You're then taking that result handle and trying to re-query it. If you'd bothered having proper error handling on ALL of your mysqli calls, you'd have seen this.
was able to update the record after moving the update and select code to top of html
<?php
if(isset($_POST['Submit'])){//if the submit button is clicked
// Check connection
$productname = $_POST['updateproductname'];
$productoriginal = $_POST['updateoriginalname'];
$sku = $_POST['productsku'];
$descshort = $_POST['updatedescshort'];
$mysqli->query("UPDATE testproducts ".
"SET product_name='$productname',product_originalname='$productoriginal', product_sku='$sku', product_description_short='$descshort'".
" WHERE product_id='$id'");
}
?>
<?php
//Create a query
$sql = "SELECT * FROM testproducts WHERE product_id = $id";
//submit the query and capture the result
$result = $mysqli->query($sql) or die(mysql_error());
//$query=getenv(QUERY_STRING);
//parse_str($query);
//$ud_title = $_POST['Title'];
//$ud_pub = $_POST['Publisher'];
//$ud_pubdate = $_POST['PublishDate'];
//$ud_img = $_POST['Image'];
$mysqli->close();
?>
i'm creating asset database system (just an offline system, not connected to internet) that will show all assets list. on the list, i can click on any asset to view the details. also i'm manage to update the details or delete the asset. but when it goes to asset record parts, it give an error on inserting record to asset using a form.
here is my record add form. and i'm also wanna make machine id visible under MACHINE ID field in the form, but i did't know yet how to put the data there.
for inserting record, its will capture machine id on rekod_add.php ( record add) url address from asset table to passing into rekod_tab table.
here is my record add page ( rekod_add.php )
<?php
//Start session
session_start();
//Check whether the session variable SESS_MEMBER_ID is present or not
if(!isset($_SESSION['username']) || (trim($_SESSION['password']) == '')) {
header("location: login.php");
exit();
}
?>
<html>
<head>
<title>EXA_mySQL</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style type="text/css">
body,td,th {
font-family: Tahoma, Geneva, sans-serif;
}
</style>
</head>
<body>
<script type="text/javascript">function checkinput() {
var id_mesin = document.getElementById('id_mesin').value;
if(!id_mesin.match(/\S/)) {
alert ('Please enter Machine ID');
return false;
} else {
return true;
}
}
</script>
<?php
$con=mysqli_connect("localhost","root","admin","exa");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$id_mesin = $_POST['id_mesin'];
$query = "SELECT * FROM asset WHERE id_mesin ='".$id_mesin."'";
$result = mysqli_query($con,$query);
$rows = mysqli_fetch_array($result);
?>
<table width="733" border="0" align="center" cellpadding="0" cellspacing="1">
<tr>
<td><form name="form_insert" method="post" action="rekod_add_ac.php">
<table width="709" border="0" align="center">
<tr>
<th width="23" scope="col">MACHINE ID</th>
<th colspan="2" scope="col">DATE</th>
<th width="68" scope="col">TIME</th>
<th width="175" scope="col">RECEIVE CALL BY</th>
<th width="97" scope="col">CURRENT METER</th>
<th width="90" scope="col">LAST METER</th>
<th width="136" scope="col">J.SHEET NO</th>
</tr>
<tr>
<td> </td>
<td colspan="2"><input name="tarikh_rekod" type="text" id="tarikh_rekod" size="15" /></td>
<td><input name="time" type="text" id="time" size="10" maxlength="9" /></td>
<td><input type="text" name="call_by" id="call_by" /></td>
<td><input name="meter_semasa" type="text" id="meter_semasa" size="15" /></td>
<td><input name="meter_last" type="text" id="meter_last" size="15" /></td>
<td><input name="rujukan" type="text" id="rujukan" size="10" /></td>
</tr>
<tr>
<td> </td>
<th width="81">PROBLEM</th>
<th width="5">:</th>
<td colspan="3"><textarea name="masalah" id="masalah" cols="55" rows="5"></textarea></td>
<th colspan="2" rowspan="2"><p>REMARK</p>
<p>
<textarea name="remark" cols="30" rows="6" id="remark"></textarea>
</p></th>
</tr>
<tr>
<td> </td>
<th>SOLUTION</th>
<th>:</th>
<td colspan="3"><textarea name="solution" id="solution" cols="55" rows="5"></textarea></td>
</tr>
<tr>
<td colspan="8" align="right"><?php echo "<input type='hidden' value='" . $rows['id_mesin'] . "' name='id_mesin'>"; echo "<input type='submit' value='Add Record'>";?></td>
</tr>
</table>
</form>
</td>
</tr>
</table>
<?php
mysqli_close($con);
?>
</body>
</html>
here is my rekod_add_ac.php
<?php
session_start();
if(!isset($_SESSION['username']) || (trim($_SESSION['password']) == '')) {
header("location: login.php");
exit();
}
?>
<html>
<head>
<title>EXA_mySQL</title>
<script type="text/javascript">
<!--
function CloseWindow() {
window.close();
window.opener.location.reload();
}
//-->
</script>
</head>
<body>
<?php
error_reporting(E_ALL);
ini_set('display_errors','on');
$con=mysqli_connect("localhost","root","admin","exa");
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
print_r($_POST);
$id_mesin=$_POST['id_mesin'];
$tarikh_rekod=$_POST['tarikh_rekod'];
$time=$_POST['time'];
$call_by=$_POST['call_by'];
$meter_semasa=$_POST['meter_semasa'];
$meter_last=$_POST['meter_last'];
$rujukan=$_POST['rujukan'];
$masalah=$_POST['masalah'];
$solution=$_POST['solution'];
$remark=$_POST['remark'];
$rekod_in="INSERT INTO rekod_tab ( id_mesin, tarikh_rekod, time, call_by, meter_semasa, meter_last, rujukan, masalah, solution, remark) VALUES ( $'id_mesin', $'tarikh_rekod', $'time', $'call_by', $'meter_semasa', $'meter_last', $'rujukan', $'masalah', $'solution', $'remark')";
$result=mysqli_query($con, $rekod_in);
if($result){
echo "Successful";
echo "<BR>";
echo "<th><form>";
echo "<input type='button' onClick='CloseWindow()' value='Back to Exa_mySQL' align='middle'>";
echo "</form></th>";
}
else {
echo "Data error, please recheck before submit.";
echo "<BR>";
echo "Click back to add record.";
echo "<BR>";
echo "<form action='rekod_add.php?id=$id_mesin' method='post'>";
echo "<td><input type='hidden' value='$id_mesin' name='id_mesin'>";
echo "<input type='submit' value='Back'></td>";
echo "</form>";
echo "<th><form>";
}
mysqli_close($con);
?>
</body>
</html>
after user done inserting record details, the form will add the record on rekod_tab table including machine id ( id_mesin ) which automatically capture from url like i said before.
but the result is error. when inserting detail manual in sql, its work. can anyone help me?
here my error result.
sorry for my bad english.
Try INSERT query like this
$rekod_in="INSERT INTO rekod_tab
( id_mesin, tarikh_rekod, time, call_by, meter_semasa, meter_last,
rujukan, masalah, solution, remark)
VALUES ( '$id_mesin', '$tarikh_rekod', '$time', '$call_by', '$meter_semasa',
'$meter_last', '$rujukan', '$masalah', '$solution', '$remark')";
I'm new to HTML and am wondering what the best practice is to structure a calculator that I'm coding. For example, When pressing the "calculate" button, all of the input forms shift to the right. How can I keep everything still?
http://rgoo.co/calculators/bmr-calculator.php
<?php
$answer = "";
$agev = "";
$feetv = "";
$inchesv = "";
$weightv = "";
if (isset($_POST['agev']) && isset($_POST['feetv']) && isset($_POST['inchesv']) && isset($_POST['weightv'])) {
$agev = $_POST['agev'];
$feetv = $_POST['feetv'];
$inchesv = $_POST['inchesv'];
$weightv = $_POST['weightv'];
$totalheightv = $inchesv + ($feetv*12);
$answer = 66 + (6.23*$weightv) + (12.7*$totalheightv) - (6.8*$agev);
}
echo <<<_END
<form method='post' action=''>
<table border='0' width='500px' cellpadding='2' cellspacing='1' class="table">
<tr class="calcheading"><td colspan="4" align="left"><strong>IIFYM test</strong></td></tr>
<tr class="calcrow"><td>Age:</td><td align="justify"><input type='text' name='agev' value="$agev"/>Years</td></tr>
<tr class="calcrow2"><td>Height:</td><td align="justify"><input type='text' name='feetv' value="$feetv"/>Ft<input type='text' name='inchesv' value="$inchesv"/>In</td></tr>
<tr class="calcrow"><td>Weight:</td><td align="left"><input type='text' name='weightv' value="$weightv"/>lbs</td></tr>
<tr class="submit"><td colspan="2"><input type='submit' value='Calculate'/></td></tr>
_END;
?>
<tr class="calcrow">
<td>Your BMR is: <?php echo $answer?></td>
</tr>
</table>
</form>
<!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>BMR Calculator</title>
</head>
<body>
BMR = Basal Metabolic Rate (similar to RMR = Resting Metabolic Rate. Your BMR is represents the number of calories your body burns at rest. Regular routine of cardiovascular exercise can increase your BMR, improving your health and fitness when your body's ability to burn energy gradually slows down.
</body>
</html>
Try adding colspan="2" to <td>Your BMR is: <?php echo $answer?></td>
Also, format your HTML correctly!
<?php
$answer = "";
$agev = "";
$feetv = "";
$inchesv = "";
$weightv = "";
if(isset($_POST['agev']) && isset($_POST['feetv']) && isset($_POST['inchesv']) && isset($_POST['weightv'])) {
$agev = $_POST['agev'];
$feetv = $_POST['feetv'];
$inchesv = $_POST['inchesv'];
$weightv = $_POST['weightv'];
$totalheightv = $inchesv + ($feetv*12);
$answer = 66 + (6.23*$weightv) + (12.7*$totalheightv) - (6.8*$agev);
}
?>
<!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>BMR Calculator</title>
</head>
<body>
<form method='post' action=''>
<table border='0' width='500px' cellpadding='2' cellspacing='1' class="table">
<tr class="calcheading">
<td colspan="2" align="left"><strong>IIFYM test</strong></td>
</tr>
<tr class="calcrow">
<td>Age:</td>
<td align="justify"><input type='text' name='agev' value="<?php echo $agev; ?>"/>Years</td>
</tr>
<tr class="calcrow2">
<td>Height:</td>
<td align="justify"><input type='text' name='feetv' value="<?php echo $feetv; ?>"/>Ft<input type='text' name='inchesv' value="<?php echo $inchesv; ?>"/>In</td>
</tr>
<tr class="calcrow">
<td>Weight:</td>
<td align="left"><input type='text' name='weightv' value="<?php echo $weightv; ?>"/>lbs</td>
</tr>
<tr class="submit">
<td colspan="2"><input type='submit' value='Calculate'/></td>
</tr>
<tr class="calcrow">
<td colspan="2">Your BMR is: <?php echo $answer?></td>
</tr>
</table>
</form>
BMR = Basal Metabolic Rate (similar to RMR = Resting Metabolic Rate. Your BMR is represents the number of calories your body burns at rest. Regular routine of cardiovascular exercise can increase your BMR, improving your health and fitness when your body's ability to burn energy gradually slows down.
</body>
</html>
The forms moves to the right because the td that you display the BMI in has gotten wider. Just set the colspan to 4 like you did in calcheading.