Page 1 of 1
Deletion process ERROR
Posted: Tue Feb 06, 2007 9:08 pm
by victhour
feyd | Please use Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
hello forum,
bellow are the codes that i currently hang'up with... i cant figure it out what went wrong. at the very bottom of this post, is an error('Its a notice actually') message of the function delete.php
hope anyone could help me..
tanx in advanced..
Vic
[syntax="javascript"]function goDelete(){
var recslen = document.forms[0].length;
var checkboxes = "";
for(i = 1; i < recslen; i++){
if(document.forms[0].elements[i].checked==true)
checkboxes+= " " + document.forms[0].elements[i].name
}
if(checkboxes.length > 0){
var con=confirm("Are you sure you want to delete");
if(con){
document.forms[0].action="delete.php?recsno="+checkboxes
document.forms[0].submit()
}
}else{
alert("No record is selected.")
}
}
[/syntax]
Code: Select all
<?php
require('config.php');
conn_db($host, $user, $pass, 'superdb');
$recsno=$_GET["recsno"];
$data=trim($recsno);
$ex=explode(" ",$data);
$size=sizeof($ex);
for($i=0;$i<$size;$i++){
$id=trim($ex[$i]);
$query = 'DELETE news_mas, news_dtl FROM news_mas, news_dtl WHERE news_mas.mas_id = '.$id.' AND news_dtl.dtl_id = '.$id;
$result = mysql_query($query) or die('Problem: '.mysql_error());
}
header('Location: '.$_SERVER['HTTP_REFERER']);
?>
Notice: Undefined index: recsno in C:\Web Root\Superbalita\script\modules\delete.php on line 5
Problem: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'AND news_dtl.dtl_id =' at line 1
feyd | Please use Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Posted: Tue Feb 06, 2007 9:43 pm
by feyd
Your Javascript didn't work it would appear, which resulted in blank data being given to your loop.
Posted: Tue Feb 06, 2007 10:21 pm
by victhour
i dont know much of javascript

would you kind to correct my js.. please.
by the way here's the whole structure of the code
Code: Select all
<?php
require("config.php");
include("modlib.php");
conn_db($host, $user, $pass, 'superdb');
$location = $section = NULL;
if(isset($_GET["mnuLocation"]) && is_numeric($_GET["mnuLocation"])){
$location = $_GET["mnuLocation"];
}
if(isset($_GET["mnuSection"]) && is_numeric($_GET["mnuSection"])){
$section = $_GET["mnuSection"];
}
?>
<script language="JavaScript">
function goSubmit(){
var formObject = document.forms['frmQue'];
formObject.submit();
}
</script>
<html>
<head>
<link href="../balita.css" rel="stylesheet" type="text/css">
<script type="text/javascript" src="jscript.js"><!-- //--></script>
<style type="text/css">
<!--
body {
background: #CCCC99;
margin: 0px;
}
-->
</style>
</head>
<body>
<form name="frmQue" method="get">
<table width="450" border="0" cellpadding="0" cellspacing="0" style="border-bottom: solid 4px #999966;">
<tr bgcolor="#CCCCFF">
<td height="24" colspan="3" bgcolor=""><table width="100%" border="0" cellpadding="0" cellspacing="0" style="border-bottom: solid 4px #999966;">
<tr>
<td width="38" height="20" class="capIt">Filter</td>
<td width="100"><select name="mnuLocation" id="mnuLocation" class="selval2">
<option value="null"></option>
<option value="1" <?php if($location == 1) echo " selected"; ?>>Cag. de Oro</option>
<option value="2" <?php if($location == 2) echo " selected"; ?>>Cebu</option>
<option value="3" <?php if($location == 3) echo " selected"; ?>>Davao</option>
<option value="4" <?php if($location == 4) echo " selected"; ?>>Gen. Santos</option>
</select></td>
<td width="95"><select name="mnuSection" id="mnuSection" class="selval2">
<option value="null"></option>
<option value="1" <?php if($section == 1) echo " selected"; ?>>Balita</option>
<option value="2" <?php if($section == 2) echo " selected"; ?>>Opinyon</option>
<option value="3" <?php if($section == 3) echo " selected"; ?>>Kalingawan</option>
<option value="4" <?php if($section == 4) echo " selected"; ?>>Sports</option>
</select></td>
<td width="43" class="capIt">Search</td>
<td width="89"><input name="cmdSearch" type="image" src="rel_script/action_go.gif" width="16" height="16" border="0" onClick="goSubmit();" style="margin-top: 3px;"></td>
<td width="23" align="center"><input name="checkAll" type="checkbox" id="checkAll" onClick="selectAll();" value="ON"></td>
<td width="62" align="center"><input name="cmdDelete" type="submit" class="cmd" id="cmdDelete" onClick="goDelete();" value="Delete"></td>
</tr>
</table></td>
</tr>
<?php
if(!is_null($location) && is_numeric($location) && !is_null($section) && is_numeric($section)){
$query = 'SELECT news_mas.mas_id, news_mas.location, news_mas.section, news_mas.lock, news_dtl.date, news_dtl.title FROM news_mas, news_dtl
WHERE news_mas.mas_id = news_dtl.dtl_id AND news_mas.location = '.$location.' AND news_mas.section = '.$section.' ORDER BY news_dtl.date';
$result = mysql_query($query) or die('Error: '.mysql_error());
if(!mysql_num_rows($result) > 0){
echo '<script type="text/javascript">alert("No Articles Found!..")</script>';
exit;
}
session_start();
while($ctr = mysql_fetch_array($result)){ //Begin While
$section = $ctr['section'];
$location = $ctr['location'];
switch($section){ // Begin Switch
case 1: $sec = 'Balita'; break;
case 2: $sec = 'Opinyon'; break;
case 3: $sec = 'Kalingawan'; break;
case 4: $sec = 'Sports'; break;
} // End Switch
switch($location){ // Begin Switch
case 1: $loc = 'CDO'; break;
case 2: $loc = 'CBU'; break;
case 3: $loc = 'DVO'; break;
case 4: $loc = 'GEN'; break;
} // End Switch
$_SESSION['article_id'] = $ctr['mas_id'];
if(is_null($ctr['lock']) || $ctr['lock'] == 0){ // ?>
<tr>
<td width="373" height="20" class="trbdr"><?php echo $loc.' - '.$sec.': '; ?><a href="rel_script/view_article.php?article_id=<?= $ctr['mas_id']; ?>" target="_blank">
<?= filval(charslen(48, $ctr['title'])); ?>
</a> </td>
<td width="35" class="trbdr"><a href="mod_update.php?article_id=<?= $ctr['mas_id']; ?>">Edit</a></td>
<td width="42" class="trbdr">
<input name="<?= $ctr['mas_id']; ?>" type="checkbox">
</td>
</tr>
<?php }elseif($ctr['lock'] == 1){ ?>
<tr>
<td height="20" class="trbdr"><?php echo $loc.' - '.$sec.': '.filval(charslen(48, $ctr['title'])); ?> </a> </td>
<td width="35" class="trbdr">Edit</td>
<td width="42" class="trbdr"><input name="" type="checkbox" disabled="disabled"></td>
</tr>
<?php }
} // end while
free_mem($result);
}
?>
</table>
</form>
</body>
</html>
Javascript(jscript.js)
Code: Select all
function goDelete(){
var recslen = document.forms[0].length;
var checkboxes = "";
for(i = 1; i < recslen; i++){
if(document.forms[0].elements[i].checked==true)
checkboxes+= " " + document.forms[0].elements[i].name
}
if(checkboxes.length > 0){
var con=confirm("Are you sure you want to delete");
if(con){
document.forms[0].action="delete.php?recsno="+checkboxes
document.forms[0].submit()
}
}else{
alert("No record is selected.")
}
}
function selectAll(){
// var formname=document.getElementById(formname);
var recslen = document.forms[0].length;
if(document.forms[0].checkAll.checked==true){
for(i=1;i<recslen;i++) {
document.forms[0].elements[i].checked=true;
}
}else{
for(i=1;i<recslen;i++)
document.forms[0].elements[i].checked=false;
}
}
delete.php
Code: Select all
<?php
require('config.php');
conn_db($host, $user, $pass, 'superdb');
$recsno=$_GET["recsno"];
$data=trim($recsno);
$ex=explode(" ",$data);
$size=sizeof($ex);
for($i=0;$i<$size;$i++){
$id=trim($ex[$i]);
$query = 'DELETE news_mas, news_dtl FROM news_mas, news_dtl WHERE news_mas.mas_id = '.$id.' AND news_dtl.dtl_id = '.$id;
$result = mysql_query($query) or die('Problem: '.mysql_error());
}
header('Location: '.$_SERVER['HTTP_REFERER']);
?>
Posted: Tue Feb 06, 2007 10:50 pm
by superdezign
I'm not too keen on fixing your code for you, but looking at your first post, I think the first step to solving you problem would be to first check if $_GET['recsno'] is set before attempting to use it, so your javascript actually has a chance to run and add the recsno to the URL.
Posted: Tue Feb 06, 2007 11:12 pm
by RobertGonzalez
You should also look at a different method of redirecting as the HTTP REFERER server var is highly unreliable.
Posted: Wed Feb 07, 2007 12:30 am
by victhour
i guess i can do the checking of the value $_GET["recsno"]. but my prob is how would i make my JS work since im not to knowledgeble bout javascript. is their any other way doing this?

Posted: Wed Feb 07, 2007 12:35 am
by feyd
I don't see a reason Javascript is required.
And please use the correct highlighting tags for Javascript.
Posted: Wed Feb 07, 2007 12:53 am
by victhour
sorry bout the highlights...
i wanted my code to list all the records according to location and section that can be deleted('via checkbox') or updated('links'). im really having trouble with my project now.

this is supposed to be a simple CMS.
Posted: Wed Feb 07, 2007 1:01 am
by feyd
The point is, what you're wishing to do can simply be sent to PHP in the standard fashion -- no Javascript required. PHP can, and probably should, ask them to confirm that the records selected should be deleted instead of a "confirm" box.
Posted: Wed Feb 07, 2007 3:37 am
by victhour
i think the delete function is working... but whit the added code:
Code: Select all
if(isset($_GET['cmdSearch'])){
if(isset($_GET["mnuLocation"]) && is_numeric($_GET["mnuLocation"])){
$location = $_GET["mnuLocation"];
}
if(isset($_GET["mnuSection"]) && is_numeric($_GET["mnuSection"])){
$section = $_GET["mnuSection"];
}
}
it will not give me some query.. what seems could be the problem? bellow is the complete code.
Code: Select all
<?php
require("config.php");
include("modlib.php");
conn_db($host, $user, $pass, 'superdb');
$location = $section = NULL;
if(isset($_GET['cmdSearch'])){
if(isset($_GET["mnuLocation"]) && is_numeric($_GET["mnuLocation"])){
$location = $_GET["mnuLocation"];
}
if(isset($_GET["mnuSection"]) && is_numeric($_GET["mnuSection"])){
$section = $_GET["mnuSection"];
}
}
if(isset($_GET['cmdDelete'])){
if(isset($_GET['del'])){
foreach($_GET['del'] as $del_id){
$seek = 'SELECT news_mas.lock FROM news_mas WHERE news_mas.mas_id = '.$del_id;
$que = mysql_query($seek) or die('Problem:'.mysql_error());
$pos = mysql_fetch_array($que) or die('Problem:'.mysql_error());
if(is_null($pos['lock']) || $pos['lock'] == 0){
$query = 'DELETE news_mas, news_dtl FROM news_mas, news_dtl WHERE news_mas.mas_id = '.$del_id.' AND news_dtl.dtl_id = '.$del_id;
$result = mysql_query($query) or die('Problem: '.mysql_error());
}
}
}
}
?>
<html>
<head>
<link href="../balita.css" rel="stylesheet" type="text/css">
<script type="text/javascript" src="jscript.js"><!-- //--></script>
<style type="text/css">
<!--
body {
background: #CCCC99;
margin: 0px;
}
-->
</style>
</head>
<body>
<form name="frmQue" method="get">
<table width="450" border="0" cellpadding="0" cellspacing="0" style="border-bottom: solid 4px #999966;">
<tr bgcolor="#CCCCFF">
<td height="24" colspan="3" bgcolor=""><table width="100%" border="0" cellpadding="0" cellspacing="0" style="border-bottom: solid 4px #999966;">
<tr>
<td width="38" height="20" class="capIt">Filter</td>
<td width="100"><select name="mnuLocation" id="mnuLocation" class="selval2">
<option value="null"></option>
<option value="1" <?php if($location == 1) echo " selected"; ?>>Cag. de Oro</option>
<option value="2" <?php if($location == 2) echo " selected"; ?>>Cebu</option>
<option value="3" <?php if($location == 3) echo " selected"; ?>>Davao</option>
<option value="4" <?php if($location == 4) echo " selected"; ?>>Gen. Santos</option>
</select></td>
<td width="95"><select name="mnuSection" id="mnuSection" class="selval2">
<option value="null"></option>
<option value="1" <?php if($section == 1) echo " selected"; ?>>Balita</option>
<option value="2" <?php if($section == 2) echo " selected"; ?>>Opinyon</option>
<option value="3" <?php if($section == 3) echo " selected"; ?>>Kalingawan</option>
<option value="4" <?php if($section == 4) echo " selected"; ?>>Sports</option>
</select></td>
<td width="43" class="capIt">Search</td>
<td width="89"><input name="cmdSearch" type="image" src="rel_script/action_go.gif" width="16" height="16" border="0" style="margin-top: 3px;"></td>
<td width="23" align="center"><input name="checkAll" type="checkbox" id="checkAll" onClick="selectAll();" value="ON"></td>
<td width="62" align="center"><input name="cmdDelete" type="submit" class="cmd" id="cmdDelete" value="Delete"></td>
</tr>
</table></td>
</tr>
<?php
if(!is_null($location) && is_numeric($location) && !is_null($section) && is_numeric($section)){
$query = 'SELECT news_mas.mas_id, news_mas.location, news_mas.section, news_mas.lock, news_dtl.date, news_dtl.title FROM news_mas, news_dtl
WHERE news_mas.mas_id = news_dtl.dtl_id AND news_mas.location = '.$location.' AND news_mas.section = '.$section.' ORDER BY news_dtl.date';
$result = mysql_query($query) or die('Error: '.mysql_error());
if(!mysql_num_rows($result) > 0){
echo '<script type="text/javascript">alert("No Articles Found!..")</script>';
exit;
}
session_start();
while($ctr = mysql_fetch_array($result)){ //Begin While
$section = $ctr['section'];
$location = $ctr['location'];
switch($section){ // Begin Switch
case 1: $sec = 'Balita'; break;
case 2: $sec = 'Opinyon'; break;
case 3: $sec = 'Kalingawan'; break;
case 4: $sec = 'Sports'; break;
} // End Switch
switch($location){ // Begin Switch
case 1: $loc = 'CDO'; break;
case 2: $loc = 'CBU'; break;
case 3: $loc = 'DVO'; break;
case 4: $loc = 'GEN'; break;
} // End Switch
$_SESSION['article_id'] = $ctr['mas_id'];
if(is_null($ctr['lock']) || $ctr['lock'] == 0){ // ?>
<tr>
<td width="373" height="20" class="trbdr"><?php echo $loc.' - '.$sec.': '; ?><a href="rel_script/view_article.php?article_id=<?= $ctr['mas_id']; ?>" target="_blank">
<?= filval(charslen(48, $ctr['title'])); ?>
</a> </td>
<td width="35" class="trbdr"><a href="mod_update.php?article_id=<?= $ctr['mas_id']; ?>">Edit</a></td>
<td width="42" class="trbdr"><input type="checkbox" name="del[]" value="<?= $ctr['mas_id']; ?>">
</td>
</tr>
<?php }elseif($ctr['lock'] == 1){ ?>
<tr>
<td height="20" class="trbdr"><?php echo $loc.' - '.$sec.': '.filval(charslen(48, $ctr['title'])); ?> </a> </td>
<td width="35" class="trbdr">Edit</td>
<td width="42" class="trbdr"><input name="" type="checkbox" disabled="disabled"></td>
</tr>
<?php }
} // end while
free_mem($result);
}
?>
</table>
</form>
</body>
</html>
Posted: Wed Feb 07, 2007 10:46 am
by RobertGonzalez
Code: Select all
<?php
// Handle required includes
require 'config.php';
include 'modlib.php';
// Connect to the database
conn_db($host, $user, $pass, 'superdb');
// Default location and section to NULL
$location = $section = NULL;
// If the get var cmdSearch is set
if (isset($_GET['cmdSearch']))
{
// If the get var mnuLocation is set and a number
if (isset($_GET["mnuLocation"]) && is_numeric($_GET["mnuLocation"]))
{
// Change the location var from NULL to mnuLocation
$location = $_GET["mnuLocation"];
}
// If the get var mnuSection is set and a number
if (isset($_GET["mnuSection"]) && is_numeric($_GET["mnuSection"]))
{
// Change the section var from NULL to mnuSection
$section = $_GET["mnuSection"];
}
}
// If the get var cmdDelete is set
if (isset($_GET['cmdDelete']))
{
//if the get var del is set
if (isset($_GET['del']))
{
/**
* This will only work for array values.
*
* If $_GET['del'] is not an array you are going to get
* a warning to the effect of supplied argument for foreach
* is not an array. To alleviate that, check is_array() first...
*/
if (is_array($_GET['del']))
{
foreach ($_GET['del'] as $del_id)
{
// Run a query to select a row for each member of the delete array
$seek = 'SELECT news_mas.lock FROM news_mas WHERE news_mas.mas_id = '.$del_id;
// Return a result identifier
$que = mysql_query($seek) or die('Problem:'.mysql_error());
// I would probably put this into a while loop
while ($pos = mysql_fetch_array($que))
{
if (is_null($pos['lock']) || $pos['lock'] == 0)
{
// Remember that DELETE removes an entire row, not selected fields
$query = 'DELETE FROM news_mas, news_dtl WHERE news_mas.mas_id = '.$del_id.' AND news_dtl.dtl_id = '.$del_id;
$result = mysql_query($query) or die('Problem: '.mysql_error());
}
}
}
}
else
{
/**
* This is an assumption on my part, but wouldn't you
* want to handle del vars that might not be an array?
*/
}
}
}
?>
Posted: Tue Feb 27, 2007 12:37 am
by victhour
feyd | Please use Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
i'm very disparate really... coz the deadline of this project is near
basically, the code will do some query according to location and section. now what I want is to delete check box(s) if enabled. My problem really here is to make my JavaScript to execute my PHP function.
[syntax="javascript"]function goDelete(){
var recslen = document.forms[0].length;
var checkboxes = "";
for(i = 1; i < recslen; i++){
if(document.forms[0].elements[i].checked==true)
checkboxes+= " " + document.forms[0].elements[i].name
}
if(checkboxes.length > 0){
var con=confirm("Are you sure you want to delete");
if(con){
document.forms[0].action="delete.php?recsno="+checkboxes
document.forms[0].submit()
}
}else{
alert("No record is selected.")
}
}
Could anyone please help me how to make my javascript/php function work? or atlist same concept to make it work. I think I can handle the php part… my concern is the JavaScript code since I’m not so knowledgeable with it.
feyd | Please use[/syntax]Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Posted: Tue Feb 27, 2007 11:58 am
by RobertGonzalez
Is your question purely about JavaScript?
Posted: Wed Feb 28, 2007 12:02 am
by victhour
nope, i just don't know whats wrong with my code... it should delete some rows after i click delete button. will you kindly please look at my code if your not busy...