i try to store the booking booths into database based on user selection, there are 10 check boxes for each booths and user can choose which day they want to reserve booths. For each check box has it own field in database, if user choose booth A01, D1 and D2, when he press reserve button, it will insert value into D1 and D2. But I dont know how to get the checked checkbox value to store in database
my booth interface
http://i.imgur.com/umYcI.gif
my table structure
http://i.imgur.com/vKh6R.gif
My coding
<?php
session_start();
if ( !isset($_SESSION['AUTHORIZED_USERNAME']) || empty($_SESSION['AUTHORIZED_USERNAME']) ) {
header("location:index.php");
}else{
$user=$_SESSION['AUTHORIZED_USERNAME'];
}
include('db.php');
if($_REQUEST){
$id = $_REQUEST['search_category_id'];
$query2 = mysql_query("SELECT filenameBig, filename, url FROM eventinfo where eventID ='$id'");
$row = mysql_fetch_array($query2, MYSQL_ASSOC);
if($id == -1)
{
echo "<style type='text/css'>#btn_submit{visibility:hidden}</style>";
}
else{
/*echo "<a href='{$row['url']}'>Click me!</a>";*/
echo "<p><br><img src='{$row['filename']}' alt='' /></p>";
echo "<p></p>";
echo "<p align='right'><a href='$row[filenameBig]' target='_blank'>Click to view large image</a></p>";
echo "<hr size='1'>";
echo "<div style='padding-left:4px;' align='left'><strong>Booths Listing</strong>";
echo "<p></p>";
$query = "select boothAlias, totalDay from booths, eventinfo where booths.eventID=eventinfo.eventID && booths.eventID = ".$id."";
$_SESSION['EVENT_ID']=$id;
$result = mysql_query($query);
$result2= mysql_query($query);
echo "<table border='0' style='width:400px;table-layout:fixed' >";
$rows2 = mysql_fetch_array($result);
$Day=$rows2['totalDay'];
echo "<table>";
for ($day = 0; $day <= $Day; ++$day) {
if($day==0){
echo "<th>Booth</th>";
}else{
echo "<th>D".$day."</th>";
}
}
while($rows = mysql_fetch_array($result2)){
$boothAlias=$rows['boothAlias'];
$totalDay=$rows['totalDay'];
echo "<tr><td>$boothAlias</td>";
for ($day2 = 1; $day2 <= $totalDay; ++$day2) {
echo "<td><input name='day2[]' type='checkbox' value='$day2' /></td>";
}
echo "</tr>";
}
echo "</table>";
}
}
?>
I think that SET type would be good solution for this.
http://dev.mysql.com/doc/refman/5.0/en/set.html
Related
The employee will enter empID and set the session for them. When they enter the page there will a list of customer. When they click update, it will redirect to update page while make the session id based on the custIC. The question is why is it send the last custIC in the array and not the one I choose??? Btw i'm using xampp to connect with my database.
<?php
session_start();
require "lowkosDB.php";
?>
<?php
$empID = $_POST['empID'];
$password = $_POST['password'];
$selectsql = "SELECT *
FROM employee
WHERE empID = '$empID'
AND password = '$password';";
$result = mysql_query($selectsql);
$numRows = mysql_num_rows($result);
$row = mysql_fetch_array($result);
$id = $row['empID'];
$selectsql2 = "SELECT * from customer C, employee E, item I, reference R, service S
WHERE R.custIC = C.custIC
AND R.itemNo = I.itemNo
AND R.servNo = S.servNo
AND R.empID = E.empID
ORDER BY refNo;";
$result2 = mysql_query($selectsql2);
$numRows2 = mysql_num_rows($result2);
$row2 = mysql_fetch_array($result2);
if($numRows > 0) {
print "Welcome back, $row[empName]<br>";
print "What to do next?<br>";
print "<a href=update.php?empID=$id>Update</a><br>";
print "<a href=delete.php?empID=$id>Delete</a><br>";
$_SESSION['empID'] = $id;
print "Your session id is ".$_SESSION['empID'];
print "<table border=1 ><tr align=center><th>Reference No</th>";
print "<th>Customer IC</th>";
print "<th>Customer Name</th>";
print "<th>Item No</th>";
print "<th>Service No</th>";
print "<th>Technician ID</th>";
print "<th>Progress</th></tr>";
$c = 0;
while($row2 = mysql_fetch_assoc($result2)) {
echo "<tr align=center><td>$row2[refNo]</td>";
echo "<td>$row2[custIC]</td>";
echo "<td>$row2[custName]</td>";
echo "<td>$row2[itemNo]</td>";
echo "<td>$row2[servNo]</td>";
echo "<td>$row2[empName]</td>";
echo "<td>$row2[progress]</td>";
$cust[$c] = $row2['custIC'];
echo "<td><a href=update.php?custIC[$c]=$cust[$c]>UPDATE</a></td></tr>";
$c = $c + 1;
echo "$c"; }
print "</table>";
print "<br/>Register a new customer? Click <a href=insert.php>HERE</a>";
for($i=0;$i<$c;$i++) {
echo $cust[$i];
}}
else
print "Login unsuccessful. Please <a href=login.php>Re-Login</a>";
?>
I have problem in retrieving one question on one page for online examination system from database. Currently I am retrieving with session variable. But problem in that is if we refresh page then session variable is increment and question is change with next serial number. Currently I am increment retrieving session variable from other page. So my question is how to solve change of question problem while refreshing page? Below is my code. and remaining code is in image file.
include("database.php");
$query="select * from ctip_question";
if($submit=='Next Question' && isset($ans))
{
mysql_data_seek($rs,$_SESSION[qn]);
$row= mysql_fetch_row($rs);
$question = $_SESSION[question];
$time = date('Y-m-d h:i:s');
mysql_query("insert into ctip_answer(test_id, q_no, qtype, answer,time) values ('1', '$_SESSION[qn]','$question','$ans','$time')") or die(mysql_error());
if($ans==$row[7])
{
$_SESSION[trueans]=$_SESSION[trueans]+1;
}
$_SESSION[qn]=$_SESSION[qn]+1;
$initialize_qn_no++;
}
else if($submit=='Get Result' && isset($ans))
{
mysql_data_seek($rs,$_SESSION[qn]);
$row= mysql_fetch_row($rs);
$time = date('Y-m-d h:i:s');
$question = $_SESSION[question];
mysql_query("insert into ctip_answer(test_id, q_no, qtype, answer,time) values ('1', '$_SESSION[qn]','$question','$ans','$time')") or die(mysql_error());
if($ans==$row[7])
{
$_SESSION[trueans]=$_SESSION[trueans]+1;
}
echo "<h1 class=head1> Result</h1>";
$_SESSION[qn]=$_SESSION[qn]+1;
echo "<Table align=center><tr class=tot><td>Total Question<td> $_SESSION[qn]";
echo "<tr class=tans><td>True Answer<td>".$_SESSION[trueans];
$w=$_SESSION[qn]-$_SESSION[trueans];
echo "<tr class=fans><td>Wrong Answer<td> ". $w;
echo "</table>";
mysql_query("insert into mst_result(login,test_id,test_date,score) values('$login',$tid,'".date("d/m/Y")."',$_SESSION[trueans])") or die(mysql_error());
echo "<h1 align=center><a href=review.php> Review Question</a> </h1>";
unset($_SESSION[qn]);
unset($_SESSION[sid]);
unset($_SESSION[tid]);
unset($_SESSION[trueans]);
exit;
}
$sql = "select * from ctip_test_question where test_id='$_SESSION[testid]' && sr_no=$_SESSION[qn]";
$result = mysql_query($sql);
while ($row1 = mysql_fetch_array($result)) {
{
$question = $row1['que_no'];
$_SESSION[question]=$question;
$rs=mysql_query("select * from ctip_question where que_id=$question",$cn) or die(mysql_error());
mysql_data_seek($rs,$_SESSION[qn]);
$row= mysql_fetch_row($rs);
echo "action=self_page";
$n=$_SESSION[qn]+1;
echo "here is my question";
echo "option1";
echo "option2";
echo "option3";
echo "option4";
if($_SESSION[qn]<20)
echo "next question";
else
echo "get result";
}
}
Below is the code from catalog page with the data which has to be inserted to the database. It has some problem and i cant insert that data to the database table, and i think i have not ported variables correctly.
My catalogue page has this code (it is for purchasing photographs):
while ($row=mysql_fetch_assoc($result))
{
echo "<tr><td width=100><img src=".$row['FilePath']." /></td>";
echo "<td width=100 padding=25>".$row['Title']."</td>"; $hour = time() + 3600; setcookie('titlecookie', $row['Title'], $hour);
echo "<td width=100 padding=25>".$row['Cost']."</td>";
echo "<td width=100>".$row['FileSize']."</td>";
echo "<td width=100>".$row['CaptureDate']."</td>";
echo "<td width=100>".$row['Resolution']."</td>";
echo "<td width=100><input type=checkbox name=checked[] value=select />Purchase</td></tr>";
}
echo "</table><input type=submit name=submit value=Purchase></form></center>";
}
else
{
echo "Query not successful";
}
The code for my purchase page appears as follows:
$username = "COOKIE['ID_my_site']";
$title = "COOKIE['titlecookie']";
$Custid = mysql_query("SELECT Custid from Customer Where Username=$username");
$Money = $_POST['Cost'];
$Photoid = mysql_query("SELECT Photoid from Photograph Where Title = $row[Title]");
foreach ($_POST['checked'] as $select) {
if(mysql_query('INSERT INTO Transaction (Money, Custid)
VALUES ($Money, $Custid)'))
{
echo "successfully added to Transaction";
}
else
{
echo "Problems adding data to Transaction";
}
if(mysql_query("INSERT INTO TransPhoto (Photoid, Transid)
VALUES ('$Photoid', '$Transid')"))
{
echo "successfully added to Transphoto";
}
else
{
echo "Problems adding data to Transphoto";
}
}
Could you possible assist me with fixing this code? I am relatively new to this but have searched and could not find an effective solution. Thanks
I'm having problems to find how to create an hyperlink in a table column result and then, on click, open another page with all fields (textboxes) filled. Imagine when a click an ID, i do a select * from table where column_id = ID... Is there a way to do it?
Thanks.
Best regards
I'm not completely sure what you are asking, but this may help you a bit.
First make a Javascript.
<script type="text/JavaScript">
function selectID() {
var ID = document.getElementById("ID").value;
document.location.href ="yoursite.php?ID="+ID;
}
</script>
Then connect to your database to query the table for a link ID (or more) for example by changing the variable $value.
<?php
//Connect to database
mysql_connect("host", "user", "pass");
mysql_select_db("db_name");
$value = 'something';
$ID = $_GET['ID'];
if (!$ID) {
$ID = 0;
}
if ($ID == 0) {
$query = "SELECT * FROM table WHERE `column_1` = '$value'";
$result = mysql_query($query);
echo "<table>";
while($myrow = mysql_fetch_array($result)) {
echo "<tr>";
echo "<td>";
echo "ID";
echo "</td>";
echo "</tr>";
}
echo "</table>";
}
elseif ($ID > 0) {
$query2 = "SELECT * FROM table WHERE `column_id` = '$ID'";
$result2 = mysql_query($query2);
while($myrow2 = mysql_fetch_array($result2)) {
$value1 = $myrow2['column_1'];
$value2 = $myrow2['column_2'];
}
echo "<form type=\"GET\" action=\"$PHP_SELF\">";
echo "<input type=\"text\" id=\"ID\" name=\"ID\" value=\"$ID\"><br>";
echo "<input type=\"text\" id=\"value1\" name=\"value1\" value=\"$value1\"><br>";
echo "<input type=\"text\" id=\"value2\" name=\"value2\" value=\"$value2\"><br>";
echo "<input type=\"hidden\" id=\"search\" name=\"search\" value=\"searching\">";
echo "<input type=\"submit\" id=\"submitbutton\" name=\"submitbutton\" value=\" Search \">";
echo "</form>";
}
?>
Trying to Update the MySQL Tables but nothing is being updated, I'm sure I'm just not seeing the tiny issue, would love some help. Thanks
So its a trade block for a hockey pool, if you want the player on the trade block then you just check the CHECKBOX in the form and submit and it should change the value in the database to value of "1".
FORM:
echo "<table border='1'>";
echo "<tr><th>NAME</th> <th>POS</th> <th>BLOCK</th></tr>";
$counter = 1;
while($row = mysql_fetch_array( $result )) {
echo "<tr><td>";
echo "{$row['f_name']}" . " " . "{$row['l_name']}";
echo "</td><td><input name='pl_id[$counter]' type='hidden' value='{$row['pl_id']}'>";
echo "{$row['pos']}";
echo "</td><td><input name='pos[$counter]' type='hidden' value='{$row['pos']}'>";
echo "<input type='checkbox' name='block[$counter]' size='1' value='1'";
if($row['block'] == '1')
{
echo "checked='checked'";
}
echo "></td></tr>";
$counter++;
}
echo "</table>";
SUBMIT PHP PAGE:
mysql_connect("localhost", "user", "pass") or die(mysql_error());
mysql_select_db("mbbcom1_fantrax") or die(mysql_error());
$i = 1;
while ($i < 26) {
$block = $_POST['block'][$i];
$pl_id = $_POST['pl_id'][$i];
$query = mysql_query("UPDATE 'players'
SET `block` = '$block'
WHERE `players`.`pl_id` = '$pl_id'");
mysql_query($query);
$i++; }
echo mysql_close();
Remove comma before WHERE
mysql_query("UPDATE 'players'
SET block = '$block'
WHERE players.pl_id = '$pl_id'");
You have a } to less, so the PHP code doesn't run.
You do a while loop and a foreach loop, but you are only closing the for loop.
And of course you don't need a , before the WHERE statement