HTML table shifting to the right - php

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.

Related

Updating Data in Mysql through php on a current page

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.'');

The Array is working but do not insert random values to table

I have courses to let user select from, I take SET value(drop down list) and checkbox value and insert them into table. Now when I print_r the array after selection is working fine. When I check the table I find checkbox value is correctly inserted, but the value of the drop down list is always 0 unless I start to select the drop down list(SET VALUE) from the beginning it will work fine??? I know sound complicated,but simply I can not insert array values of the drop down list(SET VALUE) randomly I need to select from the first value to make it work??! Any help please!
<?php include("includes/db_connection.php"); ?>
<!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" />
<style type="text/css">
<!--
body {
background-color: #E6E6FA;
}
-->
</style>
</head>
<body>
<form id="form" name="form" method="post" action="">
<table width="1047" border="1">
<tr>
<th colspan="8" bgcolor="#009966" scope="row"> </th>
</tr>
<tr>
<th width="77" scope="row">set</th>
<th width="77" scope="row"><div align="center"><strong>Select All
</strong></div></th>
<td width="107"><div align="center"><strong>Course Code </strong></div></td>
<td width="130"><div align="center"><strong>Course Name </strong></div></td>
<td width="50"><div align="center"><strong>Credits</strong></div></td>
<td width="162"><div align="center"><strong>Prerequisite Courses</strong></div></td>
<td width="196"><div align="center"><strong>Semester Available</strong></div></td>
<td width="196"><div align="center"><strong>Set Number </strong></div></td>
</tr>
<?php
if(isset($_POST['Submit']) AND $_POST['Submit'] == 'Submit')
{
print_r($_POST);
$coursid =isset($_POST['checkbox']) ? $_POST['checkbox'] : '';
$curid=isset($_GET['id']) ? $_GET['id'] : '';
$setnumber=isset($_POST['select']) ? $_POST['select'] : '';
for($x = 0; $x < count($coursid); $x++)
{
if ($setnumber[$x] == "" || strlen($setnumber[$x]) == 0)
continue;
$sql2=$mysqli->query("INSERT INTO `curriculumcourses`(`course_id`, `curriculum_id`, `set_number`) VALUES ( '".$coursid[$x] ."','". $curid ."','". $setnumber[$x] ."')");
}
}
?>
<?php
$sql1 = "SELECT * FROM courses";
$result = $mysqli->query($sql1);
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
?>
<tr>
<th scope="row"> <label>
<select name="select[]" id="select[]">
<option value="0">NO SET</option>
<option value="1">SET 1</option>
<option value="2">SET 2</option>
<option value="3">SET 3</option>
<option value="4">SET 4</option>
<option value="5">SET 5</option>
</select>
</label></th>
<th height="27" scope="row"><label>
<input name="checkbox[]" type="checkbox" id="checkbox[]" value="<?php echo $row['course_id']; ?>" />
</label></th>
<td><div align="center"><?php echo $row["course_code"];?></div></td>
<td><div align="center"><a href="add_prerequisites.php?id=<?php echo $row['course_id'];?>"/a><?php echo $row["course_name"];?></div></td>
<td><div align="center"><?php echo $row["credits"];?></div></td>
<td><div align="center">
<?php
$cid=$row['course_id'];
$sql3 = "SELECT * FROM prerequisites WHERE cours_id='$cid'";
$result3 = $mysqli->query($sql3);
if ($result3->num_rows > 0) {
while($row3 = $result3->fetch_assoc()) {
$s= $row3['set'];
if ($s==0){
echo $row3['prereq_id'];
}
else if($s==1){
echo $row3['prereq_id'];
}
else if($s==2){
echo $row3['prereq_id']." "."OR"." ";
}else if($s==3){
echo " "."AND"." ".$row3['prereq_id'];
}
}
}
?>
</div></td>
<td><div align="center"><?php $sems= $row["semester_ava"];
if ($sems==0){
echo "Fall ";
}
else if($sems==1){
echo "Spring";
}
else if($sems==2){
echo "BOTH";
}
?></div></td>
<td><div align="center">
</div></td>
</tr>
<?php
}
}
?>
<tr>
<th colspan="8" bgcolor="#009966" scope="row"><label>
<input type="submit" name="Submit" value="Submit" />
</label></th>
</tr>
</table>
<p> </p>
<p> </p>
</form>
</body>
</html>
i figured this out,I just added default selected value
<option selected disabled>Please Select</option>

In this code i still have this message when i update the data

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'];
.
.
.
}

Uploading file is not working in this page

It saves every thing in data but not the name of updated file. It shows undefined index in line 17,18,19,20 it does not show anything in PIC column in database & nothing is stored in subjects_pic folder.
Code is shown here:
<?php
include('conect.php');
$d = '';
$qre = mysql_query("select * from courses1");
while ($res = mysql_fetch_array($qre)) {
$d .='<option value="' . $res['cid'] . '">' . $res['cname'] . '</option>';
}
?>
<?php
include('auth.php');
include('conect.php');
$msg = '';
if (isset($_POST['save'])) {
$course = $_POST['courses1'];
$subjects = $_POST['subjects'];
$name = $_POST['name'];
$file_name = $_FILES['f1']['name'];
$file_type = $_FILES['f1']['type'];
$file_size = $_FILES['f1']['size'];
$file_tmp = $_FILES['f1']['tmp_name'];
$file_path = '../subject_pic/' . $file_name;
move_uploaded_file($file_tmp, $file_path);
mysql_query("INSERT INTO up_file (cid,subid,name,pic)
VALUES ('$course','$subjects','$name','$file_name')");
$msg = '<h3>Record Saved</h3>';
}
?>
<!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>subjects</title>
<link rel="stylesheet" type="text/css" href="headerstyle.css" />
<script type="application/javascript" src="prototype.js"></script>
<script type="text/javascript">
function abc()
{
var a = $('courses1').value;
$("k").innerHTML = '<img src="ajax-loader.gif">';
new Ajax.Request("ajax1.php", {
method: 'post',
postBody: "e=" + a,
onComplete: Update_abc
});
}
function Update_abc(req)
{
var data = req.responseText;
$("k").innerHTML = '';
$("k").innerHTML = data;
//alert(data);
}
</script>
</head>
<body>
07/25/2014
<div class="fixx"><?php include('header.php'); ?></div>
<div class="tabl">
<table width="700" border="0">
<tr>
<td>
<form method="post" action="filupload.php">
<table width="700" border="1" cellpadding="10">
<tr>
<td colspan="2"><h3> ADD Files To Subjects | EDIT </h3></td>
</tr>
<tr>
<td colspan="2"><?php echo $msg; ?></td>
</tr>
<tr>
<td width="174"><h4>Select Course </h4></td>
<td width="674"><label for="courses"></label>
<select name="courses1" id="courses1" onchange="abc()">
<option value="">Select Course</option>
<?php echo $d; ?>
</select> </td>
</tr>
<tr>
<td width="174"><h4>Select Subject </h4></td>
<td width="674"><label for="subjects"></label>
<div id="k">
<select name="subjects" id="subjects"><option value="">Select Subject</option></select>
</div> </td>
</tr>
<tr>
<td><h4>File Name</h4></td>
<td><input type="text" name="name" id="name" /></td>
</tr>
<tr>
<td><h4>Upload Pic</h4></td>
<td><label for="f1"></label>
<input type="file" name="f1" id="f1" /></td>
</tr>
<tr>
<td><input type="submit" name="save" id="save" value="Submit" /></td>
</tr>
</table>
</form>
</td>
</tr>
</table>
</div>
</body>
</html>
use enctype="multipart/form-data" in form tag like:
<form action="filupload.php" method="post" enctype="multipart/form-data">
To upload images or any files 'enctype' should be assigned
<form method="post" action="filupload.php" enctype="multipart/form-data">

Dynamically enable and disable DIV via MySQL

Last night I was trying to figure out how I can how I can dynamically enable and disable span#txtCaptchaDiv on my contact form at the very bottom, above the submit button.
So I added a new field to MySQL, called captcha where I wanted to 1 to show and 0 to hide
So if I add 1 to field captcha the following code will show on my form.php
<label for="code">Write code below > <span id="txtCaptchaDiv" style="color:#F00"></span><!-- this is where the script will place the generated code -->
<input type="hidden" id="txtCaptcha" /></label><!-- this is where the script will place a copy of the code for validation: this is a hidden field -->
<input type="text" name="txtInput" id="txtInput" size="30" />
If I add 0 to field captcha the captcha area will be blank on my form.php.
Can you guy help me out please?
here is my index.php code I currently have:
<?php
require_once("/config/database.php");
$con = mysql_connect($config["db_server"],$config["db_user"],$config["db_pass"]);
?>
<!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>Email FORM</title>
</head>
<body>
<div style="width: 550px; text-align: center;">
<span style="filter:alpha(opacity=60); opacity:.6; padding-left: 10px;"><br />
<?php
$data = mysql_query("SELECT * FROM formrelated")
or die(mysql_error());
while($info = mysql_fetch_array( $data ))
Print " ".$info['welcomemsg'] . "";
?>
</span></div>
<form id="form1" name="form1" method="post" action="submit.php" onsubmit="return checkform(this);">
<table width="454" border="1" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="123">Name</td>
<td width="325">
<input name="name" type="text" />
</td>
</tr>
<tr>
<td height="21">Address</td>
<td><input name="adress" type="text" /></td>
</tr>
<tr>
<td height="21"> </td>
<td><input name="address2" type="text" /></td>
</tr>
<tr>
<td height="21">Email</td>
<td><input name="email" type="text" /></td>
</tr>
<tr>
<td height="21">Tel</td>
<td><input name="email" type="text" /></td>
</tr>
</table>
<!--- captcha code here--->
<center>
<table width="454" height="122" border="0" cellspacing="0" cellpadding="0" background="reCAPbg.png">
<tr>
<td height="73" colspan="2" align="center" valign="middle"><label for="code"><span id="txtCaptchaDiv" style="color:#333; font-size:18px;"></span><!-- this is where the script will place the generated code -->
<input type="hidden" id="txtCaptcha" /></label></td>
<td width="136" rowspan="2"> </td>
</tr>
<tr>
<td width="145"> type the code here:</td>
<td width="173" height="47" align="center"><input type="text" name="txtInput" id="txtInput" size="20" /></td>
</tr>
</table>
</center>
<!--- captcha code ends here--->
<input name="Submit" type="button" value="submit" />
</form>
<script type="text/javascript">
//Generates the captcha function
var a = Math.ceil(Math.random() * 9)+ '';
var b = Math.ceil(Math.random() * 9)+ '';
var c = Math.ceil(Math.random() * 9)+ '';
var d = Math.ceil(Math.random() * 9)+ '';
var e = Math.ceil(Math.random() * 9)+ '';
var code = a + b + c + d + e;
document.getElementById("txtCaptcha").value = code;
document.getElementById("txtCaptchaDiv").innerHTML = code;
</script>
<script type="text/javascript">
function checkform(theform){
var why = "";
if(theform.txtInput.value == ""){
why += "- Security code should not be empty.\n";
}
if(theform.txtInput.value != ""){
if(ValidCaptcha(theform.txtInput.value) == false){
why += "- Security code did not match.\n";
}
}
if(why != ""){
alert(why);
return false;
}
}
// Validate the Entered input aganist the generated security code function
function ValidCaptcha(){
var str1 = removeSpaces(document.getElementById('txtCaptcha').value);
var str2 = removeSpaces(document.getElementById('txtInput').value);
if (str1 == str2){
return true;
}else{
return false;
}
}
// Remove the spaces from the entered and generated code
function removeSpaces(string){
return string.split(' ').join('');
}
</script>
</body>
</html>
This will work for you... enjoy!
<?PHP
$query = mysql_query("SELECT captcha FROM formrelated WHERE id = '1'");
while ($row = mysql_fetch_assoc($query)) {
$captchathis = $row['captcha'];
if ($captchathis == "1") {
echo "YOUR HTML CODE HERE";
}
else {
echo "BLANK";
}
}
?>
Try it like this
<?PHP
if($mysqlResult['captcha'] === 1)
{
echo $myHtml;
}
?>
Where $mysqlResult is an array with the result from the query, $mysqlResult['captcha']is the value of the row captcha from your query and $myHtml is that HTML code you just showed on your answer.
Good luck! ;)
Reffer to
http://php.net/manual/en/
EDIT:
http://www.php.net/manual/en/language.types.array.php ( Array type on the manual )
http://www.php.net/manual/en/control-structures.if.php ( If control structure on the manual )
http://www.php.net/manual/en/ref.mysql.php ( MySQL native functions. deprecated. Preffer MySQLi )
http://www.php.net/manual/en/book.mysqli.php ( MySQLi extension )
http://www.php.net/manual/en/book.pdo.php ( PDO native php class )
Another answer to explain the basic construct of IF logic.
Suppose i have some condition i want to meet to do something; in this case, the following logic
SHOW my form with the basic inputs
IF condition 'captcha = 1' is met, SHOW input2 (captcha)
SHOW rest of the HTML
it would be like this in PHP
<?PHP
echo $myFormWithBasicInputs;
if($captcha === 1)
{
echo $input2;
}
echo $restOfHTML;
?>
In your case, $myFormWithBasicInput and $restOfHTML is already outputed as HTML. All you want to do is inject an PHP code in it to check if some condition is matched. It will be like this
<html>
<!-- MY FORM WITH BASIC INPUTS -->
<?PHP
$captcha = $mySQLresult['captchaRow'];
if($captcha === 1)
{
?>
<!-- CAPTCHA INPUT HERE -->
<?PHP
}
?>
<!-- REST OF HTML -->
</html>
be aware that this is an workaround with example code.
<?PHP
$mysql_query = "SELECT captcha FROM formrelated";
$captcha = $mySQLresult['captchaRow'];
if($captcha === 1)
{
?>
<!--- CODE---->
<table width="454" height="122" border="0" cellspacing="0" cellpadding="0" background="reCAPbg.png">
<tr>
<td height="73" colspan="2" align="center" valign="middle"><label for="code"><span id="txtCaptchaDiv" style="color:#333; font-size:18px;"></span><!-- this is where the script will place the generated code -->
<input type="hidden" id="txtCaptcha" /></label></td>
<td width="136" rowspan="2"> </td>
</tr>
<tr>
<td width="145"> type the code here:</td>
<td width="173" height="47" align="center"><input type="text" name="txtInput" id="txtInput" size="20" /></td>
</tr>
</table>
<?PHP
}
?>
<!-- REST OF HTML -->

Categories