PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
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.")
}
}
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
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]
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;
}
}
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.
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?
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.
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.
<?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?
*/
}
}
}
?>
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.
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]
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...