Jump to content

Archived

This topic is now archived and is closed to further replies.

t.bo

Deleting rows only works on localhost and not online?

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

Share this post


Link to post
Share on other sites
Can you please post your 'DB Connect' it might be something in there.  With out seeing it, I think it might be that your Database locally is simply different from your online DB.  Check with your hosting provider for your SQL details.

Share this post


Link to post
Share on other sites
  add a & ok!

example ok


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

Share this post


Link to post
Share on other sites
[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...

Share this post


Link to post
Share on other sites
u might want to make posts without ur username, etc... in them mate, easy for people to steal..

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
Check also that your web host uses localhost.  My web host uses a random alphanumeric string for the name and NOT localhost.  I believe several companies do this.  Check everyone elses suggestiong too.

Share this post


Link to post
Share on other sites
Still doesn't help guys :-(...

Localhost is no problem...

U can see the example on [url=http://www.euroclinix.com/affildelete.php]http://www.euroclinix.com/affildelete.php[/url]

Share this post


Link to post
Share on other sites
thats it I have really had enough of u all copying me... please stop it... lol.. only messing i have nothing else to do at work, but post silly comments on here.. and im getting paid for it.. lol..wooo hooo..

Share this post


Link to post
Share on other sites
As i said.

I already tried changing cmd to $_GET['cmd']

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Nothin changed..

It did not even output anything from that echo "command is..."

Share this post


Link to post
Share on other sites
<?

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!";
}

?>

Share this post


Link to post
Share on other sites
I think you really have error on something else.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
<?

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...

Share this post


Link to post
Share on other sites
look like it works

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

×

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.