Mysql query Issue

Ye' old general discussion board. Basically, for everything that isn't covered elsewhere. Come here to shoot the breeze, shoot your mouth off, or whatever suits your fancy.
This forum is not for asking programming related questions.

Moderator: General Moderators

Post Reply
pascale
Forum Newbie
Posts: 10
Joined: Wed May 16, 2012 1:40 am

Mysql query Issue

Post by pascale »

Code: Select all

<?php
session_start();
include("configdb.php");
if(!session_is_registered(username)){
header("location:index.php");
}
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Projects</title>
<link href="style.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<link href="modalPopLite.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="modalPopLite.min.js"></script>
<script type="text/javascript">
$(function () {
   $('#popup-wrapper').modalPopLite({ openButton: '#clicker', closeButton: '#close-btn' });
});
function validateForm()
{
var x=document.forms["f1"]["project"].value;
  if (x==null || x=="")
  {
  alert("all fileds are required");
  return false;
}
}

function un_check(){
for (var i = 0; i < document.frmactive.elements.length; i++) {
var e = document.frmactive.elements[i];
if ((e.name != 'allbox') && (e.type == 'checkbox')) {
e.checked = document.frmactive.allbox.checked;
}
}
}
function Confirm(form){
alert("Project has been activated!"); 
form.submit();
}
function unConfirm(form){
alert("Project has been Deactivated!"); 
form.submit();
}
</script>
</head>

<body>
<div id="costDiv">
<div id="divErc"></div>
<div id="costBack">

<?php

if(isset($_POST['checkbox'])){$checkbox = $_POST['checkbox'];
if(isset($_POST['activate'])?$activate = $_POST["activate"]:$deactivate = $_POST["deactivate"])

$id = "('" . implode( "','", $checkbox ) . "');" ;
$sql="UPDATE projects SET p_isActive = '".(isset($activate)?'1':'0')."' WHERE p_id IN $id";
$result = mysql_query($sql) or die(mysql_error());

}
if (isset($_GET['pageno'])) {
   $pageno = $_GET['pageno'];
} else {
   $pageno = 1;
}
$sql="SELECT COUNT(*) FROM projects ";
$result=mysql_query($sql);
   $query_data = mysql_fetch_row($result);
   $numrows = $query_data[0];
   
   $rows_per_page = 8;
$lastpage      = ceil($numrows/$rows_per_page);
$pageno = (int)$pageno;
if ($pageno > $lastpage) {
   $pageno = $lastpage;
} 
if ($pageno < 1) {
   $pageno = 1;
}
$limit = 'LIMIT ' .($pageno - 1) * $rows_per_page .',' .$rows_per_page;
$sql="SELECT * FROM projects $limit";
$result=mysql_query($sql);
$count=mysql_num_rows($result);
?>
<?php include("hor_menu.php"); ?>
<div id="container"><br/><div id="clicker" style="cursor:pointer; width:120px;margin-left:15px;color:#20358c; font-weight:bold"">Add New Project</div>
<div id="popup-wrapper" style="background-color: #ccc; height:150px">
<form action="addnewproject.php" method="post" name="f1" onSubmit="return validateForm();">
<table>
<tr>
<td><label><h4>Project :</h4></label></td>
<td><input type="text" name="new_project" id="project" class="text-input-pop" /></td>
<tr>
<td><label><h4>Country :</h4></label></td>
<td><select name="country" id="country" style="width:190px ; height:31px"> 
    <option value="Lebanon">Lebanon</option>
    <option value="Syria">Syria</option>
    <option value="UAE">UAE</option>
</select> </td>
</tr>
</tr>
<tr>
<td></td>
<td><input type="submit" value="Submit" class="styled-button-4" style="margin-left:130px;"/></td>
</tr>
</table>
</form> 
<a id="close-btn" href="#">Close</a></div><table border="0" cellpadding="5" cellspacing="1" align="center" style="text-align:center">



<form name="frmactive" method="post" action="">

<table width="350" border="0" cellspacing="1" cellpadding="5" align="center" style="margin-left:150px ; margin-right:auto ; margin-top:20px ; margin-bottom:auto ; position:absolute ; width:400px">

<tr>
<td align="center" ><input type="checkbox" name="allbox" onclick="un_check(this);" title="Select or Deselct ALL" style="background-color:#ccc;"/></td>

<td align="left"><strong>Project</strong></td>
<td align="left"><strong>Country</strong></td>
<td align="left"><strong>Active</strong></td>

</tr>

<?php
while($rows=mysql_fetch_array($result)){
?>
<tr>
<td align="center"><input name="checkbox[]" type="checkbox" id="checkbox[]" value="<?php echo $rows['p_id']; ?>"/></td>
<td><?php echo $rows['p_name']; ?></td>
<td><?php echo $rows['p_country']; ?></td>
<td><?php if ($rows['p_isActive'] == '1'){ echo'Active';} else{ echo 'Inactive';} ?></td>

</tr>
<?php
}
?>
<tr>
<td colspan="5"><input name="activate" type="submit" id="activate" value="Activate" onClick="Confirm(this.form)" />
<input name="deactivate" type="submit" id="deactivate" value="Deactivate" onClick="unConfirm(this.form)"/></td>
</tr>
</table>
<table align="right" style="margin-top:336px ; margin-bottom:auto ; margin-right:20px">
<tr>
<td>
<?php

if ($pageno == 1) {
   echo "FIRST PREV ";
} else {
   echo "<a href='{$_SERVER['PHP_SELF']}?pageno=1'>FIRST</a> ";
   $prevpage = $pageno-1;
   echo " <a href='{$_SERVER['PHP_SELF']}?pageno=$prevpage'>PREV</a> ";
} // if
echo " ( Page $pageno of $lastpage ) ";
if ($pageno == $lastpage) {
   echo " NEXT LAST ";
} else {
   $nextpage = $pageno+1;
   echo " <a href='{$_SERVER['PHP_SELF']}?pageno=$nextpage'>NEXT</a> ";
   echo " <a href='{$_SERVER['PHP_SELF']}?pageno=$lastpage'>LAST</a> ";
} 

?>
</td>
</tr>
</table>
</form>
</body>
</html>


[text]i have this code.when i check a checkbox project will be either activated or deactivated according to bottom.however this code works perfectly on all browsers except google chrome and safari.can anyone help please.it keeps giving that have an error in my sql syntax espeaciall after the where clause in the update query.thank you[/text]
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: Mysql query Issue

Post by califdon »

Your error message should direct you to the problem: it is in the WHERE clause, where you use "IN" keyword, which requires parentheses. Reference: http://www.tutorialspoint.com/mysql/mysql-in-clause.htm
Post Reply