I can't update MySQL PHP - php

I don't get any errors but I can't update MySQL PHP. I want to change dropdown status from "sedang diproses" dropdown into "Berjaya or Tidak Berjaya". Also I can't change in the database "sedang diproses" into "Berjaya or Tidak Berjaya"
This is my Code Html
<?php
session_start();
include ('include/myFunction.php');
require('include/connect.php');
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<link href="css/myStyle.css" rel="stylesheet" type="text/css" />
<link href="css/myStyle1.css" rel="stylesheet" type="text/css" />
<!-- Button to open the modal login form -->
<link href="css/myStyle3.css" rel="stylesheet" type="text/css" />
<body>
<div align="right">
<a href="logout.php" ><img src="img/logout.png" width="63" height="46" /></a>
</div>
<div class="header" align="left"><img src="img/gmbar.PNG" width="223" height="126" /><!-- end .header --><!-- end .header --></div>
<div class="content" style="font:Verdana, Geneva, sans-serif">
<div class="content" style="font:Verdana, Geneva, sans-serif">
<div class="topnav" id="myTopnav" style="font-family:Verdana, Geneva, sans-serif">Kembali
</div>
<p> </p>
<?php if($_SESSION['namaadmin'] ==null)
{
header('location:index.php');
}
else
{
?>
<form action="prosesstatus.php" method="post">
<table width="1002" height="87" border="0" align="center" bgcolor="#CCCCFF">
<tr bgcolor="#00CCFF">
<td width="30"><strong>Bil</strong></td>
<td width="298"><strong>Nama</strong></td>
<td width="176"><strong>Nama Kursus</strong></td>
<td width="150"><strong>Tarikh Daftar</strong></td>
<td width="150"><strong>Status</strong></td>
<td width="168"><strong>Kemaskini Status</strong></td>
<td width="131"><strong>Pilihan</strong></td>
</tr>
<?php
$namakursus = '';
if( isset( $_GET['namakursus'])) {
$namakursus = $_GET['namakursus'];
}
$sql1 = "Select * from pemohonan INNER JOIN kursus ON pemohonan.idkursus = kursus.idkursus
INNER JOIN pemohon ON pemohonan.idPemohon = pemohon.idPemohon WHERE kursus.namakursus = '$namakursus' ";
$result1=mysqli_query($dbc,$sql1) or die (mysqli_error());
$i=1;
while($row1 = mysqli_fetch_assoc($result1))
{
?>
<tr>
<td><strong><?php echo $i; ?><input name="idkursus" type="hidden" size="50" value="<?php echo $row1['idkursus'];?>"/><input name="idPemohonan" type="hidden" size="50" value="<?php echo $row1['idPemohonan'];?>"/></strong></td>
<td><strong><?php echo $row1['nama']; ?></strong><input name="id" type="hidden" size="50" value="<?php echo $row1['idPemohon'];?>"/></strong></td>
<td><strong><?php echo $row1['namakursus']; ?></strong></td>
<td><strong><?php echo $row1['tarikhpemohon']; ?></strong></td>
<td><strong><?php echo $row1['status']; ?></strong></td>
<td><select name="status" value="<?php echo $row1['status']; ?>">
<option value="sila pilih">-Sila Pilih-</option>
<option value="Berjaya">Berjaya</option>
<option value="Tidak Berjaya">Tidak Berjaya</option>
</select></td>
<td><input name="btnKemaskini" type="submit" value="Kemaskini" /></td>
</tr>
<?php
$i++;
}
mysqli_close($dbc);
}
?>
</table></form>
<p> </p>
<p> </p>
<div class="footer" style="font-family:Arial, Helvetica, sans-serif">
<?php footertext(); ?>
</div>
</body>
</html>
This is Image
This Is My Image DB
This is my Code Php
<?php
require ('include/connect.php');
$idPemohonan = '';
$idPemohon = '';
$idkursus = '';
if (isset($_GET['idPemohon'],$_GET['idkursus'],$_GET['idPemohonan']))
{
$idPemohon = $_GET['idPemohon'];
$idkursus = $_GET['idkursus'];
$idPemohonan = $_GET['idPemohonan'];
}
$tarikhharini=date('y-m-d');
$status=$_POST['status'];
$sql1 = "UPDATE pemohonan SET idPemohonan ='$idPemohonan' , idPemohon ='$idPemohon' , idkursus ='$idkursus' , tarikhpemohon ='$tarikhharini' , status='$status'
where idPemohonan = '$idPemohonan' and idPemohon = '$idPemohon'";
$result1 = mysqli_query($dbc,$sql1) or die (mysqli_error());
$num_row1 = mysqli_affected_rows($dbc);
echo "<script language=\"JavaScript\">\n";
echo "alert('Status Pemohonan Telah Dihantar!');\n";
echo "window.location='senaraipemohon.php'";
echo "</script>";
mysqli_close($dbc);
?>

Your code is not working because you haven't sent in
<form action="prosesstatus.php" method="post">
Parameters:
$idPemohon = $_GET['idPemohon'];
$idkursus = $_GET['idkursus'];
$idPemohonan =
$_GET['idPemohonan'];
If you want use $_GET link should look like:
prosesstatus.php?idPemohon=value&idkursus=value&idPemohonan=value
Or you should add these parameters in
Input type hidden and change in php to $_POST
I agree with others than you should use MVC for example some kind of framework (Laravel, CodeIgniter)
Or separate as much as possible php and html because your code looks unprofessional.
Your MySQL queries are vulnerable to SQL injection and most likely file
include/connect.php
is not outside public folder which is not good practice to do.

Related

Add to cart button redirecting to another page

Whenever I click on the add to cart button it just goes to another page instead of showing it in the table
<?php
require "includes/dbh.php";
if(isset($_post['add'])){
if(isset($_SESSION['shopping_cart'])){
This is how I get the data in the html
$item_array_id=array_column($_SESSION['shopping_Cart'],'item_id');
if(!in_array($_GET['id'],$item_array_id)){
$count=count($_SESSION['shopping_cart']);
$item_array=array(
'item_id' =>$_GET['id'],
'item_name'=>$_POST['hidden_name'],
'item_price'=>$_POST['hidden_price'],
'item_quantity'=>$_POST['quantity'],
);
$_SESSION['shopping_cart'][$count]=$item_array;
}else{
echo "<script> alert('item already added')</script>";
echo "window.location='displayitems.php'></script>";
}
}else{
$item_array=array(
'item_id' =>$_GET['id'],
'item_name'=>$_POST['hidden_name'],
'item_price'=>$_POST['hidden_price'],
'item_quantity'=>$_POST['quantity'],
);
$_SESSION['shopping_cart'][0]=$item_array;
}
}
if(isset($_get['action'])){
if($_get['action']=='delete'){
foreach($_SESSION['shopping_cart'] as $keys =>$values){
if($values['item_id']==$_get['id'])
{
unset($_SESSION['shopping_cart'][$keys]);
echo '<script>alert("item removed")</script>';
echo '<script>window.location="displayitems.php</script>';
}
}
}
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Page Title</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" media="screen" href="main.css" />
<script src="main.js"></script>
<style>
.product{
border:1px solid
margin:-1px 19px 3px -1px;
padding: 10px;
text-align:center;
bacgkround-color:#efefef;
}
</style>
</head>
<body>
<?php
if(isset($_SESSION['userId'])){
echo '<div id="items" >';
include_once 'includes/dbh.php';
require 'includes/gallery-upload.in.php';
$sql="SELECT * FROM gallery ORDER BY orderitems DESC;";
$stmt=mysqli_stmt_init($conn);
if(!mysqli_stmt_prepare($stmt,$sql)){
echo "sql statement failed in displayitems.php";
}else{
mysqli_stmt_execute($stmt);
$result=mysqli_stmt_get_result($stmt);
while($row=mysqli_fetch_assoc($result))
{
?>
This is my form in adding to cart button
<div class="col-md-3">
<form method="POST" action="displayitems.php?action=add&id=<?php
echo $row["idGallery"]?>">
<div class="product">
<img src=images/<?php echo $row['imgFullNameGallery'] ?>
<br>
<h3><?php echo $row['nameitem']?></h3>
<h3><?php echo $row['price']?></h3>
<input type='number' name='quantity' value="1">
<input type='hidden' name='hidden_name' value="<?php echo
$row['nameitem']?>">
<input type='hidden' name='hidden_price' value="<?php
echo
$row['price']?>">
<button type='submit' name='add'>Add to cart</button>
</div>
</form>
</div>
<?php
}
}
}
?>
<div style="clear":both"></div>
<h3 class="title2">Shopping cart details</h3>
<div class="table table-bordered">
<table>
<tr>
<th width=40%>Item Name</th>
<th width=10%>Quantity</th>
<th width=20%>Price</th>
<th width=15%>Total</th>
<th width=5%>Action</th>
</tr>
<?php
if(!empty($_SESSION['shopping_cart'])){
$total=0;
foreach($_SESSION['shopping_cart']as $keys => $values){
?>
<tr>
<td><?php echo $values['item_name'];?></td>
<td><?php echo $values['item_quantity'];?></td>
<td>$<?php echo $values['item_price'];?></td>
<td><?php echo
number_format($values['item_quantity']*$values['item_price'],2);?></td>
<td>REMOVE</span></td>
</tr>
<?php
$total= $total+($values['item_quantity']*$values['item_price']);
}
?>
<tr>
<td coslpan="3" align="right">total</td>
<td align="right"><?php echo number_format($total,2);?></td>
</td></td>
<?php
}
?>
</table>
</div>
</body>
</html>
It doesn't show in the table and the url is just changing to http://localhost/Soft/displayitems.php?action=add&id=1 and the page is blank
because of you using form and the button type is submit so it's expecting a callback function. Regarding you don't have one and you want to display everything in the same page so you have instead to make the submit functionality to a link instead.
Change :
<button type='submit' name='add'>Add to cart</button>
to
<a type='submit' name='add'>Add to cart</a>
or
<input type="submit" value="Add to cart">
here is a mozilla ref

dynamically added link are not triggering in php

I have added images and the corresponding links to the database and viewed on index page, problem is when i click the images it goes to the present page, it does not open corresponding links related to images. But same is working fine in marquee.
code for adding images and links is
<?php
include_once("../init.php");
validation_check($_SESSION['UID'], SITE_HOME_ADMIN);
$msg='';
if(isset($_POST['save']))
{
$upDir ='../'.VIDEO;
$videourl = $_POST['videourl'];
$insertSql =("INSERT INTO videonews (videourl)
VALUES ('$videourl')");
$insertSql="INSERT INTO ".VIDEONEWS." SET
`adv_url` = '".realStrip($_POST['adv_url'])."'";
$query = mysql_query($insertSql);
$adv_id = mysql_insert_id();
$adv = '';
if($_FILES["adv"]['name']!= ''){
$fileData = pathinfo(basename($_FILES["adv"]["name"]));
$adv = $adv_id . '_adv.' . $fileData ['extension'];
move_uploaded_file($_FILES["adv"]["tmp_name"], $upDir . $adv);
}
$upSql="UPDATE ".VIDEONEWS." SET `adv` = '".$adv."' WHERE id = '$adv_id'";
$query = mysql_query($upSql);
$msg = '<h3>Record Saved</h3>';
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Video News</title>
<link rel="stylesheet" type="text/css" href="headerstyle.css" />
<script type="text/javascript">
</script>
</head>
<body>
07/25/2014
<div class="fixx">
<?php include('header.php');?>
</div>
<div class="tabl">
<table width="700" border="0">
<tr>
<td><form action="news1.php" method="post" enctype="multipart/form-data">
<table width="900" border="1" cellpadding="10">
<tr>
<td colspan="2"><h3> ADD Files To Video News | EDIT </h3></td>
</tr>
<tr>
<td colspan="2"><?php echo $msg;?></td>
</tr>
<tr>
<td><input type="file" name="adv" id="adv" /><input type="text" placeholder="URL" name="adv_url" id="adv_url" size="50" /></td></tr>
</tr>
<tr>
<td>Video Link <input type="text" name="videourl" id="videourl" size="100" /></td></tr>
<tr> <td><input type="submit" name="save" id="save" value="Submit" /></td></tr>
</table>
</form></td>
</tr>
</table>
</div>
</body>
</html>
Retrieving file code is
<?php
validation_check($_SESSION['UID'], SITE_HOME_ADMIN);
$msg='';
$adDir ='./'.VIDEO;
$qr = mysql_query("select * from ".VIDEONEWS) or die('Error in connection');
while($rs = mysql_fetch_array($qr))
{
$adv = '';
if($rs['adv']!='') {
$adv = '<img src="'.$adDir.$rs['adv'].'" style="width:250px; height:150px" > ';
}
$image = $adv;
$msg .='<tr>
<tr>'.$image.'</tr>
</tr>';
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Videonews Lists</title>
<link href="style.css" rel="stylesheet" type="text/css" />
<link rel="stylesheet" type="text/css" href="headerstyle.css" />
</head>
<body>
<div class="tabl">
<table width="100%" border="0" align="center" class="main">
<td>
<table width="95%" border="1" align="center" cellpadding="10">
<?php echo $msg;?>
</table>
</td></tr></table>
</body>
</html>
Retrieving file is included in index.php to show all images in a frame.
Marquee code in index page which is working fine is
<div class="ads-242x90 right">
<strong>VIDEO NEWS</strong>
<marquee direction="up" scrollamount="2" onmouseover="this.stop();" onmouseout="this.start();">
<div align="left" >
<span style="text-transform:uppercase;">
<?
$qryAdv = mysql_query("SELECT * FROM ".VIDEONEWS." WHERE 1");
if(mysql_num_rows($qryAdv) > 0)
{
while($adv = mysql_fetch_assoc($qryAdv))
{
?>
<img src="<?=VIDEO.$adv['adv']?>" width="98%" height="90" alt=""> <br />
<?
}
} else { echo 'NO ADDS FOUND!!!'; }
?>
</marquee>
First thing you should do is to protect yourself from SQL injection, read about it.
I think your problem lies here:
$adv = ''; ///you set $adv equal to empty string
if($rs['adv']!='') { //VVVV here you try to use your empty string
$adv = '<img src="'.$adDir.$rs['adv'].'" style="width:250px; height:150px" > ';
}
I believe it should be
//VVVVVV
$adv = '<img src="'.$adDir.$rs['adv'].'" style="width:250px; height:150px" > ';

Inserting MySQL data into exsisting row

I need to insert a timestamp into table visitors column out after the user clicks on the sign-out button. The sign-out button already deletes rows in the table liveroster but its not updating rows in table visitors at column out with the timestamp.
mysql_query("UPDATE visitors SET out=test WHERE ID=" . $ID);
<?php
/*
Connection Stuff
*/
if (isset($_POST['ID'])) {
$ID = $_POST['ID'];
if (isset($_POST['delete_id'])) {
mysql_query("UPDATE visitors SET out=test WHERE ID=" . $ID);
mysql_query("DELETE FROM liveroster WHERE ID = " . $ID);
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8"/>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<style>
#delete-post {
width: 100%;
margin: auto;
background-color: #999;
}
</style>
<script src="http://code.jquery.com/jquery-1.5.min.js"></script>
</head>
<body>
<div>
<table border cellpadding="3">
<tr>
<td></td>
<td><strong>Time</strong></td>
<td><strong>Name</strong></td>
<td><strong>Teacher</strong></td>
<td><strong>Reason</strong></td>
</tr>
<?php
$data = mysql_query("SELECT * FROM liveroster") or die(mysql_error());
while($info = mysql_fetch_array($data)){ ?>
<tr>
<th>
<form method="post" action="">
<input type="hidden" name="ID" value="<?php echo $info['ID']; ?>" />
<input type="submit" name="delete_id" value="Sign-Out" />
</form>
</th>
<td>
<?php echo $info['timestamp']; ?>
</td>
<td>
<?php echo $info['name']; ?>
</td>
<td>
<?php echo $info['teacher']; ?>
</td>
<td>
<?php echo $info['reason']; ?>
</td>
</tr>
<?php } ?>
</table>
</div>
</body>
</html>
Use PDO:
<?php
$dsn = "mysql:host=localhost;port=$port;dbname=$dbname";
$options = array(
PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8',
);
$dbh = new PDO($dsn, $username, $password, $options);
/*
Connection Stuff
*/
if (isset($_POST['ID'])) {
$ID = $_POST['ID'];
if (isset($_POST['delete_id'])) {
/* Update */
$count = $dbh->exec("UPDATE `visitors` SET `out` = 'test' WHERE `ID` = '" . $ID ."'");
/* Delete */
$count = $dbh->exec("DELETE FROM `liveroster` WHERE `ID` = '" . $ID ."'");
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8"/>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<style>
#delete-post {
width: 100%;
margin: auto;
background-color: #999;
}
</style>
<script src="http://code.jquery.com/jquery-1.5.min.js"></script>
</head>
<body>
<div>
<table border cellpadding="3">
<tr>
<td></td>
<td><strong>Time</strong></td>
<td><strong>Name</strong></td>
<td><strong>Teacher</strong></td>
<td><strong>Reason</strong></td>
</tr>
<?php
$sql = "SELECT * FROM liveroster";
$sth = $dbh->prepare($sql);
$sth->execute();
$rows = $sth->fetchAll();
foreach($rows as $value){ ?>
<tr>
<th>
<form method="post" action="">
<input type="hidden" name="ID" value="<?php echo $value['ID']; ?>" />
<input type="submit" name="delete_id" value="Sign-Out" />
</form>
</th>
<td>
<?php echo $value['timestamp']; ?>
</td>
<td>
<?php echo $value['name']; ?>
</td>
<td>
<?php echo $value['teacher']; ?>
</td>
<td>
<?php echo $value['reason']; ?>
</td>
</tr>
<?php } ?>
</table>
</div>
</body>
</html>
You could create a column and update it using the "NOW()" function every time you click submit.
UPDATE visitors
SET out = test, getdate = NOW()
WHERE ID = $ID

Finding syntax error in code [PHP/HTML]

I have some HTML/PHP code in Dreamweaver and for the life of me I cannot figure out the cause of this error. The error reads, "There is a syntax error on line 318. Code hinting may not work until you fix this error." Could someone help? And yes, I know I have terrible commenting practice and variable nomenclature. The code can also be found here
<?php
require $_SERVER['DOCUMENT_ROOT'].'/resources/feeds.php';
require $_SERVER['DOCUMENT_ROOT'].'/resources/mysql.php';
session_start();
if(empty($_SESSION['username']) || $_SESSION['login'] != 'true'){ header("location:/"); }
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!--
Design by Free CSS Templates
http://www.freecsstemplates.org
Released for free under a Creative Commons Attribution 2.5 License
Name : Vegetables
Description: A two-column, fixed-width design with dark color scheme.
Version : 1.0
Released : 20110416
-->
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<link rel="icon" type="/image/png" href="/resources/favicon.png">
<meta name="keywords" content="" />
<meta name="description" content="" />
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>My Website • Edit Information</title>
<link href="/style.css" rel="stylesheet" type="text/css" media="screen" />
</head>
<body>
<div id="header">
<div id="logo">
<h1>My Website</h1>
This is the best website ever
<p> </p>
</div>
</div>
<!-- end #header -->
<div id="wrapper">
<div id="menu">
<ul>
<li class="current_page_item">Home</li>
<li>Events</li>
<li>Forums</li>
<li>About</li>
<li>Minutes</li>
<li>Documents</li>
<li>Contact Us</li>
</ul>
</div>
<!-- end #menu -->
</div>
<div id="page">
<div id="content">
<div class="post">
<h2 class="title">Edit Information</h2>
<div style="clear: both;"><form action="/admin"><input type="submit" value='Back'/></form></div>
<div style="clear: both;"></div>
<div class="entry">
<SCRIPT language="javascript">
function add() {
x++;
var foo = document.getElementById('my_div');
foo.innerHTML = foo.innerHTML +"<input type='text' name='tg"+x+"' placeholder='name'><br />";
}
function addch() {
y++;
var foo = document.getElementById('my_other_div');
foo.innerHTML = foo.innerHTML +"<input type='text' name='ch"+y+"' placeholder='name'><br />";
}
function addws() {
z++;
var foo = document.getElementById('my_other_other_div');
foo.innerHTML = foo.innerHTML +"<input type='text' name='ws"+z+"' placeholder='workshop name and leaders' style='width: 98%;'><br />";
}
function detect(form) {
if(form.checked) {
window.backUpHtml = document.getElementById('con_div').innerHTML;
document.getElementById('con_div').innerHTML = '';
} else {
document.getElementById('con_div').innerHTML = window.backUpHtml;
window.backUpHtml = '';
}
}
</SCRIPT>
<form name="form1" method="post" action="./"><font color="#FFFFFF">
<table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#00000" style="max-width: 560px;">
<tr>
<td width="10%">Name</td>
<td width="90%"><?php echo "<input name='name' type='text' value='".stripslashes($_POST['name'])."' required='required'/>"; ?><input type="checkbox" onclick="detect(this)" name="isyac" id="isyac" value="yes" <?php if(isset($_POST['isyac'])) { echo "checked='checked'";} ?> /><label for="isyac">YAC Meeting</label></td>
</tr>
<tr>
<td width="10%" style="vertical-align:top;">Description</td>
<td width="90%"><?php echo '<textarea name="desc" rows="5" cols="60" style="resize: vertical;" required="required">'.stripslashes($_POST["desc"]).'</textarea>'; ?></td>
</tr>
<tbody id="con_div">
<!-- START OF CON DIV -->
<tr>
<td width="10%" style="vertical-align:top;">Touchgroup Leaders</td>
<td width="90%">
<?php
$blah = 1;
while(isset($_POST['tg'.$blah])) {
echo '<input type="text" name="tg'.$blah.'" value="'.stripslashes($_POST["tg".$blah]).'" /><br />';
$blah++;
}
$hoo = $blah - 1;
echo "<script language='javascript'> var x = ".$hoo."; </script>";
?>
<div id="my_div"></div>
<input type="button" value="Add" onClick="add()">
</td>
</tr>
<tr>
<td width="10%" style="vertical-align:top;">Chaplains</td>
<td width="90%">
<?php
$blah = 1;
while(isset($_POST['ch'.$blah])) {
echo '<input type="text" name="ch'.$blah.'" value="'.stripslashes($_POST["ch".$blah]).'" /><br />';
$blah++;
}
$hoo = $blah - 1;
echo "<script language='javascript'> var y = ".$hoo."; </script>";
?>
<div id="my_other_div"></div>
<input type="button" value="Add" onClick="addch()">
</td>
</tr>
<tr>
<td width="10%" style="vertical-align:top;">Workshops</td>
<td width="90%">
<?php
$blah = 1;
while(isset($_POST['ws'.$blah])) {
echo '<input type="text" name="ws'.$blah.'" value="'.stripslashes($_POST["ws".$blah]).'" style="width: 98%;"/><br />';
$blah++;
}
$hoo = $blah - 1;
echo "<script language='javascript'> var z = ".$hoo."; </script>";
?>
<div id="my_other_other_div"></div>
<input type="button" value="Add" onClick="addws()">
</td>
</tr>
</tbody>
<!-- END OF CON DIV -->
<tr>
<td width="10%" style="vertical-align:top;">Registration Links</td>
<td width="90%">
<?php echo '<input type="text" name="YouthLink" value="'.stripslashes($_POST['YouthLink']).'"/> Youth Link<br />
<input type="text" name="AdultLink" value="'.stripslashes($_POST['AdultLink']).'"/> Adult Link'; ?>
</td>
</tr>
<tr>
<td width="10%" style="vertical-align:top;">Start Date</td>
<td width="90%">
<select name='startmonth'>
<?php $idk = array("January","February","March","April","May","June","July","August","September","October","November","December");
foreach ($idk as $bob):
if($bob = $_POST['startmonth']) {
echo '<option value="'.$bob.'" selected="selected">'.$bob.'</option>';
} else {
echo '<option value="'.$bob.'">'.$bob.'</option>';
}
endforeach;
?>
</select>
<select name="startday">
<?php
$x = 1;
while($x <= 31) {
if((int)$_POST['startday'] == $x) {
echo "<option value='".$x."' selected='selected'>".$x."</option>";
} else {
echo "<option value='".$x."'>".$x."</option>";
}
$x++;
}
?>
</select>
<select name="startyear">
<?php $date = getdate();
for($x = 0;$x < 3;$x++) {
$y = (int)$date['year']+$x;
if($y == $_POST['startyear']) {
echo "<option value='".$y."' selected='selected'>".$y."</option>";
} else {
echo "<option value='".$y."'>".$y."</option>";
}
}
?>
</select>
</td>
</tr>
<tr>
<td width="10%" style="vertical-align:top;">End Date</td>
<td width="90%">
<select name='endmonth'>
<?php $idk = array("January","February","March","April","May","June","July","August","September","October","November","December");
foreach ($idk as $bob):
if($bob = $_POST['endmonth']) {
echo '<option value="'.$bob.'" selected="selected">'.$bob.'</option>';
} else {
echo '<option value="'.$bob.'">'.$bob.'</option>';
}
endforeach;
?>
</select>
<select name="endday">
<?php
$x = 1;
while($x <= 31) {
if((int)$_POST['endday'] < $x) {
echo "<option value='".$x."'>".$x."</option>";
} else if((int)$_POST['endday'] == $x) {
echo "<option value='".$x."' selected='selected'>".$x."</option>";
} else if((int)$_POST['endday'] > $x) {
echo "<option value='".$x."'>".$x."</option>";
}
$x++;
}
?>
</select>
<select name="endyear">
<?php $date = getdate();
for($x = 0;$x < 3;$x++) {
$y = (int)$date['year']+$x;
if($y == $_POST['endyear']) {
echo "<option value='".$y."' selected='selected'>".$y."</option>";
} else {
echo "<option value='".$y."'>".$y."</option>";
}
}
?>
</select>
</td>
</tr>
<tr>
<td width="10%" style="vertical-align:top;">Location</td>
<td width="90%">
<?php echo '<input type="text" name="location" value="'.stripslashes($_POST['location']).'" required="required"/>'; ?>
</td>
</tr>
<tr>
<td width="90%"></td>
<td width="10%">
<input type="hidden" name="blah" value="blah"/>
<input type="submit" name="woohoo" value="Save" align="right"/>
</td>
</table>
</form>
<?php if(isset($_POST['isyac'])) {
echo "<script language='javascript'>window.backUpHtml = document.getElementById('con_div').innerHTML;
document.getElementById('con_div').innerHTML = '';</script>"; ?>
}
</div>
</div>
<div style="clear: both;"> </div>
</div>
<!-- end #content -->
<div id="sidebar">
<?php include($_SERVER['DOCUMENT_ROOT'].'/resources/side.php'); ?>
</div>
<!-- end #sidebar -->
<div style="clear: both;"> </div>
</div>
<!-- end #page -->
<div id="footer-menu">
<ul>
<li class="current_page_item">Home</li>
<li>Events</li>
<li>Forums</li>
<li>About</li>
<li>Minutes</li>
<li>Documents</li>
<li>Contact Us</li>
</ul>
</div>
<div id="footer">
<p>Copyright © <?php $date = getdate(); echo $date['year']; ?> My Website. All rights reserved.</p>
</div>
<!-- end #footer -->
</body>
</html>
Your problem comes from this bit of code:
<?php if(isset($_POST['isyac'])) {
echo "<script language='javascript'>window.backUpHtml = document.getElementById('con_div').innerHTML;
document.getElementById('con_div').innerHTML = '';</script>"; ?>
}
the closing brace } needs to be inside the php tags (before the ?>)
I just glanced over your code and I would say this is probably it:
</form>
<?php if(isset($_POST['isyac'])) {
echo "<script language='javascript'>window.backUpHtml = document.getElementById('con_div').innerHTML;
document.getElementById('con_div').innerHTML = '';</script>"; ?>
}
</div>
Your end curly should be inside the ?>
</form>
<?php if(isset($_POST['isyac'])) {
echo "<script language='javascript'>window.backUpHtml = document.getElementById('con_div').innerHTML;
document.getElementById('con_div').innerHTML = '';</script>";
}
?>
</div>

div coming down while refreshing the page

I want to make a page for android which is refreshing in every sec . All things are working well but the problem i am facing on this page when you click on the reserve button then entire div come down and leave a small space above but after next refresh it becomes ok . I have tried without div but its not working Here is the code
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<?php
Header('Refresh:2;url=http://medical.gofreeserve.com/and/checkm.php');
?>
<head>
<style type="text/css">
<!--
.style2 {color: #FFFFFF}
-->
</style>
</head>
<body bgcolor="#000000">
<?php
include("../common/connection.php");
?>
<?php
if(isset($_GET['reserve']))
{
echo $sql = "UPDATE newsevents SET booking ='1' WHERE news_id='$_GET[val]'";
$query = mysql_query($sql) or die(mysql_error());
}
$new_query=mysql_query("select * from newsevents where booking=0") or die(mysql_error());
while($row=mysql_fetch_array($new_query))
{
$id=$row['news_id'];
$date=$row['date'];
$news_text=$row['text'];
?>
<div style="border-bottom:2px solid #FFFFFF" >
<form name="fm1" action="checkm.php" method="get">
<table width="95%">
<tr>
<td width="60%" height="50" ><span class="style2"><?php echo $date ?></span></td>
<td width="40%"><span class="style2"><?php echo $news_text ?></span></td>
<td width="40%"><span class="style2"><input type="hidden" name="val" value="<?php echo $id?>" / ></span></td>
<td width="30%"><input type="submit" name="reserve" id="reserve" value="reserve" /></td>
</tr>
</table>
</form>
</div>
<?php }?>
</body>
</html>
You're echoing the SQL statement when running the SQL query, which is pushing down the div. Just use the following instead:
if(isset($_GET['reserve']))
{
$sql = "UPDATE newsevents SET booking ='1' WHERE news_id='".$_GET['val']."'";
$query = mysql_query($sql) or die(mysql_error());
}

Categories