I am trying to call a form and php filefrom a javascript function but it does not work. It might have to do with the cookies, it does not call the "frmSubdeptChainDailyHL" form and it does not call the "subdeptclass_reportHL.php" file, here is the code:
function submitClassChainDaily()
{
var store = readCookie('storeAccess');
var clss = readCookie('classAccess');
var subdept = readCookie('subDeptAccess');
var period = readCookie('period');
if (period == null || period == '') {
period = 'CUR';
}
document.frmClassChainDaily.period.value = period;
var storePref = readCookie('storePref');
if (storePref == null || storePref == '') {
if (store == null || store == '') {
storePref = 'ALL';
} else {
storePref = store;
}
}
if ((storePref.length) > 3 && storePref != 'ALL100') {
document.setStore.submit();
} else {
document.frmClassChainDaily.store.value = storePref;
if (clss == null || clss == '') {
clss = 'ALL';
}
document.frmClassChainDaily.clss.value = clss;
if (subdept == null || subdept == '') {
subdept = 'ALL';
}
document.frmClassChainDaily.subdept.value = subdept;
";
if ($_REQUEST['storePref']=='099')
{
echo "document.frmSubdeptChainDailyHL.submit();";
} else {
echo "document.frmSubdeptChainDaily.submit();";
}
echo "
}
}
Here is the form code:
if ($_REQUEST['storeCode'] == '099') {
echo"
<li>
<!-- SubDept Daily Sales - Chain -->
<form name=\"frmSubdeptChainDailyHL\" action=\"subdeptclass_reportHL.php\">
<input type=hidden value=\"\" name=\"store\">
<input type=hidden value=\"\" name=\"subdept\">
<input type=hidden value=\"\" name=\"clss\">
<input type=hidden value=\"\" name=\"period\">
</form>
<a style=\"display: block; text-decoration: none; color: #000\" href=\"javascript: submitSubDeptChainDaily();\">
<h3 class=\"longfield\">
<img src=\"content/images/icons/US_dollar_icon.png\" alt=\"icon\" class=\"icon\"/>
<span>Sales</span>
</h3>
</a>
</li>
You cant directly call to a php function from javascript. Make use of some ajax calls
Related
My error because the user inputted a non numerical value, the if else statement to change the value of the incrementing value to a positive number if the user inputs a negative value and the change if the start value is greater that the stop value is not working either.
<?php
$banner = "Self-referring Forms w/Data Validation";
include ("./header.php");
$start = "";
$stop = "";
$incr = "";
$error = "";
$output = "";
$checkResult = false;
$MAX_ITERATIONS = 100;
?>
<h2><?php echo $output; ?></h2>
<h3><?php echo $error; ?></h3>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST" >
<p id="para6">Starting Temperature: <input
type="text" name="starting_number" size="12"<?php ?>/><br/>
<p id="para6">Stop Temperature :
<input type="text" name="stop_number" size="12" /><br/>
<p id="para6">Temperature Increment: <input type="text"
name="increment_number" size="12" /><br/></p>
<input id="para6" type="submit" value="Create Temperature Conversion Table" name="calculate"/>
<?php
error_reporting(E_ERROR | E_PARSE);
try
{
if($_SERVER["REQUEST_METHOD"] == "GET"){
$start = "";
$stop = "";
$incr = "";
}
else if($_SERVER["REQUEST_METHOD"] == "POST")
{
$start=(double)trim($_POST["starting_number"]);
$stop=(double)trim($_POST["stop_number"]);
$incr=(double)trim($_POST["increment_number"]);
$num = (double)($stop-$start)/$incr;
if($start == "" || $stop == "" || $incr == "" || $num == "")
{
//means the user did not enter anything
$error .= "The text boxes cannot be blank.";
echo $error;
}
else if($num>$MAX_ITERATIONS)
{
$error .= "The conditions will cause too many iterations (max. 100), therefore (for the
sake of server resources) your request is denied.";
echo $error;
}
This is where I need help
else if($start >= $stop)
{
$start == $stop;
$stop == $start;
}
else if($incr == "0")
{
$error .= "You must enter a non-zero increment.";
echo $error;
}
else if($incr < "0")
{
$incr == $incr * (-1);
}
else if($start == input type="text" || $stop == input type="text" ||$incr == input
type="text" || $num == input type="text")
{
$error .= "You must enter a numerical value";
echo $error;
}
The rest is just for you to see what the rest of my code looks like
else
{
echo "<table border='1'>";
echo "<tr>";
echo "<th>Celcius</th>";
echo "<th>Fahrenheit</th>";
echo "</tr>";
for($i=$start; $i<=$stop; $i += $incr)
{
echo "<tr>";
echo "<td>". $i . "°</td>";
echo "<td>". (($i * 9/5) + 32 ). "°</td>";
echo "</tr>";
}
echo "</table>";
}
if($error == "")
{
$output = "";
}
else
{
$error .= "<br/>Please try again.";
}
}
}
catch(DivisionByZeroError $e)
{
echo "The text boxes cannot be blank.";
}
catch(Exception $e)
{
echo 'Please Enter correctly';
}
?>
</form>
<?php
include ("./footer.php");
?>
I am working on a page that deals with a lot of data that the user can select what to pass to another page via a form. I have stumbled upon a big problem: When I want to pass the first items on the list the page does it flawlessly. However when I want to just select the very last items they're not being passed. Example
Can you please tell me what is going on? Thanks!
Code that creates the checkboxes. All 1085 of them:
echo "<form name='frmIns' method = 'POST' action = 'xx.php'>";
if(mysqli_num_rows($tablaO)>0)
{
$i = 0;
$e = 1;
while($registroO=mysqli_fetch_assoc($tablaO))
{
if ($e%2== 0)
{
if($registroO['art_nota'] == 'Inventario' || $registroO['art_nota'] == 'Espera de Devolución' || $registroO['art_nota'] == 'Se va a Inventario') $color = 'e9bd15';
else $color='c5efef';
}else{
if($registroO['art_nota'] == 'Inventario' || $registroO['art_nota'] == 'Espera de Devolución' || $registroO['art_nota'] == 'Se va a Inventario') $color = 'e9bd15';
else $color='fdfdfd';
}
$ValidacionID = $registroO['art_id_verificador'];
if($ISBN13r == null and $libro != null && $articulos == null)
{
$Idverificador = $registroO['art_id_verificador'];
echo '<tr valign="top" class="registro" name="tr/'.$i.'" id="tr/'.$Idverificador.'" style="font-size: 11.5px; text-align: -webkit-center; background-color:#'.$color.'">
<td>'.$e.'</td>
<td>
<input type="checkbox" name="chbArticulo[]" value="'.$Idverificador.'" onChange="cambia(this)" />
<input type="hidden" name="IDEs[]" value="'.$Idverificador.'" />
<input type="hidden" name="IdVerif[]" value="'.$ValidacionID.'" />
</td>';
}else if($ISBN13r != null and $libro == null && $articulos == null){
echo'<tr valign="top" class="registro" style="font-size: 11.5px; text-align: -webkit-center; background-color:#'.$color.'">
<td>'.$e.'</td>
<td></td>';
}else{
$Idverificador = $registroO['art_id_verificador'];
echo '<tr valign="top" class="registro" name="tr/'.$i.'" id="tr/'.$Idverificador.'" style="font-size: 11.5px; text-align: -webkit-center; background-color:#'.$color.'">
<td>'.$e.'</td>
<td>
<input type="checkbox" name="chbArticulo[]" value="'.$Idverificador.'-'.$Idverificador.'" onChange="cambia(this)" />
<input type="hidden" name="IDEs[]" value="'.$Idverificador.'" />
<input type="hidden" name="IdVerif[]" value="'.$ValidacionID.'" />
</td>';
}
echo'<td>'.$registroO['art_id_verificador'].'</td>
<td>'.$registroO['art_id_orden'].'</td>
<td>'.$registroO['art_fecha'].'</td>
<td>'.$registroO['art_N13'].'</td>
<td>'.$registroO['art_destino'].'</td>
<td style="'.($registroO['art_ofna_de'] != "" || $registroO['art_ofna_de'] != null ? "background-color:yellow;" : "").'">'.$registroO['art_ofna_de'].'</td>
<td>'.$registroO['art_ISBN'].'</td>
<td style = "max-width:250px; overflow:ellipsis;">'.$registroO['art_titulo'].'</td>
<td>'.$registroO['art_SKU'].'</td>
<td>'.$registroO['art_cantidad'].'</td>
<td>$'.number_format(($registroO['art_precio_logistica'] > 0 ? $registroO['art_precio_logistica'] : $registroO['art_precio']),2,".",",").'</td>
<td>'.$registroO['art_id_proveedor'].'</td>
<td>'.$registroO['art_nota'].'</td>
<td>'.($registroO['art_guia_ofna_arg'] == '' ? $registroO['art_guia_ofna'] : $registroO['art_guia_ofna_arg']).'</td>
</tr>';
$i=$i+ 1;
$e=$e+ 1;
/*<td>'.$registroO['OfMi_pvp'].'</td>
<td>'.$registroO['OfMi_costUnitario'].'</td>
<td>'.$registroO['OfMi_TotalDeposito'].'</td>
<td>'.$registroO['OfMi_TotalOrden'].'</td>
<td>'.$registroO['OfMi_MarginProf'].'</td>*/
}
}
echo "</form>";
<input type="button" value="addkid " onClick="show()" />
<div>
<div id="myTableData" style="display:none; width:800px; height:500px; background-color:yellow; margin:0 auto;">
<form action="javascript:insert()" method="get">
<table>
<tr>
<td width="175">NAME</td>
<td width="245"> Gender</td>
<td width="245">Date of Birth</td>
</tr>
<tr>
<td width="175">
<input type="text" name="kid_name" id="kid_name" />
</td>
<td width="245">FEMALE
<input type="radio" name="gender" value="female" id="gender" />MALE
<input type="radio" name="gender" id="gender" value="male" />
</td>
<td width="245">
<?php for ( $i=1; $i<13; $i++ ) { $month=d ate( 'm', mktime(0,0,0,$i,2,2000)); $sel=( $i==d ate( 'n') ? ' selected="selected"' : ''); $options1[]="<option value=\" {$month}\ " {$sel}>{$month}</option>"; } $options_list1=j oin( "", $options1); echo "<select name=\"month\ " id='month' >{$options_list1}</select>"; for ( $j=1; $j<32; $j++ ) { $theday=d ate( 'd', mktime(0,0,0,0,$j,2000)); $sel=( $j==d ate( 'd') ? ' selected="selected"' : ''); $options2[]="<option value=\" {$theday}\ " {$sel}>{$theday}</option>"; } $options_list2=j oin( "\r\n", $options2); echo "<select name=\"day\ " id='day' >{$options_list2}</select>"; for ( $k=1960; $k<2016; $k++ ) { $theyear=d ate( 'Y', mktime(0,0,0,1,1,$k)); $sel1=( $k==d ate( "Y") ? ' selected="selected"' : ''); $options3[]="<option value=\" {$theyear}\ " {$sel1}>{$theyear}</option>"; } $options_list3=j oin( "\r\n", $options3); echo "<select name=\"year\ " id='year' >{$options_list3}</select>"; ?>
</td>
</tr>
</table>
<input type="submit" name="sub" value="add" />
</form>
</div>
</div>
<script>
function show() {
document.getElementById("myTableData").style.display = "block";
}
function createObject() {
var request_type;
var browser = navigator.appName;
if (browser == "Microsoft Internet Explorer") {
request_type = new ActiveXObject("Microsoft.XMLHTTP");
} else {
request_type = new XMLHttpRequest();
}
return request_type;
}
var http = createObject();
//value solve an Internet Explorer cache issue
var nocache = 0;
function insert() {
// Optional: Show a waiting message in the layer with ID login_response
document.getElementById('content02').innerHTML = "Just a second..."
// Required: verify that all fileds is not empty. Use encodeURI() to solve some issues about character encoding.
var kid_name = encodeURI(document.getElementById('kid_name').value);
var gender = encodeURI(document.getElementById('gender').value);
var month = encodeURI(document.getElementById('month').value);
var day = encodeURI(document.getElementById('day').value);
var year = encodeURI(document.getElementById('year').value);
// Set te random number to add to URL request
nocache = Math.random();
// Pass the login variables like URL variable
http.open('get', '4.php?kid_name=' + kid_name + '&gender=' + gender + '&month=' + month + '& day=' + day + '&year=' + year + '&nocache = ' + nocache);
http.onreadystatechange = insertReply;
http.send(null);
}
function insertReply() {
if (http.readyState == 4) {
var response = http.responseText;
// else if login is ok show a message: "Site added+ site URL".
document.getElementById('content02').innerHTML = 'Your contact was successfully added!' + response;
}
}
</script>
4.php
<?php
if(isset($_GET['kid_name']) && isset($_GET['gender']) && isset($_GET['year']) && isset($_GET['day']) && isset($_GET['month']) )
{
echo $newFname = $_GET["kid_name"] ;
echo $newLname = $_GET["gender"] ;
echo $newPhone = $_GET["year"] ;
echo $newEmail = $_GET["day"] ;
echo $newAddress = $_GET["month"] ;
//$insertContact_sql = "INSERT INTO `test`.`contacts` (`newFname`, `newLname`, `newPhone`, `newEmail`, `newAddress`, `group`) VALUES ('{$newFname}' , '{$newLname}' , '{$newPhone}' , '{$newEmail}' , '{$newAddress}' , '{$group}')";
//$insertContact= mysql_query($insertContact_sql) or die(mysql_error());
} else
{
echo 'Error! Please fill all fileds!';
}
?>
I am working with php language. There is a addkid button, which, when the user clicks on the button a pop type window shows the form which has NAME , GENDER AND DOB. In the form action javascript:insert(). I am using ajax for the 1st time so I am not able to understand why it's not working. I guess it should redirect me to 4.php and in 4.php it will echo the values?
I have tested your code and seems it works, I just added a div to show the results there...
You can try to add this div you are not already added it...
<div id="content02">
</div>
Here you write the response, like "Your contact was successfully added"....
So, i made a seat booking system where there are checkboxes in every seat and the user select this boxes and the seats are considered reserved.
But now i want make the user be able to give each marked seat a name. How can i do that?
seats.php
<?php include("login.php"); ?>
<html>
<head>
<title>Tickets</title>
<style>
* {
font-size: 11px;
font-family: arial;
}
</style>
<script>
function reserveSeats() {
var selectedList = getSelectedList('Reserve Seats');
if (selectedList) {
if (confirm('Do you want to reserve
selected seat/s '
+ selectedList + '?')) {
document.forms[0].oldStatusCode.value=0;
document.forms[0].newStatusCode.value=1;
document.forms[0].action='bookseats.php';
document.forms[0].submit();
} else {
clearSelection();
}
}
}
function cancelSeats() {
var selectedList = getSelectedList('Cancel Reservation');
if (selectedList) {
if (confirm('Do you want to cancel reserved seat/s ' + selectedList + '?')) {
document.forms[0].oldStatusCode.value=1;
document.forms[0].newStatusCode.value=0;
document.forms[0].action='bookseats.php';
document.forms[0].submit();
} else {
clearSelection();
}
}
}
function confirmSeats() {
var selectedList = getSelectedList('Confirm Reservation');
if (selectedList) {
if (confirm('Do you want to confirm reserved seat/s ' + selectedList + '?')) {
document.forms[0].oldStatusCode.value=1;
document.forms[0].newStatusCode.value=2;
document.forms[0].action='bookseats.php';
document.forms[0].submit();
} else {
clearSelection();
}
}
}
function getSelectedList(actionSelected) {
// get selected list
var obj = document.forms[0].elements;
var selectedList = '';
for (var i = 0; i < obj.length; i++) {
if (obj[i].checked && obj[i].name == 'seats[]') {
selectedList += obj[i].value + ', ';
}
}
// no selection error
if (selectedList == '') {
alert('Please select a seat before clicking ' + actionSelected);
return false;
} else {
return selectedList;
}
}
function clearSelection() {
var obj = document.forms[0].elements;
for (var i = 0; i < obj.length; i++) {
if (obj[i].checked) {
obj[i].checked = false;
}
}
}
function refreshView() {
clearSelection();
document.forms[0].action='<?php echo $_SERVER['PHP_SELF']; ?>';
document.forms[0].submit();
}
</script>
</head>
<body>
<table>
<tr><td width="100%" align="center">
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<input type="hidden" name="oldStatusCode" value=""/>
<input type="hidden" name="newStatusCode" value=""/>
<table width='100%' border='0'>
<tr><td align='center'>
<input type='button' value='Refresh View' onclick='refreshView();'/>
</td></tr>
</table>
</td></tr>
<tr><td width="100%" align="center">
<table width='100%' border='0'>
<tr><td align='center'>
<input type='button' value='Reserve Seats' onclick='reserveSeats()'/>
<input type='button' value='Confirm Reservation' onclick='confirmSeats()'/>
<input type='button' value='Cancel Reservation' onclick='cancelSeats()'/>
</td></tr>
</table>
</td></tr>
<tr><td width="100%" align="center">
<table width='100%' border='0'>
<tr><td align='center'>
<input type='button' value='Clear Selection' onclick='clearSelection()'/></td>
</tr>
</table>
</td></tr>
<tr><td width="100%" align="center">
<?php
/*
* Created on Mar 17, 2007
* Author: dayg
*/
$linkID = # mysql_connect("localhost", "tickets", "tickets") or die("Could not connect to MySQL server");
# mysql_select_db("tickets") or die("Could not select database");
/* Create and execute query. */
$query = "SELECT * from seats order by rowId, columnId desc";
$result = mysql_query($query);
$prevRowId = null;
$seatColor = null;
$tableRow = false;
//echo $result;
echo "<table width='100%' border='0' cellpadding='3' cellspacing='3'>";
while (list($rowId, $columnId, $status, $updatedby) = mysql_fetch_row($result))
{
if ($prevRowId != $rowId) {
if ($rowId != 'A') {
echo "</tr></table></td>";
echo "\n</tr>";
}
$prevRowId = $rowId;
echo "\n<tr><td align='center'><table border='1' cellpadding='8' cellspacing='8'><tr>";
} else {
$tableRow = false;
}
if ($status == 0) {
$seatColor = "lightgreen";
} else if ($status == 1 && $updatedby == 'user1') {
$seatColor = "FFCC99";
} else if ($status == 1 && $updatedby == 'user2') {
$seatColor = "FFCCFF";
} else if ($status == 2 && $updatedby == 'user1') {
$seatColor = "FF9999";
} else if ($status == 2 && $updatedby == 'user2') {
$seatColor = "CC66FF";
} else {
$seatColor = "red";
}
echo "\n<td bgcolor='$seatColor' align='center'>";
echo "$rowId$columnId";
if ($status == 0 || ($status == 1 && $updatedby == $_SERVER['PHP_AUTH_USER'])) {
echo "<input type='checkbox' name='seats[]' value='$rowId$columnId'></checkbox>";
}
echo "</td>";
if (($rowId == 'A' && $columnId == 7)
|| ($rowId == 'B' && $columnId == 9)
|| ($rowId == 'C' && $columnId == 9)
|| ($rowId == 'D' && $columnId == 10)
|| ($rowId == 'E' && $columnId == 8)
|| ($rowId == 'F' && $columnId == 5)
|| ($rowId == 'G' && $columnId == 13)
|| ($rowId == 'H' && $columnId == 14)
|| ($rowId == 'I' && $columnId == 14)
|| ($rowId == 'J' && $columnId == 12)
|| ($rowId == 'K' && $columnId == 14)
|| ($rowId == 'L' && $columnId == 13)
|| ($rowId == 'M' && $columnId == 9)) {
// This fragment is for adding a blank cell which represent the "center aisle"
echo "<td> </td>";
}
}
echo "</tr></table></td>";
echo "</tr>";
echo "</table>";
/* Close connection to database server. */
mysql_close();
?>
</td></tr>
<tr><td> </td></tr>
<tr><td width="100%" align="center">
<table border="1" cellspacing="8" cellpadding="8">
<tr>
<td bgcolor='lightgreen'>Available</td>
<td bgcolor='FFCC99'>Reserved user1</td>
<td bgcolor='FF9999'>Confirmed user1</td>
<td bgcolor='FFCCFF'>Reserved user2</td>
<td bgcolor='CC66FF'>Confirmed user2</td>
</tr>
</table>
</td></tr>
<tr><td> </td></tr>
<tr><td width="100%" align="center">
View Layout
</td></tr>
</table>
</form>
</body>
</html>
bookseats.php
<html>
<head>
<title>Book Seats</title>
<style>
* {
font-size: 14px;
font-family: arial;
}
</style>
</head>
<body>
<?php include("login.php"); ?>
<center>
<br/>
<br/>
<br/>
<?php
if (isset($_POST['seats']))
{
$user = $_SERVER['PHP_AUTH_USER'];
$newStatusCode = $_POST['newStatusCode'];
$oldStatusCode = $_POST['oldStatusCode'];
// open database connection
$linkID = # mysql_connect("localhost", "tickets", "tickets") or die("Could not connect to MySQL server");
# mysql_select_db("tickets") or die("Could not select database");
// prepare select statement
$selectQuery = "SELECT rowId, columnId from seats where (";
$count = 0;
foreach($_POST['seats'] AS $seat) {
if ($count > 0) {
$selectQuery .= " || ";
}
$selectQuery .= " ( rowId = '" . substr($seat, 0, 1) . "'";
$selectQuery .= " and columnId = " . substr($seat, 1) . " ) ";
$count++;
}
$selectQuery .= " ) and status = $oldStatusCode";
if ($oldStatusCode == 1) {
$selectQuery .= " and updatedby = '$user'";
}
//echo $selectQuery;
// execute select statement
$result = mysql_query($selectQuery);
//echo $result;
$selectedSeats = mysql_num_rows($result);
//echo "<br/>" . $selectedSeats;
if ($selectedSeats != $count) {
$problem = "<h3>There was a problem executing your request. No seat/s were updated.</h3>";
$problem .= "Possible problems are:";
$problem .= "<ul>";
$problem .= "<li>Another process was able to book the same seat while you were still browsing.</li>";
$problem .= "<li>You were trying to Confirm an unreserved Seat.</li>";
$problem .= "<li>You were trying to Cancel an unreserved Seat.</li>";
$problem .= "<li>You were trying to Reserve a reserved Seat.</li>";
$problem .= "<li>There was a problem connecting to the database.</li>";
$problem .= "</ul>";
$problem .= "<a href='seats.php'>View Seat Plan</a>";
die ($problem);
}
// prepare update statement
$newStatusCode = $_POST['newStatusCode'];
$oldStatusCode = $_POST['oldStatusCode'];
$updateQuery = "UPDATE seats set status=$newStatusCode, updatedby='$user' where ( ";
$count = 0;
foreach($_POST['seats'] AS $seat) {
if ($count > 0) {
$updateQuery .= " || ";
}
$updateQuery .= " ( rowId = '" . substr($seat, 0, 1) . "'";
$updateQuery .= " and columnId = " . substr($seat, 1) . " ) ";
$count++;
}
$updateQuery .= " ) and status = $oldStatusCode";
if ($oldStatusCode == 1) {
$updateQuery .= " and updatedby = '$user'";
}
// perform update
$result = mysql_query($updateQuery);
$updatedSeats = mysql_affected_rows();
if ($result && $updatedSeats == $count) {
//$mysql->commit();
echo "<h3>";
echo "You have successfully updated $updatedSeats seat/s: ";
echo "[";
foreach($_POST['seats'] AS $seat) {
$rowId = substr($seat, 0, 1);
$columnId = substr($seat, 1);
echo $rowId . $columnId . ", ";
}
echo "]";
echo "...</h3>";
} else {
//$mysql->rollback();
echo "<h3>There was a problem executing your request. No seat/s were updated.</h3>";
echo "Possible problems are:";
echo "<ul>";
echo "<li>Another process was able to book the same seat while you were still browsing.</li>";
echo "<li>You were trying to Confirm an unreserved Seat.</li>";
echo "<li>You were trying to Cancel an unreserved Seat.</li>";
echo "<li>You were trying to Reserve a reserved Seat.</li>";
echo "<li>There was a problem connecting to the database.</li>";
echo "</ul>";
}
echo "<a href='seats.php'>View Seat Plan</a>";
// Enable the autocommit feature
//$mysqldb->autocommit(TRUE);
// Recuperate the query resources
//$result->free();
mysql_close();
}
?>
</center>
</body>
</html>
EDIT:
I tried the following:
When the user submit the checkboxes, this is included:
name.php
<?php
//$mysql->commit();
session_start();
$_SESSION['rowId'] = $_POST['rowId'];
$_SESSION['columnId'] = $_POST['columnId'];
echo "<h3>";
echo "Please enter the name for each seat:<br><p> </p>";
echo "";
foreach($_POST['seats'] AS $seat) {
$rowId = substr($seat, 0, 1);
$columnId = substr($seat, 1);
echo $rowId . $columnId . '</br><form method="post" name="input" action="pt2.php" >
<input name="name" type="text"/></br>';
}
?>
<input type="submit" name="Submit" value="insert" />
</form>
pt2.php:
<?php
// Connect to MySQL
mysql_connect("localhost", "root", "root") or die("Connection Failed");
mysql_select_db("tickets")or die("Connection Failed");
$name = $_POST['name'];
session_start();
$rowId = $_SESSION['rowId'];
$columnId = $_SESSION['columnId'];
$result = mysql_query("UPDATE seats SET updatedby='".$name."' WHERE rowId='".$rowId."' AND columnId='".$columnId."'")
or die(mysql_error());
?>
If the user selects only one seat, this code works like a charm. But when there's two or more, the $columnId and the $rowId doesn't change as it should, and only the name of the last checked seat is changed.
i think you shouldn't use jquery for this part. try using php with an html form ( show an input next to the seat it has the checkbox ) then save the data into mysql seatid, seat_userId, seat_name etc... then just pull the data and do whatever you want with it.
My program here is a simple tic tac toe game and my winners are not being displayed properly the only 4 correct ones are the two diagonals and row ones win and column win.The html/javascript is not the problem its just the php.
<?php
//Players
$X = "Dalton";
$O = "Joe";
$winner = false;
//game board positoins
$r1c1 = !empty($_POST['r1c1'] ) ? $_POST['r1c1'] : '';
$r1c2 = !empty($_POST['r1c2'] ) ? $_POST['r1c2'] : '';
$r1c3 = !empty($_POST['r1c3'] ) ? $_POST['r1c3'] : '';
$r2c1 = !empty($_POST['r2c1'] ) ? $_POST['r2c1'] : '';
$r2c2 = !empty($_POST['r2c2'] ) ? $_POST['r2c2'] : '';
$r2c3 = !empty($_POST['r2c3'] ) ? $_POST['r2c3'] : '';
$r3c1 = !empty($_POST['r3c1'] ) ? $_POST['r3c1'] : '';
$r3c2 = !empty($_POST['r3c2'] ) ? $_POST['r3c2'] : '';
$r3c3 = !empty($_POST['r3c3'] ) ? $_POST['r3c3'] : '';
if($r1c1 == $r1c2 && $r1c2 == $r1c3 ) {
$winner = $r1c1;
} elseif($r2c1 == $r2c2 && $r2c2 == $r2c3 ) {
$winner = $r2c1;
} elseif($r3c1 == $r3c2 && $r3c2 == $r3c3 ) {
$winner = $r3c1;
} elseif($r1c1 == $r2c1 && $r2c1 == $r3c1 ) {
$winner = $r1c1;
} elseif($r1c2 == $r2c2 && $r2c2 == $r3c2 ) {
$winner = $r1c2;
} elseif($r1c3 == $r2c3 && $r2c3 == $r3c3 ) {
$winner = $r1c3;
} elseif($r1c1 == $r2c2 && $r2c2 == $r3c3 ) {
$winner = $r1c1;
} elseif($r1c3 == $r2c2 && $r2c2 == $r3c1 ) {
$winner = $r1c3;
} else {
$winner = 'Draw';
}
?>
<html>
<head>
<title>Tic-Tac-Toe</title>
<!--
The Javascript code below requires access to the internet to run. If you are
running this page on a computer with no Internet access, it will cause errors.
You may delete these lines or modify them if you wish.
The 1st block in the code below is helping you by not allowing any character
except an uppercase 'X' or uppercase 'O'. This is unnessisary, but makes it easier
for you to process on the PHP side.
The 2nd block of code is helping you by making any field that already has has
'X' or 'O' readonly when the page loads. Extra points will be giving to any student
how can replicate this part of the Javascript using only PHP. Simply delete the lines
below if you wish to attempt.
-->
<script src='https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js'></script>
<script type='text/javascript'>
$(document).ready(function(){
// This block of code prevents you from entering anything but X or O
$('input').bind('keyup',function() {
if( $(this).hasClass('button') == false ){
this.value = this.value.toUpperCase();
if(this.value != 'X' && this.value != 'O') {
this.value = '';
}
}
});
// This block of code makes the used spots on the grid readonly once used
$('input').each(function(i){
this.value = this.value.toUpperCase();
if(this.value == 'X' || this.value == 'O') {
$(this).addClass('disabled').attr('readonly', true);
//this.readOnly = true;
}
});
});
</script>
<!-- You may do as you please with this CSS code -->
<style>
body * { padding:0; margin:0; }
.disabled { background: #eeeeee; }
.button { display: block; width:180px; margin: 10px 0; }
#gameboard { border-collapse:collapse; padding:0; margin:0; }
#gameboard tr:nth-child(even) {
border-top:2px solid black;
border-bottom:2px solid black;
}
#gameboard tr td:first-child { border-right:2px solid black; }
#gameboard tr td:last-child { border-left:2px solid black; }
#gameboard input {
font-size:50px;
width:60px;
padding:3px;
text-transform:uppercase;
text-align:center;
}
</style>
</head>
<body>
<!--
Notice that the default values for each box below is set to '', and empty string.
You will have to set them using data from the $_POST, if you don't the game will
reset after every move. Something like this for every box maybe ...
if( !empty($_POST['r1c0']) ) {
$r1c0 = $_POST['r1c0'];
} else {
$r1c0 = '';
}
-->
<form action="" name='game' method='POST'>
<table cellpadding='0' cellspacing='0' id='gameboard'>
<tr>
<td><input type='text' maxlength='1' name='r1c1' value='<?php echo $r1c1; ?>' /></td>
<td><input type='text' maxlength='1' name='r1c2' value='<?php echo $r1c2; ?>' /></td>
<td><input type='text' maxlength='1' name='r1c3' value='<?php echo $r1c3; ?>' /></td>
</tr>
<tr>
<td><input type='text' maxlength='1' name='r2c1' value='<?php echo $r2c1; ?>' /></td>
<td><input type='text' maxlength='1' name='r2c2' value='<?php echo $r2c2; ?>' /></td>
<td><input type='text' maxlength='1' name='r2c3' value='<?php echo $r2c3; ?>' /></td>
</tr>
<tr>
<td><input type='text' maxlength='1' name='r3c1' value='<?php echo $r3c1; ?>' /></td>
<td><input type='text' maxlength='1' name='r3c2' value='<?php echo $r3c2; ?>' /></td>
<td><input type='text' maxlength='1' name='r3c3' value='<?php echo $r3c3; ?>' /></td>
</tr>
</table>
<?php if($winner != '') { ?>
<h3><?php echo "The winner is ".$winner; ?></h3>
<?php } else { ?>
<input class='button' type='submit' value='Finish Move' />
<input class='button' type="reset" value="Reset Game" />
<?php } ?>
</form>
</body>
</html>
Adding something like this at the top of your code should make it work. Some of your cells are passing lower case values. You should probably put in some other error checking as Javascript can be manipulated.
foreach ($_POST as $key => $val) {
$_POST[$key] = strtoupper($val);
}