I have this form:
<form method="post" action="mypage.php" orderform="" name="" id="orderform">
<a id="add">+</a>
<table width="533" cellspacing="0" cellpadding="2" border="0" id="ordertable">
<tbody>
<tr>
<td width="33%">Product Code (e.g 66203)</td>
<td width="33%">mtrs sq Required (e.g 10)</td>
<td width="33%">Preview Image</td>
</tr>
<tr class="item">
<td class="prodcode "><input type="text" id="prodcode[]" name="prodcode[]" class=" "></td>
<td class="meterage"><input type="text" id="meterage[]" name="meterage[]"></td>
<td class="imgsample"></td>
</tr>
<tr class="item">
<td class="prodcode "><input type="text" id="prodcode[]" name="prodcode[]" class=" "></td>
<td class="meterage"><input type="text" id="meterage[]" name="meterage[]"></td>
<td class="imgsample"></td>
</tr>
</tbody>
</table>
<button>Submit</button>
</form>
I am trying to receive the post and print the associate product value with its meterage...as below ( this only seems to return the last result) any ideas?
$number_of_products=count($_POST['prodcode']);
for ( $i=0; $i<$number_of_products; $i++){
$orderdetails = $_POST['prodcode'][$i]." has the meterage: ".$_POST['meterage'][$i]."<br/>";
}
You're overwriting the content of $orderdetails each time the for loop is run.
Try something like this:
$number_of_products=count($_POST['prodcode']);
$orderdetails = "<h1>Order Details</h1>";
for ( $i=0; $i<$number_of_products; $i++){
$orderdetails .= $_POST['prodcode'][$i]." has the meterage: ".$_POST['meterage'][$i]."<br/>";
}
Try indexing the prodcode[] and meterage[] names on your input fields, i.e.:
<form method="post" action="mypage.php" orderform="" name="" id="orderform">
<a id="add">+</a>
<table width="533" cellspacing="0" cellpadding="2" border="0" id="ordertable">
<tbody>
<tr>
<td width="33%">Product Code (e.g 66203)</td>
<td width="33%">mtrs sq Required (e.g 10)</td>
<td width="33%">Preview Image</td>
</tr>
<tr class="item">
<td class="prodcode "><input type="text" id="prodcode_0" name="prodcode[0]" class=" "></td>
<td class="meterage"><input type="text" id="meterage_0" name="meterage[0]"></td>
<td class="imgsample"></td>
</tr>
<tr class="item">
<td class="prodcode "><input type="text" id="prodcode_1" name="prodcode[1]" class=" "></td>
<td class="meterage"><input type="text" id="meterage_1" name="meterage[1]"></td>
<td class="imgsample"></td>
</tr>
</tbody>
</table>
<button>Submit</button>
</form>
it because you overwrite it everytime
change
$orderdetails =
to
$orderdetails .=
Related
I am trying to create a html table showing results from php sql query. it is a result page of students php code is as under
$r1=$_GET["r"];
$con=mysqli_connect(localhost,chumspai_tlss,Tls121,chumspai_tlsResult);
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con,"SELECT * FROM nursery_blue_ WHERE sr_='$r1'");
while($row = mysqli_fetch_array($result))
{
html code is
<pre>
<form name="frmResult" id="frmResult" action="" method="post" onsubmit="return checkEmpty();">
<table width="80%" cellpadding="5" cellspacing="5" border="0">
<tr>
<td class="heading noborder">Enter Your Roll Number:</td>
<td class="noborder"><input type="text" id="r" name="r" value="" /></td>
</tr>
<tr>
<!--
<td class="heading noborder">Enter Your Name:</td>
<td class="noborder"><input type="text" id="name" name="name" value="" /></td>
</tr>
<tr>
<td class="heading noborder">Search by</td>
<td class="noborder"><input type="radio" id="option" name="option" value="rno" checked="checked" />
Roll No
<input type="radio" id="option" name="option" value="name" />
Name </td>
</tr>
-->
<tr>
<td class="noborder"> </td>
<td class="noborder"><input type="submit" name="submit" value="Search" />
<input type="reset" name="reset" value="Clear" />
</td>
</tr>
<!--<tr>
<td colspan="2"> <embed src="images/wait.swf"></embed></td>
</tr> -->
</table>
</form>
<div style="border:1px solid #000000;">
<table width="100%" cellpadding="10" cellspacing="0" border="0">
<tr>
<td class="heading grey" width="30%">RNO</td>
<td><?php
Print $row['sr_'];
?>
</td>
</tr>
<tr>
<td class="heading grey">NAME</td>
<td class="shade"></td>
</tr>
<tr>
<td class="heading grey">FATHER</td>
<td></td>
</tr>
<tr>
<td class="heading grey">regno</td>
<td></td>
</tr>
</table>
<table width="100%" cellpadding="10" cellspacing="0" border="0">
<tr class="grey">
<td rowspan="2" class="heading">Sr.no </td>
<td rowspan="2" class="heading">Name of subject </td>
<td rowspan="2" class="heading">Maximum Marks</td>
<td colspan="7" class="heading">detail of marks Obtained</td>
<tr class="grey">
<td class="heading">PART ONE</td>
<td class="heading">Total</td>
</tr>
<tr>
<td>1</td>
<td>Urdu</td>
<td></td>
<td> </td>
<td></td>
</tr>
<tr class="shade">
<td>2</td>
<td>English</td>
<td></td>
<td> </td>
<td></td>
</tr>
<tr>
<td>3</td>
<td>Islamyat</td>
<td></td>
<td> </td>
<td></td>
</tr>
<tr class="shade">
<td>4</td>
<td>pakstudies</td>
<td></td>
<td> </td>
<td></td>
</tr>
<tr class="shade">
<td>6</td>
<td></td>
<td></td>
<td></td>
<td>0</td>
</tr>
<tr>
<td>7</td>
<td></td>
<td></td>
<td></td>
<td>0</td>
</tr>
<tr class="shade">
<td>8</td>
<td></td>
<td></td>
<td></td>
<td>0</td>
</tr>
<tr class="shade">
<td>9</td>
<td></td>
<td></td>
<td></td>
<td>0</td>
</tr>
<tr class="grey">
<td colspan="2" class="heading">TOTAL</td>
<td class="heading">1100</td>
<td colspan="4" class="heading"></td>
</tr>
<tr class="grey">
<td colspan="3" class="heading">NOTIFICATION</td>
<td class="heading"></td>
<td class="heading"></td>
<td colspan="2" class="heading"></td>
</tr>
<tr>
<td colspan="7">(i) This provisional result intimation is issued as a notice only. Errors and omissions are excepted.</td>
</tr>
</table>
</pre>
please help me how to embed this php query with this html table and html form also.
you are not so far.
The variable $row is an array containing your data. Try this to see it's structure in your while call:
print_r($row);
Using this command you will see the name of each item of your array. Note it somewhere. Then you can do something like this:
...<td><?php echo $row['desired_column_name']; ?></td>...
If you receive data from your mysql query, this should do the trick.
Hope it helps,
Paul
Try This :
$result = mysql_query("select * from emp");
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td id=SrNo$cnt >".$row['eno']."</td>";
echo "<td id=ItemId$cnt >".$row['eId']."</td>";
echo "<td>". "<button name='Update' id='update' onclick='show(".$cnt.")'>UPDATE</button>"."</td>";
echo "<td>". "<button name='Report' id='show' onclick='Report(".$row['SrNo'].")'>REPORT</button>"."</td>";
echo "</tr>";
echo "<div id=show$cnt>";
echo "</div>";
$cnt++;
}
I am using a query to populate a list of messages by using a loop, here's my code:
<?php
$sql_i_msg_sent_waiting="SELECT t1.i_message_id,t2.username,t2.name,t2.propic,t2.age,t2.dob,t3.religion,t3.caste
FROM candidate_i_message as t1, candidate_register_table as t2, candidate_social_table as t3 WHERE t1.from_username='$_SESSION[logged_user]' AND t1.to_username=t2.username AND t2.username=t3.username AND t1.status='0'";
$result_i_msg_sent_waiting=mysql_query($sql_i_msg_sent_waiting,$con);
$count=mysql_num_rows($result_i_msg_sent_waiting);
echo $count;
?>
<div id="section_i_message_sent_waiting" style="width:650px; overflow:auto;">
<h2>Awaiting Sent Request</h2>
<?php
if(mysql_num_rows($result_i_msg_sent_waiting)==0)
{
?>
<div style="width:650px; border-bottom:1px solid #CCCCCC" align="center">
<table border='0' cellspacing='0' cellpadding='0' width='550px' align='center'>
<tr style='padding-botton:5px; border-bottom:1px solid #CCCCCC'>
<td width='50px'/>
<td><FONT COLOR=red FACE='Geneva, Arial' SIZE=2>
No Messages Found.</FONT></td>
<td width='50px'/></tr></table>
</div>
<?php
}
else
{
while($row_i_msg_sent_waiting=mysql_fetch_array($result_i_msg_sent_waiting))
{
?>
<div style="width:650px; border-bottom:1px solid #CCCCCC" align="center">
<table width="550px" cellpadding="0" cellspacing="0" border="2" align="center" style="vertical-align:middle">
<tr style='vertical-align:middle'>
<td style='vertical-align:middle' width="100px">
<form method='post' action='id.php' name='showid' id='showid'>
<input type='hidden' name='pro_username' id='pro_username'
value="<?php echo $row_i_msg_sent_waiting['username'];?>"/>
<input type='image' src='<?php echo $row_i_msg_sent_waiting['propic'];?> ' style="width:100px; vertical-align:middle"/>
</form>
</td>
<td style='vertical-align:middle;border-right:1px solid #CCCCCC;border-top:1px solid #CCCCCC' width="450px" >
<table width="450px" cellpadding="0" cellspacing="0" border="0">
<tr>
<td width="10px"/>
<td width="100px" align="left">Name</td>
<td width="10px">:</td>
<td width="100px" align="left"><?php echo $row_i_msg_sent_waiting['name'];?>
</td>
<td width="10px">
<td width="100px" align="left">Age</td>
<td width="10px">:</td>
<td width="100px" align="left"><?php echo $row_i_msg_sent_waiting['age'];?>
</td>
<td width="10px"/>
</tr>
<tr>
<td width="10px"/>
<td width="100px" align="left">Date Of Birth</td>
<td width="10px">:</td>
<td width="100px" align="left"><?php echo $row_i_msg_sent_waiting['dob'];?>
</td>
<td width="10px">
<td width="100px" align="left">Religion</td>
<td width="10px">:</td>
<td width="100px" align="left"><?php echo $row_i_msg_sent_waiting['religion'];?>
</td>
<td width="10px"/>
</tr>
<tr>
<td width="10px"/>
<td width="100px" align="left">Caste</td>
<td width="10px">:</td>
<td width="100px" align="left"><?php echo $row_i_msg_sent_waiting['caste'];?>
</td>
<td width="10px">
<td width="100px" align="left">Religion</td>
<td width="10px">:</td>
<td width="100px" align="left"><?php echo $row_i_msg_sent_waiting['religion'];?>
</td>
<td width="10px"/>
</tr>
<tr>
<td width="10px"/>
<td width="100px" align="left">Action</td>
<td width="10px">:</td>
<td width="100px" align="left">
<form method="post" name="cancel_request_form" id="cancel_request_form"
action="javascript:cancel_request(document.getElementById('cancel_request_form'));">
<input type="text" name="no_of_msg" id="no_of_msg" value="<?php echo $count;?>"/>
<input type="text" name="cancel_request[]" id="cancel_request[]"
value="<?php echo $row_i_msg_sent_waiting['i_message_id'];?>"/>
<input type="submit" name="cancel" id="cancel" class="button" style="width: 100px" value="Cancel Request"/>
</form>
</td>
<td width="10px">
<td width="100px" align="left"></td>
<td width="10px">:</td>
<td width="100px" align="left">
</td>
<td width="10px"/>
</tr>
</table>
</td>
</tr>
</table>
</div>
<?php
}
}?>
</div>
the line
<input type="text" name="cancel_request[]" id="cancel_request[]"
value="<?php echo $row_i_msg_sent_waiting['i_message_id'];?>"/>
creates a array of input type text, and each input text contains corressponding message_id...since each input text is contained within a form, and since the form is within a loop, the form is also repeatative..when the submit button will be clicked corressponding to a particular form, the input type text[] within that form will fire the value to get accepted in the javascript i give below...
<script>
function cancel_request(obj) {
alert(document.getElementByName('cancel_request[]').value);
}
</script>
But the script is showing problem, it's not working at all. I don't know what's wrong. It's not displaying anything. There is message_id 1 and 2: one text type input[] contains value 1, another value 2.
When I click the submit button corresponding to value 1, the value of that text type input will be send to JavaScript and displayed. What's the problem with my script?
The function is getElementsByName - Elements in the plural. You then access it like an array.
Ive been working with meeplace and i've come into a problem regarding a syntax error in the code.
its in the advertising management pages:
echo "<option value='0'>AM</option>";
echo "<option value='12' ".$select.">PM</option>";
echo " </select></td>\r\n </tr>\r\n \r\n <tr>\r\n <td align=\"right\">Total Views Allowed:</td>\r\n <td><input type=\"text\" id=\"ad_total_views\" style=\"width:50px;\" value=\"\" disabled=\"disabled\" /> <label><input type=\"checkbox\" checked=\"checked\" onclick=\"if(this.checked==true){$('#ad_total_views').val('');$('#ad_total_views').attr('disabled','disabled');}else{$('#ad_total_views').val('');$('#ad_total_views').removeAttr('disabled');$('#ad_total_views').focus()}\" />Unlimited</label></td>\r\n </tr>\r\n \r\n <tr>\r\n <td align=\"right\">Total Clicks Allowed:</td>\r\n <td><input type=\"text\" id=\"ad_total_clicks\" style=\"width:50px;\" value=\"\" disabled=\"disabled\" /> <label><input type=\"checkbox\" checked=\"checked\" onclick=\"if(this.checked==true){$('#ad_total_clicks').val('');$('#ad_total_clicks').attr('disabled','disabled');}else{$('#ad_total_clicks').val('');$('#ad_total_clicks').removeAttr('disabled');$('#ad_total_clicks').focus()}\" />Unlimited</label></td>\r\n </tr>\r\n </table></td>\r\n </tr>\r\n <tr bgcolor=\"#FFFFFF\">\r\n <td class=\"td_th\" align=\"center\">Smarty Code (Developer)</td>\r\n <td>{\$ads->getAdCode(<span id=\"smartycode\">1</span>)}</td>\r\n </tr>\r\n <tr bgcolor=\"#FFFFFF\">\r\n <td class=\"td_th\" align=\"center\"> </td>\r\n <td><input type=\"button\" value=\"Create New Campaign\" onclick=\"new_ad()\" /></td>\r\n </tr>\r\n </TBODY></TABLE>\r\n<br />\r\n\r\n<TABLE cellSpacing=1 cellPadding=4 width=\"100%\" border=0>\r\n <TBODY>\r\n <TR class=\"td_title\">\r\n <TD colSpan=7>Ad Campaigns</TD></TR>\r\n <TR bgColor=#ffffff>\r\n \r\n <TD width=\"10%\" align=\"center\" class=\"td_th\"> </TD>\r\n <TD width=\"4%\" align=\"center\" class=\"td_th\">ID</TD>\r\n <TD width=\"29%\" align=\"center\" class=\"td_th\">Campaign Name</TD>\r\n <TD width=\"12%\" align=\"center\" class=\"td_th\">Start Date</TD>\r\n <TD width=\"11%\" align=\"center\" class=\"td_th\">End Date</TD>\r\n <TD width=\"17%\" align=\"center\" class=\"td_th\">Viewed / Views Allowed</TD>\r\n <TD width=\"17%\" align=\"center\" class=\"td_th\">Clicked / Clicks Allowed</TD>\r\n </TR>\r\n ";
i'm not too sure whats going wrong, the error is on the third line of code above.
Parse error: syntax error, unexpected '(', expecting T_VARIABLE or '$' in /mgt/body/ad_list.php on line 185
If anyone else has had this problem or knows a simple answer to cure this it would be brilliant. I've tried a few things like making it more than one line but no luck! :s
Update
Ive managed to narrow the problem down to this bit:
<label><input type=\"checkbox\" checked=\"checked\" onclick=\"if(this.checked==true){$('#ad_total_views').val('');$('#ad_total_views').attr('disabled','disabled');}else{$('#ad_total_views').val('');$('#ad_total_views').removeAttr('disabled');$('#ad_total_views').focus()}\" />Unlimited</label></td>\r\n
This is one crazy echo have seen in a long while .. I would advice you to use Heredoc
Example
$str = <<<EOD
Example of string
spanning multiple lines
using heredoc syntax.
EOD;
echo $str ;
Back to your Script
<?php
$select ="test";
echo "<option value='0'>AM</option>";
echo "<option value='12' " . $select . ">PM</option>";
echo <<<DATA
</select>
</td>
</tr>
<tr>
<td align="right">Total Views Allowed:</td>
<td><input type="text" id="ad_total_views" style=""
"width:50px;" value="" disabled="disabled" /> <label><input
type="checkbox" checked="checked" onclick="if(this.checked==true){\$ ('#ad_total_views') . val ( '' );$
('#ad_total_views') . attr ( 'disabled', 'disabled' );
}else{\$('#ad_total_views').val('');$('#ad_total_views').removeAttr('disabled');\$('#ad_total_views').focus()}" />Unlimited</label></td>
</tr>
<tr>
<td align="right">Total Clicks Allowed:</td>
<td><input type="text" id="ad_total_clicks" style=""
"width:50px;" value="" disabled="disabled" /> <label><input
type="checkbox" checked="checked" onclick="if(this.checked==true){\$( '#ad_total_clicks').val('');$('#ad_total_clicks').attr('disabled','disabled');
}else{\$('#ad_total_clicks').val('');\$('#ad_total_clicks').removeAttr('disabled');\$('#ad_total_clicks').focus()}" />Unlimited</label></td>
</tr>
</table>
</td>
</tr>
<tr bgcolor="#FFFFFF">
<td class="td_th" align="center">Smarty Code (Developer)</td>
<td>{\$ads->getAdCode(<span id="smartycode">1</span>)}
</td>
</tr>
<tr bgcolor="#FFFFFF">
<td class="td_th" align="center"> </td>
<td><input type="button" value="Create New Campaign" onclick="new_ad()" /></td>
</tr>
</TBODY>
</TABLE>
<br />
<TABLE cellSpacing=1 cellPadding=4 width="100%" border=0>
<TBODY>
<TR class="td_title">
<TD colSpan=7>Ad Campaigns</TD>
</TR>
<TR bgColor=#ffffff>
<TD width="10%" align="center" class="td_th"> </TD>
<TD width="4%" align="center" class="td_th">ID</TD>
<TD width="29%" align="center" class="td_th">Campaign Name</TD>
<TD width="12%" align="center" class="td_th">Start Date</TD>
<TD width="11%" align="center" class="td_th">End Date</TD>
<TD width="17%" align="center" class="td_th">Viewed / Views
Allowed</TD>
<TD width="17%" align="center" class="td_th">Clicked / Clicks
Allowed</TD>
</TR>
DATA;
?>
Demo : http://codepad.viper-7.com/3Scnp4
Try this instead:
echo ' </select></td>'."\r\n".' </tr>'."\r\n".' '."\r\n".' <tr>'."\r\n".' <td align="right">Total Views Allowed:</td>'."\r\n".' <td><input type="text" id="ad_total_views" style="width:50px;" value="" disabled="disabled" /> <label><input type="checkbox" checked="checked" onclick="if(this.checked==true){$(\'#ad_total_views\').val(\'\');$(\'#ad_total_views\').attr(\'disabled\',\'disabled\');}else{$(\'#ad_total_views\').val(\'\');$(\'#ad_total_views\').removeAttr(\'disabled\');$(\'#ad_total_views\').focus()}" />Unlimited</label></td>'."\r\n".' </tr>'."\r\n".' '."\r\n".' <tr>'."\r\n".' <td align="right">Total Clicks Allowed:</td>'."\r\n".' <td><input type="text" id="ad_total_clicks" style="width:50px;" value="" disabled="disabled" /> <label><input type="checkbox" checked="checked" onclick="if(this.checked==true){$(\'#ad_total_clicks\').val(\'\');$(\'#ad_total_clicks\').attr(\'disabled\',\'disabled\');}else{$(\'#ad_total_clicks\').val(\'\');$(\'#ad_total_clicks\').removeAttr(\'disabled\');$(\'#ad_total_clicks\').focus()}" />Unlimited</label></td>'."\r\n".' </tr>'."\r\n".' </table></td>'."\r\n".' </tr>'."\r\n".' <tr bgcolor="#FFFFFF">'."\r\n".' <td class="td_th" align="center">Smarty Code (Developer)</td>'."\r\n".' <td>{\$ads->getAdCode(<span id="smartycode">1</span>)}</td>'."\r\n".' </tr>'."\r\n".' <tr bgcolor="#FFFFFF">'."\r\n".' <td class="td_th" align="center"> </td>'."\r\n".' <td><input type="button" value="Create New Campaign" onclick="new_ad()" /></td>'."\r\n".' </tr>'."\r\n".' </TBODY></TABLE>'."\r\n".'<br />'."\r\n".''."\r\n".'<TABLE cellSpacing=1 cellPadding=4 width="100%" border=0>'."\r\n".' <TBODY>'."\r\n".' <TR class="td_title">'."\r\n".' <TD colSpan=7>Ad Campaigns</TD></TR>'."\r\n".' <TR bgColor=#ffffff>'."\r\n".' '."\r\n".' <TD width="10%" align="center" class="td_th"> </TD>'."\r\n".' <TD width="4%" align="center" class="td_th">ID</TD>'."\r\n".' <TD width="29%" align="center" class="td_th">Campaign Name</TD>'."\r\n".' <TD width="12%" align="center" class="td_th">Start Date</TD>'."\r\n".' <TD width="11%" align="center" class="td_th">End Date</TD>'."\r\n".' <TD width="17%" align="center" class="td_th">Viewed / Views Allowed</TD>'."\r\n".' <TD width="17%" align="center" class="td_th">Clicked / Clicks Allowed</TD>'."\r\n".' </TR>'."\r\n".' ';
PHP possibly gets confused because of the $ inside the string as it's a double quoted string and $ are parsed as variable starts inside that string.
i have a form that extract data from mysql table into a form, each row has a menu to choose a value from and i want to update mysql with each value choosen for each row when the 'Apply To All' button is clicked but doesnt work at all.,here is my code.
<td><form id="main" name="main" method="post" action="setProjectStatus.php" onsubmit="return validateMain();">
<table width="100%" cellspacing="1" cellpadding="1">
<tr>
<td width="35%" rowspan="3"><img src="../img/project.jpg" alt="Comp Sci Stud" width="325" height="199" border="2" /></td>
<td width="65%" height="42" colspan="2"><table width="94%" cellpadding="1" cellspacing="1" class="main_table">
<tr class="table_title">
<td width="100%" class="table_title">Set Project Status. </td>
</tr>
<tr>
<td height="26"> </td>
</tr>
<tr>
<td height="26"><table width="100%" cellspacing="1" cellpadding="1">
<tr class="table_head">
<td width="2%" height="35"><div align="center"></div></td>
<td width="26%" height="35"><div align="center">Student Name</div></td>
<td colspan="2"><div align="center">Project</div></td>
<td width="19%"><div align="center">Status</div></td>
</tr>
<?php
session_start();
$username = $_SESSION['username'];
require_once("mysqlConnect.php");
//
$sql="SELECT * FROM spms_Student";
$result=mysql_query($sql);
$count=mysql_num_rows($result);
echo "There are $count projects to be undertaken.";
while($rows=mysql_fetch_array($result)){
//
$query = "SELECT name FROM spms_systemUser WHERE userId = '".$rows[0]."'";
$result1 = mysql_query($query) or die(mysql_error());
$row = mysql_fetch_array($result1);
$name = $row[0];
?>
<tr>
<td height="25" align="center"> </td>
<td align="center"><?php echo $name; ?></td>
<td colspan="2" align="center"><?php echo $rows[1]; ?></td>
<td align="center"><label>
<select name="select" class="form_field_100px_select">
<option value="Pending" selected="selected">Pending</option>
<option value="Approved">Approved</option>
<option value="Disapproved">Disapproved</option>
</select>
</label></td>
</tr>
<?php
}
?>
<tr class="pager_bg">
<td height="35"> </td>
<td> </td>
<td width="37%" align="right"><input name="done" type="button" id="done" value="Done" onclick="window.location='../coordinatorMenu.html'" /></td>
<td width="16%"><label>
<input name="approveAll" type="submit" id="approveAll" value="Approve All" />
</label></td>
<td><input name="apply" type="submit" id="apply" value="Apply To All" /></td>
</tr>
<?php
mysql_close();
?>
</table></td>
</tr>
</table></td>
</tr>
<tr>
<td colspan="2"> </td>
</tr>
<tr>
<td colspan="2"><label></label> <label></label></td>
</tr>
</table>
</form></td>
You're trying to reuse your MySQL connection while still holding on to the resultset from the first query. You need to create a second connection for the inner loop queries. Even better would probably be to rewrite your query using a join, but I can't say for sure without knowing your schema.
I am trying to prevent Spam with one of my forms using the Hidden Field trick, but for some reason its not working. When I fill in the field that's supposed to be left empty, the form is submitted like a normal.
Is there something wrong with my php? (I think that's where my problem lies):
This is the code to validate the hidden field (see top of my form):
if(!empty($_POST['email'])){ die('Stop Spamming'); }
Here's the complete php form:
<?
session_start();
include("verification_image.class.php");
$image = new verification_image();
if (($image->validate_code($_POST['validate']) ? "true" : "false") == "false") {
header('Location: http://www.domain.com/fail.htm');
exit;
}
if(!empty($_POST['email'])){ die('Stop Spamming'); }
$to = "email#domain.co.za";
$bcc = "email#domain.co.za";
$from = $_POST['contactemail'];
$subject = "INTERESTED ADVERTISER";
$sbody = '<table width="420" height="135" border="0" align="center"
cellpadding="0" cellspacing="0">
<!--DWLayoutTable-->
<tr>
<td height="90" colspan="5"><div align="center">Reservation &
Enquiries Submission Form </div></td>
</tr>
<tr>
<td height="25" colspan="3" align="center" valign="middle"><span
class="style7">Full Name</span></td>
<td width="180" valign="top">'.$_POST['contactname'].'</td>
<td width="42"> </td>
</tr>
<tr>
<td height="25" colspan="3" align="center" valign="middle"><span
class="style7">Contact number</span></td>
<td valign="top">'.$_POST['contactnumber'].'</td>
<td> </td>
</tr>
<tr>
<td height="25" colspan="3" align="center" valign="middle"><span
class="style7">Email</span></td>
<td valign="top">'.$_POST['contactemail'].'</td>
<td> </td>
</tr>
<tr>
<td height="35" colspan="3" align="center" valign="bottom"><span
class="style7">Query</span></td>
<td colspan="2" rowspan="2"
valign="middle">'.$_POST['contactquery'].'</td>
</tr>
<tr>
<td width="84" height="108" align="center" valign="middle">
<!--DWLayoutEmptyCell--> </td>
<td width="69" align="center" valign="middle"><!--DWLayoutEmptyCell-->&
nbsp;</td>
<td width="17"> </td>
</tr>
<tr>
<td height="17"></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
</table>';
$sBodyNew = '<style type="text/css">
<!--
.style {
font-family: Arial;
font-size: 12px;
color: #4D241E;
}
body {
background-image: url();
background-color: #F1EAE4;
}
.style1 {font-size: 14px}
-->
</style>
<p> </p>
<table width="420" border="0" align="center" cellpadding="0" cellspacing="5">
<tr>
<td><table width="100%" border="0" cellpadding="8" cellspacing="0" bgcolor="#E7D3AF"
class="style">
<tr>
<td colspan="2" valign="top"><div align="center"><strong><span
class="style1">Website Deal</span><br>
.................................................................</strong><br>
</div></td>
</tr>
<tr>
<td width="32%" valign="top"><div align="left"><strong>Date Submitted</strong>
</div></td>
<td width="68%" valign="top">'. date("F j, Y, g:i a") .'</td>
</tr>
<tr>
<td valign="top"><div align="left"><strong>Name</strong></div></td>
<td valign="top">'.$_POST['contactname'].'</td>
</tr>
<tr>
<td valign="top"><div align="left"><strong>Contact Number</strong></div></td>
<td valign="top">'.$_POST['contactnumber'].'</td>
</tr>
<tr>
<td valign="top"><div align="left"><strong>Email</strong></div></td>
<td valign="top">'.$_POST['contactemail'].'</td>
</tr>
<tr>
<td valign="top"><div align="left"><strong>Query</strong></div></td>
<td valign="top">'.$_POST['contactquery'].'</td>
</tr>
</table></td>
</tr>
</table>
';
$headers = "From: $from\r\n";
$headers .= "Content-type: text/html\r\n";
$success = mail($to, $subject, $sBodyNew, $headers);
header('Location: http://www.domain.com/success.htm');
?>
Heres this is what I added to my HTML form:
<label>
<input type="text" class="email" name="email" id="email" />
</label>
And heres the HTML form:
<form action="process_advertise.php" method="post" name="order"
onSubmit="MM_validateForm('contactname','','R','contactnumber','','R','contactemail',
'','RisEmail','validate','','R','contactquery','','R');return document.MM_returnValue">
<input name="success" type="hidden"
value=http://www.domain.com/success.htm>
<table width="465" border="0" cellspacing="0" cellpadding="0">
<!--DWLayoutTable-->
<tr>
<td width="465" height="387" valign="top"><span class="style66">NAME:
<input name="contactname" type="text" id="contactname" />
</span><br />
<span class="style66">CONTACT NUMBER:</span>
<input name="contactnumber" type="text" id="contactnumber" />
<br />
<span class="style66">EMAIL:
<input name="contactemail" type="text" id="contactemail" />
</span><br />
<span class="style66">QUERY:</span>
<textarea name="contactquery" cols="40" rows="8"
id="contactquery"></textarea>
<br />
<br />
<input type="text" class="email" name="email" id="email" />
<br />
<br />
<img src="picture.php" /><br />
<span class="style57 style16"><em>Please enter character<br />
as listed above</em></span><br />
<input name="validate" type="text" id="validate" />
<br />
<input type="reset" name="button2" id="button2" value="Reset" />
<input type="submit" name="button" id="button" value="Submit" /></td>
</tr>
</table>
</form>
Anyone know what I'm doing wrong?
=======================================================================
Problem Solved:
Ok guys... I've tested the form again and its working now!
I'm not why it didn't work earlier, but for those who like to know... all my coding there is correct except I removed this code from my process php form:
$sbody = '<table width="420" height="135" border="0" align="center"
cellpadding="0" cellspacing="0">
<!--DWLayoutTable-->
<tr>
<td height="90" colspan="5"><div align="center">Reservation &
Enquiries Submission Form </div></td>
</tr>
<tr>
<td height="25" colspan="3" align="center" valign="middle"><span
class="style7">Full Name</span></td>
<td width="180" valign="top">'.$_POST['contactname'].'</td>
<td width="42"> </td>
</tr>
<tr>
<td height="25" colspan="3" align="center" valign="middle"><span
class="style7">Contact number</span></td>
<td valign="top">'.$_POST['contactnumber'].'</td>
<td> </td>
</tr>
<tr>
<td height="25" colspan="3" align="center" valign="middle"><span
class="style7">Email</span></td>
<td valign="top">'.$_POST['contactemail'].'</td>
<td> </td>
</tr>
<tr>
<td height="35" colspan="3" align="center" valign="bottom"><span
class="style7">Query</span></td>
<td colspan="2" rowspan="2"
valign="middle">'.$_POST['contactquery'].'</td>
</tr>
<tr>
<td width="84" height="108" align="center" valign="middle">
<!--DWLayoutEmptyCell--> </td>
<td width="69" align="center" valign="middle"><!--DWLayoutEmptyCell-->&
nbsp;</td>
<td width="17"> </td>
</tr>
<tr>
<td height="17"></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
</table>';
This code is not necessary as greg0rie pointed out
There are too many ways your code can be code injected.
You should use filter_var function for a minimal prevent for it.
For validating email use (at least and not just):
if(!filter_var($_POST['email'], FILTER_VALIDATE_EMAIL))
{
echo("E-mail is not valid");
}else{
echo("E-mail is valid");
}
This line of your code seems to be strange:
if (($image->validate_code($_POST['validate']) ? "true" : "false") == "false") {
wouldn't it easier this way?
if (!($image->validate_code($_POST['validate'])){