Jump to content

Recommended Posts

Hello everybody,

A few days ago I already asked a question about deleting rows. The code works perfect on my localhost but when I upload it (and make all the changes) the code does not delete a row. There is not even an error message. The list of links just stay visible with no links deleted.
Code : [code]
<?
include('dbconnect.php');

if(!isset($cmd))
{

  $result = mysql_query("select * from `affiliate`") or die(mysql_error());
 

  while($r=mysql_fetch_array($result))
  {

      $title=$r["titlefield"];
      $id=$r["idfield"];
   

      echo "<a href='affildelete.php?cmd=delete&idfield=$id'>$title - Delete</a>";
      echo "<br>";
    }
}
?>
<?
$id = $_GET['idfield'];
if($cmd=="delete")
{
    $sql = "DELETE FROM `affiliate` WHERE idfield='$id'";
    $result = mysql_query($sql) or die(mysql_error());
    echo "Link verwijderd!";
}
?>
[/code]

Hope someone can help out
Thanks in advance
[code]<?
$username = "euroclin"; //put your mysql username
$password = "passwurd"; //put your mysql password
$host = "localhost"; //put your mysql host usually localhost
$database = "euroclin_01"; //put your mysql


//Do not change these lines below
mysql_connect($host,$username,$password) or die("Error connecting to Database! " . mysql_error());
mysql_select_db($database) or die("Cannot select database! " . mysql_error());
?>[/code]

I doubt its the dbconnect cuz everything else that uses it works fine...
This is very likely to be problem with register global, and that you've used $cmd without assigning $cmd.  You might have assume that the variable $cmd automaticly parsed from $_GET.

my guess is from this line:
if($cmd=="delete")

change it to:
if ($_GET['cmd'] == 'delete')

if this is the error, you should never rely on register_global.
meaning, always use $_GET or $_POST .. ect,..

yes, read more about register_global
i do not see any obvious error from your code, however, it sure would help if you add some debugging code.

replace this block:
[code]
$id = $_GET['idfield'];
if($cmd=="delete")
{
    $sql = "DELETE FROM `affiliate` WHERE idfield='$id'";
    $result = mysql_query($sql) or die(mysql_error());
    echo "Link verwijderd!";
}
[/code]

with
[code]
<?php
$id = $_GET['idfield'];
$cmd = $_GET['cmd'];
//debug:
echo "command is '$cmd', id is '$id'\n";

if($cmd=="delete")
{
    $sql = "DELETE FROM `affiliate` WHERE idfield='$id'";
    $result = mysql_query($sql) or die(mysql_error());
    echo "Link verwijderd!";
}
?>
[/code]

if it print out something like
echo "command is '', id is ''\n"; then you have some kind of error.
<?

session_start();


$id = $_GET['idfield'];
$cmd = $_GET['cmd'];

include('dbconnect.php');

if(!isset($cmd))
{

  $result = mysql_query("select * from `affiliate`") or die(mysql_error());
 
  while($r=mysql_fetch_array($result))
  {

      $title=$r["titlefield"];
      $id=$r["idfield"];
   

      echo "<a href='affildelete.php?cmd=delete&idfield=$id'>$title - Delete</a>";
      echo "<br>";
    }
}


elseif($cmd == "delete")
{

    $sql = "DELETE FROM affiliate WHERE idfield='$id'";
    $result = mysql_query($sql) or die(mysql_error());
    echo "Link verwijderd!";
}

?>
Still no change [url=http://www.euroclinix.com/affildelete.php]http://www.euroclinix.com/affildelete.php[/url]

I'm really clueless on this one.
But i uploaded other php files and one had this code : [code]<?
include('dbconnect.php');
$id = $_GET[id];
$sql = mysql_query("SELECT * FROM yourtable WHERE idfield='$id'") or die(mysql_error());
$r=mysql_fetch_array($sql);
$content = mysql_result($sql, 0 ,"content");
echo "$content";
?>

[/code]

And I got the error "Warning: mysql_result(): Unable to jump to row 0 on MySQL result index 4 in /home/euroclin/public_html/page.php on line 6"
I did not get this error when I tested it on my localhost.

Could the 2 errors have something to do with each other?

grtz
<?

session_start();


$id = $_GET['idfield'];
$cmd = $_GET['cmd'];

include('dbconnect.php');

if(!isset($cmd))
{

  $result = mysql_query("select * from `affiliate`") or die(mysql_error());
 
  while($r=mysql_fetch_array($result))
  {

      $title=$r["titlefield"];
      $id=$r["idfield"];
   
 
      echo "<a href='affildelete.php?cmd=delete&idfield=$id'>$title - Delete[/url]";
      echo "
";
    }
}


elseif($cmd == "delete")
{

    $sql = "DELETE FROM affiliate WHERE idfield='$id'";
    $result = mysql_query($sql) or die(mysql_error());
    echo "Link verwijderd!";
}

?>

I HAVE CREATED THAT FILE AND UR CONNECTION FILE AND IT WORKS FINE...
If it works on 'localhost' and doesn't work on a live server, then almost certainly the 'problem' is one associated with the state of register_globals (probably ON on localhost and OFF on the live server). That code snippet doesn't appear to retrieve the value of the variable $cmd.
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.