php shopping cart not displaying items in cart? - javascript

I'm trying to implement a php shopping cart on my site. I currently have the products page correctly reading from my database. When the cart is empty, the "There are no items in your cart," text displays, however when the cart has something in it, it displays the headers to this table, but no product information.
<form name="cartform" method="post" action="">
<input type="hidden" name="productid" />
<input type="hidden" name="command" />
<span id="cont_shop">
<input type="button" value="Continue Shopping" onclick="window.location.href='../Project/products.php'" />
</span>
<div id="formerror"><?php echo $message ?></div>
<table id="cart_table">
<?php
if(count($_SESSION['cart']))
{
echo '<tr>
<th>Name</th>
<th>Price</th>
<th>Quantity</th>
<th>Amount</th>
<th>Options</th>
</tr>';
$max = count($_SESSION['cart']);
for($i = 0; $i < $max; $i++)
{
$product_id = $_SESSION['cart'][$i]['productid'];
$quantity = $_SESSION['cart'][$i]['quantity'];
$product_name = get_product_name($dbc,$product_id);
$product_price = get_price($dbc,$product_id);
if($quantity == 0)
{
continue;
}
echo '<tr>
<td>' . $product_name . '</td>
<td>$ ' . $product_price . '</td>
<td><input type="text" name="product' . $product_id . '" value="' . $quantity . '" maxlength="4" size="2" /></td>
<td>$ ' . $product_price*$quantity . '</td>
<td>Remove Item</td>
</tr>';
}
echo '<tr>
<td colspan="2"><strong>Order Total: $' . get_order_total($dbc) . '</strong></td>
<td></td>
<td colspan="3" id="cart_buttons">
<input type="submit" value="Clear Cart" onclick="clear_cart()">
<input type="submit" value="Update Cart" onclick="update_cart()">
<input type="submit" value="Complete Order" onclick="complete_order()">
</td>
</tr>';
}
else
{
echo '<tr><td>There are no items in your shopping cart.</td></tr>';
}
?>
</table>
</form>
When I view the page source, all I see is the HTML render to here:
<table id="cart_table">
<tr>
<th>Name</th>
<th>Price</th>
<th>Quantity</th>
<th>Amount</th>
<th>Options</th>
</tr>

<?php
if(count($_SESSION['cart']))
{
?>
<form name="cartform" method="post" action="">
<input type="hidden" name="productid" />
<input type="hidden" name="command" />
<span id="cont_shop">
<input type="button" value="Continue Shopping" onclick="window.location.href='../Project/products.php'" />
</span>
<div id="formerror"><?php echo $message ?></div>
<table id="cart_table">
<?php
echo '<tr>
<th>Name</th>
<th>Price</th>
<th>Quantity</th>
<th>Amount</th>
<th>Options</th>
</tr>';
$max = count($_SESSION['cart']);
for($i = 0; $i < $max; $i++)
{
$product_id = $_SESSION['cart'][$i]['productid'];
$quantity = $_SESSION['cart'][$i]['quantity'];
$product_name = get_product_name($dbc,$product_id);
$product_price = get_price($dbc,$product_id);
if($quantity == 0)
{
continue;
}
echo '<tr>
<td>' . $product_name . '</td>
<td>$ ' . $product_price . '</td>
<td><input type="text" name="product' . $product_id . '" value="' . $quantity . '" maxlength="4" size="2" /></td>
<td>$ ' . $product_price*$quantity . '</td>
<td>Remove Item</td>
</tr>';
}
echo '<tr>
<td colspan="2"><strong>Order Total: $' . get_order_total($dbc) . '</strong></td>
<td></td>
<td colspan="3" id="cart_buttons">
<input type="submit" value="Clear Cart" onclick="clear_cart()">
<input type="submit" value="Update Cart" onclick="update_cart()">
<input type="submit" value="Complete Order" onclick="complete_order()">
</td>
</tr>';
?>
</table>
</form>
<?php
}
else
{
echo '<tr><td>There are no items in your shopping cart.</td></tr>';
}
?>

Related

incorrect run php by button click

I have php function which update all records in data table and need it run by click button in html.
My php function look like this:
<?php
try {
$sql = 'SELECT id_data, date_record, value1, value2, value3 FROM data ';
$s = $pdo->prepare($sql);
$s->execute();
} catch (PDOException $e) {
$error = 'Error with select data' . $e->getMessage();
include 'error.html.php';
exit();
}
while ($row = $s->fetch()) {
$dane[] = array(
'id_data' => $row['id_data'],
'date_record' => $row['date_record'],
'value1' => $row['value1'],
'value2' => $row['value2'],
'value3' => $row['value3']
);
}
if (isset($_GET['edytion'])) {
foreach ($data as $data2) {
try {
$sql = 'UPDATE data SET date_record = :date_record, value1 = :value1, value2 = :value2, value3 = :value3 WHERE id_data= :id_data';
$s = $pdo->prepare($sql);
$s->bindValue(':date_record', $_POST['date_record']);
$s->bindValue(':value1', $_POST['value1']);
$s->bindValue(':value2', $_POST['value2']);
$s->bindValue(':value3', $_POST['value3']);
$s->bindValue(':id_data', $_POST['id_data']);
$s->execute();
} catch (PDOException $e) {
$error = 'Edit data error ' . $e->getMessage();
include 'error.html.php';
exit();
}
}
Header("Location: theme3.php");
}
?>
And my form in html where i try run this look:
<div class="table-responsive">
<table class="table table-bordered">
<thead>
<tr>
<th>Date</th>
<th>Value 1</th>
<th>Value 2</th>
<th>Value 3</th>
</tr>
</thead>
<?php if (isset($data)): ?>
<?php foreach ($data as $data1): $a = 0 ?>
<form action="?edytion" method="post" id='ed'>
<tr class="bg-primary">
<input type="hidden" name="id_data" id="id_data" value="<?php echo $data1['id_data']; ?>">
<td><input type="date" name="date_record" id="date_record" value="<?php echo $data1['date_record']; ?>"> </td>
<td><input type="text" name="value1" id="value1" value="<?php echo $data1['value1']; ?>"> </td>
<td><input type="text" name="value2" id="value2" value="<?php echo $data1['value2']; ?>"> </td>
<td><input type="text" name="value3" id="value3" value="<?php echo $data1['value3']; ?>"> </td>
<!-- <input type="hidden" ondblclick="default" id="id_buttona" value="Edit"/> -->
</tr>
</form>
<?php $a++;
endforeach; ?>
<?php endif; ?>
</tbody>
</table>
<input type="submit" id="id_buttona" onclick="document.getElementById('ed').submit();" value="Edit"/>
</div>
Ultimately when i try update data it update only first record in table, rest of them is invariable.
Anybody know what is wrong and have idea how correct it? I will be grateful for help!
You create too many forms with the same id. Surround the table with the <form> and do foreach on <tr> only.
Something like this
<div class="table-responsive">
<form action="?edytion" method="post" id='ed'>
<table class="table table-bordered">
<thead>
<tr>
<th>Date</th>
<th>Value 1</th>
<th>Value 2</th>
<th>Value 3</th>
</tr>
</thead>
<?php if (isset($data)): ?>
<?php $a = 0; foreach ($data as $data1): ?>
<tr class="bg-primary">
<input type="hidden" name="id_data<?php echo $a; ?>" id="id_data" value="<?php echo $data1['id_data']; ?>" />
<td><input type="date" name="date_record<?php echo $a; ?>" value="<?php echo $data1['date_record']; ?>"> </td>
<td><input type="text" name="value1<?php echo $a; ?>" value="<?php echo $data1['value1']; ?>"> </td>
<td><input type="text" name="value2<?php echo $a; ?>" value="<?php echo $data1['value2']; ?>"> </td>
<td><input type="text" name="value3<?php echo $a; ?>" value="<?php echo $data1['value3']; ?>"> </td>
</tr>
<?php $a++;
endforeach; ?>
<?php endif; ?>
</tbody>
</table>
<input name="row_count" value="<?php echo isset($a) ? $a : 0; ?>" type="hidden"/>
</form>
<input type="submit" id="id_buttona" onclick="document.getElementById('ed').submit();" value="Edit"/>
</div>
The way you created each form for each row will not work well because: (1) all your forms have the same javascript id, when you do getElementById only the first form is affected, (2) when you submit that one form the page reloads and all the changes to other rows are lost.
One solution is to make only 1 form and have different name to all fields. Forms fields are sent by name and value so you need different names for all fields and you don't really need ids.
You can add row count somewhere in the form and then change php to something like this:
$row_count = $_POST['row_count'];
for($i = 0; i < $row_count; i++) {
try {
$sql = 'UPDATE data SET
date_record = :date_record,
value1 = :value1,
value2 = :value2,
value3 = :value3
WHERE id_data= :id_data';
$s = $pdo->prepare($sql);
$s->bindValue(':date_record', $_POST['date_record' . $i]);
$s->bindValue(':value1', $_POST['value1' . $i]);
$s->bindValue(':value2', $_POST['value2' . $i]);
$s->bindValue(':value3', $_POST['value3' . $i]);
$s->bindValue(':id_data', $_POST['id_data' . $i]);
$s->execute();
}
catch (PDOException $e) {
$error = 'Edit data error ' . $e->getMessage();
include 'error.html.php';
exit();
}
}
It is all html file
<!DOCTYPE HTML PUBLIC>
<html>
<head>
<title>Tematyka2</title>
<link rel="stylesheet" href="style.css" type="text/css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css"/>
</head>
<body>
<div id="container">
<div id="heading"></div>
<table border="0" width="766" cellpadding="0" cellspacing="0" align="center">
<tr>
<td class="t1"><p>Example title</p></td><td class="t2"> <b class="linkW" style="padding-left: 60%">Logout</b></td>
</tr>
<tr>
<td class="top1"><div class="inscription">Your Page</div></td>
<td class="top2" valign="top"></td>
</tr>
</table>
<table align="center" cellpadding="0">
<tr>
<td valign="top">
<table cellpadding="0" cellspacing="0">
<tr><td class="topm">Main menu</td></tr>
<tr><td class="tlom">
:: Main page <br>
</td></tr>
<tr><td class="dolm"></td></tr
</table>
<table cellpadding="0" cellspacing="0">
<tr><td class="topm">Them</td></tr>
<tr><td class="tlom">
:: Them 1 <br>
:: <b>Them 2</b> <br>
:: Them 3 <br>
</td></tr>
<tr><td class="dolm"></td></tr
</table>
<table cellpadding="0" cellspacing="0">
<tr><td class="topm">Charts</td></tr>
<tr><td class="tlom">
:: Chart1 <br>
:: Chart2 <br>
</td></tr>
<tr><td class="dolm"></td></tr>
</table>
<br>
</td>
<td width="1"></td>
<td valign="top">
<table cellpadding="0" cellspacing="0">
<tr><td class="topn"></td></tr>
<tr><td class="tlon">
<div class="span7 center">
<h2>
EDYTION
</h2>
</div>
<div class="table-responsive">
<table class="table table-bordered">
<thead>
<tr>
<th>Date</th>
<th>Value 1</th>
<th>Value 2</th>
<th>Value 3</th>
</tr>
</thead>
<?php if(isset($data)): ?>
<?php foreach($data as $data1): $a=0?>
<form action="?edytion" method="post" id='ed'>
<tr class="bg-primary">
<input type="hidden" name="id_data" id="id_data" value="<?php echo $data1['id_data']; ?>">
<td><input type="date" name="date_record" id="date_record" value="<?php echo $data1['date_record']; ?>"> </td>
<td><input type="text" name="value1" id="value1" value="<?php echo $data1['value1']; ?>"> </td>
<td><input type="text" name="value2" id="value2" value="<?php echo $data1['value2']; ?>"> </td>
<td><input type="text" name="value3" id="value3" value="<?php echo $data1['value3']; ?>"> </td>
<!-- <input type="hidden" ondblclick="default" id="id_buttona" value="Edit"/> -->
</tr>
</form>
<?php $a++; endforeach; ?>
<?php endif; ?>
</tbody>
</table>
<input type="submit" id="id_buttona" onclick="document.getElementById('ed').submit();" value="Edit"/>
</div>
</td></tr>
<!-- <tr><td class="doln"></td></tr> -->
</table>
</td>
</tr>
</table>
<table align="center" cellpadding="0" cellspacing="0">
<tr>
<td class="foot1"> My page</td>
<td class="foot2"><img src="images/dol2.jpg" alt="anything"></td>
</tr>
</table>
And Php part:
<?php
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
include $_SERVER['DOCUMENT_ROOT'] . '/connection_to_database.php';
include $_SERVER['DOCUMENT_ROOT']. '/check_login.php'; try {
$sql = 'SELECT id_data, date_record, value1, value2, value3 FROM data ';
$s = $pdo->prepare($sql);
$s->execute();
} catch (PDOException $e) {
$error = 'Error with select data' . $e->getMessage();
include 'error.html.php';
exit();
}
while ($row = $s->fetch()) {
$dane[] = array(
'id_data' => $row['id_data'],
'date_record' => $row['date_record'],
'value1' => $row['value1'],
'value2' => $row['value2'],
'value3' => $row['value3']
);
}
if (isset($_GET['edytion'])) {
foreach ($data as $data2) {
try {
$sql = 'UPDATE data SET
date_record = :date_record,
value1 = :value1,
value2 = :value2,
value3 = :value3
WHERE id_data= :id_data';
$s = $pdo->prepare($sql);
$s->bindValue(':date_record', $_POST['date_record']);
$s->bindValue(':value1', $_POST['value1']);
$s->bindValue(':value2', $_POST['value2']);
$s->bindValue(':value3', $_POST['value3']);
$s->bindValue(':id_data', $_POST['id_data']);
$s->execute();
}
catch (PDOException $e) {
$error = 'Edit data error ' . $e->getMessage();
include 'error.html.php';
exit();
}
}
Header("Location: theme3.php");
}
?>
And that's all about update data. Php and html are in one file, I know it's look unprofessionally and i shoudln't do it in this way.

Enable/disable multiple textboxes

Code:
<?php
include('conect.php');
$result = mysqli_query($conn,"SELECT * FROM `op` WHERE `type` = 2 ;");
echo "<table class='table table-striped table-hover'id='datatables-example'>
<tr>
<td class='pure-table'><b>Title 1</b></td>
<td class='pure-table'><b>Title 2</b></td>
<td class='pure-table'><b>Check 1</b></td>
<td class='pure-table'><b>Title 3</b></td>
<td class='pure-table'><b>VCheck 2</b></td>
</tr>";
while($row = mysqli_fetch_array($result))
{
echo "<tbody data-link='row' class='rowlink'>
<tr>
<td>' . $row['Op'] . '</td>
<td> <input type='text' name='T2' class='form-control'>
<td style='text-align:center;'> <input type='checkbox' name='C1' id='C1' >
<td> <input type='text' name='T3' id='T3' class='form-control' disabled >
<td style='text-align:center;'> <input type='checkbox' name='C2'>
</tr>
</tbody>
}
</table>";
mysqli_close($conn);
?>
<script language ="JavaScript">
document.getElementById('C1').onchange = function() {
document.getElementById('T3').disabled = !this.checked;
};
</script>
I want to enable/disable multiple textboxes generated by the row number of input data.
The first row works fine but the other lines not.
What am I doing wrong?
None of your <td> tags are closed in the second row.

Auto add row in html

I have table like this:
<form name="frm_data_nasabah2" method="post" enctype="application/x-www-form-urlencoded" action="<?php echo $page_action;?>">
<table class="table table-bordered table-hover" id="tab_logic_usaha1" border="1" width="80%">
<thead>
<tr style="background: rgb(227,241,252)">
<th class="text-center" align="center">
No
</th>
<th class="text-center" align="center">
Nama Pemegang Saham
</th>
<th class="text-center" align="center">
%tase Saham
</th>
<th class="text-center" align="center" >
Icon
</th>
</tr>
</thead>
<tbody>
<?php
$loop = 1;
foreach($PEMEGANGSAHAM as $saham){ ?>
<tr id='addr<?php echo $loop; ?>_usaha1' >
<td>
<?php echo $loop;
?>
</td>
<td>
<input type="text" name='Nama_Pemegang_Saham[]' class="form-control" value="<?php echo $saham->NAMA_PEMEGANG_SAHAM; ?>" required/>
</td>
<td>
<input type="text" name='tase_Saham[]' value="<?php echo $saham->PER_SAHAM; ?>" class="form-control" required/>
</td>
<td>
<center>
<img src="http://brftst.bni.co.id/tap.dev/public/images/imagesManageDebitur/delete.png"
onclick="confirm_Delete_Usaha1(<?php echo $saham->ID_USAHA; ?>)" height="20" width="20" />
</center>
</td>
</tr>
<?php $inputSaham++;
$loop++;
$row1++;
?>
<?php } ?>
</tbody>
</table>
<br/>
<input name="submitTab" value="Submit" type="submit">
<input type="hidden" name="id_num" value="<?php echo $debiturId;?>" />
<input type="hidden" name="submit_segment" value="usaha_saham" />
<input type="hidden" name="rowNum" value="<?php echo $row1; ?>" />
</form>
and i have javascript like this:
var i=<?php echo $loop; ?>;
$("#add_row_usaha1").click(function(){
$('#addr'+(i)+'_usaha1').html("<td>"+ (i-1) +"</td><td><input name='Nama_Pemegang_Saham"+i+"' type='text' class='form-control input-md' required/> </td>"+
"<td><input name='tase_Saham"+i+"' type='text' class='form-control input-md' required/></td>"+"<td>"
//+"<center><img src='http://brftst.bni.co.id/tap.dev/public/images/imagesManageDebitur/edit.png' height='20' width='20'/> "
//+"<img src='http://brftst.bni.co.id/tap.dev/public/images/imagesManageDebitur/delete.png' height='20' width='20'/></center>"
+"<center><img src='http://brftst.bni.co.id/tap.dev/public/images/imagesManageDebitur/deleteRow.png' height='20' width='20' onclick='deleteRow("+i+")'/></center>"
+"</td><?php $row1++; ?>");
$('#tab_logic_usaha1').append('<tr id="addr'+(i+1)+'_usaha1"></tr>');
i++;
});
And another function:
function deleteRow(input){
if(input>1){
$("#addr"+input+"_usaha1").html('');
input--;
}
}
when i try to delete row 5, and add some rows again, the result like this:
The number of row is not like the index. How can i fix this?
function deleteRow(input){
alert('masuk');
if(input>1){
todelete=document.getElementById("addr"+input+"_usaha1");
todelete.parentNode.removeChild(todelete);
i--;
}
}
Another Fix:
Fix Append the Element and then add its innerHTML
var i=<?php echo $loop; ?>;
$("#add_row_usaha1").click(function(){
$('#tab_logic_usaha1').append('<tr id="addr'+(i+1)+'_usaha1"></tr>');
$('#addr'+(i)+'_usaha1').html("<td>"+ (i-1) +"</td><td><input name='Nama_Pemegang_Saham"+i+"' type='text' class='form-control input-md' required/> </td>"+
"<td><input name='tase_Saham"+i+"' type='text' class='form-control input-md' required/></td>"+"<td>"
//+"<center><img src='http://brftst.bni.co.id/tap.dev/public/images/imagesManageDebitur/edit.png' height='20' width='20'/> "
//+"<img src='http://brftst.bni.co.id/tap.dev/public/images/imagesManageDebitur/delete.png' height='20' width='20'/></center>"
+"<center><img src='http://brftst.bni.co.id/tap.dev/public/images/imagesManageDebitur/deleteRow.png' height='20' width='20' onclick='deleteRow("+i+")'/></center>"
+"</td><?php $row1++; ?>");
i++;
});

Cannot get radio button value on while loop

I am doing a simple quiz program using PHP and JavaScript(for its timer)
Here is my code
<!DOCTYPE html>
<html>
<head>
</head>
<body bgcolor="#CCFFCC">
<?php
session_start ();
$_SESSION['username'];
?>
<div id="wrap">
<?php
$host="localhost"; // Host name
$username="root"; // Mysql username
$password=""; // Mysql password
$db_name="table"; // Database name
$tbl_name="q_quiz"; // Table name
// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
// get value of id that sent from address bar
$id=$_GET['q_id'];
$sql="SELECT * FROM $tbl_name WHERE q_id='$id'";
$result=mysql_query($sql);
$rows=mysql_fetch_array($result);
?>
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<td><table width="100%" frame="box" cellpadding="3" cellspacing="1" bgcolor="#CCFFCC">
<tr>
<td bgcolor="#CCFFCC"><h3>Quiz Info : </h3></td>
</tr>
<tr>
<td bgcolor="#CCFFCC"><strong>Quiz Name : </strong><?php echo $rows['q_name']; ?></td>
</tr>
</table>
</td>
</tr>
</table>
<div style="font-weight: bold" id="quiz-time-left"></div>
<script type="text/javascript">
var max_time = <?php echo $rows['q_time'] ?>;
var c_seconds = 0;
var total_seconds =60*max_time;
max_time = parseInt(total_seconds/60);
c_seconds = parseInt(total_seconds%60);
document.getElementById("quiz-time-left").innerHTML='Time Left: ' + max_time + ' minutes ' + c_seconds + ' seconds';
function init(){
document.getElementById("quiz-time-left").innerHTML='Time Left: ' + max_time + ' minutes ' + c_seconds + ' seconds';
setTimeout("CheckTime()",999);
}
function CheckTime(){
document.getElementById("quiz-time-left").innerHTML='Time Left: ' + max_time + ' minutes ' + c_seconds + ' seconds' ;
if(total_seconds <=0){
setTimeout('document.quiz.submit()',1);
} else
{
total_seconds = total_seconds -1;
max_time = parseInt(total_seconds/60);
c_seconds = parseInt(total_seconds%60);
setTimeout("CheckTime()",999);
}
}
init();
</script>
</font>
Problem starts here
<br>
<?php
//so i will set a default score of 0.
$score = 0;
$tbl_name2="a_quiz";
$sql2="SELECT * FROM $tbl_name2 WHERE q_id='$id'";
$result2=mysql_query($sql2);
while($rows=mysql_fetch_array($result2)){
?>
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<td><table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
<tr style='overflow:hidden; word-wrap:break-word;'>
<td bgcolor="lightgreen"><strong>Question:</strong></td>
<td bgcolor="lightgreen">:</td>
<td bgcolor="lightgreen" style="max-width: 1000px;"><?php echo $rows['q_question'] ?></td>
</tr>
<tr>
<td bgcolor="lightgreen"><strong>A</strong></td>
<td bgcolor="lightgreen">:</td>
<td bgcolor="lightgreen"><input type="radio" name="<?php echo $rows['q_question'] ?>" value="a"><?php echo $rows['a'] ?></td>
</tr>
<tr>
<td width="18%" bgcolor="lightgreen"><strong>B</strong></td>
<td width="5%" bgcolor="lightgreen">:</td>
<td width="77%" bgcolor="lightgreen"><input type="radio" name="<?php echo $rows['q_question'] ?>" value="b"><?php echo $rows['b'] ?></td>
</tr>
<tr>
<td width="18%" bgcolor="lightgreen"><strong>C</strong></td>
<td width="5%" bgcolor="lightgreen">:</td>
<td width="77%" bgcolor="lightgreen"><input type="radio" name="<?php echo $rows['q_question'] ?>" value="c"><?php echo $rows['c'] ?></td>
</tr>
<tr>
<td bgcolor="lightgreen"><strong>D</strong></td>
<td bgcolor="lightgreen">:</td>
<td bgcolor="lightgreen"><input type="radio" name="<?php echo $rows['q_question'] ?>" value="d"><?php echo $rows['d'] ?></td>
</tr>
<?php
In this part im getting the correct answer in the database (the answer is a)
$correct_answer == $rows['answer'];
This score = score + 1; is not working
if ($correct_answer==$_POST[$rows['q_question']]){
$score = $score + 1;
}
?>
<?php
$connection=mysql_connect('localhost', 'root','');
mysql_select_db('thesis');
$username= $_SESSION['username'];
$query6 = mysql_query("SELECT * FROM student WHERE username='$username'");
$row6 = mysql_fetch_assoc($query6);
$s_id = $row6['id'];
$name = $row6['name'];
$email = $row6['email'];
$position = $row6['position'];
?>
This is where I get all the data needed in the results
<p hidden>
<input type="text" name="s_id" value="<?php echo $s_id ?>">
<input type="text" name="q_id" value="<?php echo $rows['q_id'];?>">
<input type="text" name="score" value="<?php echo $score; ?>">
</p>
</table></td>
</tr>
<hr>
</table><br>
<?php
}
?>
<input type="submit" name="submit" value="Submit Answer" class="btn">
</form>
After hitting the submit button, im only getting s_id, q_id , but the score is still 0 even if I selected the correct answer
My problem here is getting the selected radio button and then comparing it to the answer(where is in the database)
I just did a quick mock up and this worked for me.
$answer = $_POST["'" . $rows['q_question'] . "'"];
if ($correct_answer == $answer)
{
$score++;
}

How to set maximum attachment size in Squirrelmail

I am using squirrelmail and I have a max size limit 5mb. When User tries to upload file larger than this limit Squirrelmail shows warning message successfully.
The problem is when user tries to upload file larger than "post_max_size"(php.ini) value, my php page just refreshes and Squirrelmail doesn't display any warning message. Is there any way to handle files larger than "post_max_size" value?
<div class="compose">
<table cellspacing="0" class="table1" id="attachment_table">
<tr class="header">
<td class="fieldName" style="width: 1%; white-space: nowrap;">
<?php echo _("New attachment");?>:
</td>
<td class="fieldValue">
<?php
if($max_file_size != -1) {
echo '<input type="hidden" name="MAX_FILE_SIZE" value="' . $max_file_size . '" />';
}
?>
<input type="file" name="attachfile" size="48" <?php if ($accesskey_compose_attach_browse != 'NONE') echo 'accesskey="' . $accesskey_compose_attach_browse . '" '; ?>/>
<input type="submit" name="attach" <?php if ($accesskey_compose_attach != 'NONE') echo 'accesskey="' . $accesskey_compose_attach . '" '; ?>value="<?php echo _("Attach"); ?>" />
<?php
if($max_file_size != -1) {
echo '(' . _("Max.") . ' ' . humanReadableSize($max_file_size) . ')';
}
if (!empty($plugin_output['add_attachment_notes'])) echo $plugin_output['add_attachment_notes'];
?>
</td>
</tr>
<?php
if (!empty($plugin_output['attachment_inputs'])) echo $plugin_output['attachment_inputs'];
$attachment_count = 1;
foreach ($attachments as $attach) {
?>
<tr class="attachment">
<td class="fieldName" style="width: 1%">
<input type="checkbox" name="delete[]" id="delete<?php echo $attachment_count; ?>" accesskey="<?php echo ($attachment_count % 10); ?>" value="<?php echo $attach['Key']; ?>" />
</td>
<td class="fieldValue"><label for="delete<?php echo $attachment_count; ?>">
<?php echo $attach['FileName']; ?> - <?php echo $attach['ContentType']; ?> (<?php echo humanReadableSize($attach['Size']); ?>)
</label></td>
</tr>
<?php
$attachment_count++;
}
if (count($attachments) > 0) {
?>
<tr class="header">
<td colspan="2">
<input type="submit" name="do_delete" <?php if ($accesskey_compose_delete_attach != 'NONE') echo 'accesskey="' . $accesskey_compose_delete_attach . '" '; ?>value="<?php echo _("Delete Selected Attachments"); ?>" />
</td>
</tr>
<?php
}
?>
</table>
</div>

Categories

Resources