Jump to content


Photo

Deleting rows only works on localhost and not online?


  • Please log in to reply
23 replies to this topic

#1 t.bo

t.bo
  • Members
  • PipPipPip
  • Advanced Member
  • 57 posts

Posted 17 July 2006 - 01:53 PM

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

Hope someone can help out
Thanks in advance

#2 ChaosXero

ChaosXero
  • Members
  • PipPipPip
  • Advanced Member
  • 80 posts

Posted 17 July 2006 - 01:55 PM

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.

#3 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 17 July 2006 - 02:00 PM

  add a & ok!

example ok


echo "<a href='affildelete.php?&cmd=delete&idfield=$id'>$title - Delete</a>";
Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#4 t.bo

t.bo
  • Members
  • PipPipPip
  • Advanced Member
  • 57 posts

Posted 17 July 2006 - 02:06 PM

<?
$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());
?>

I doubt its the dbconnect cuz everything else that uses it works fine...

#5 brown2005

brown2005
  • Members
  • PipPipPip
  • Advanced Member
  • 943 posts

Posted 17 July 2006 - 02:07 PM

u might want to make posts without ur username, etc... in them mate, easy for people to steal..

#6 brown2005

brown2005
  • Members
  • PipPipPip
  • Advanced Member
  • 943 posts

Posted 17 July 2006 - 02:09 PM

$id = $_GET['idfield'];

u have stated that but not

$cmd  = $_GET['delete'];

#7 brown2005

brown2005
  • Members
  • PipPipPip
  • Advanced Member
  • 943 posts

Posted 17 July 2006 - 02:09 PM

$cmd  = $_GET['cmd'];

sorry that

#8 hvle

hvle
  • Members
  • PipPipPip
  • Advanced Member
  • 667 posts
  • Locationmelbourne, Australia

Posted 17 July 2006 - 02:12 PM

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

Life's too short for arguing.

#9 brown2005

brown2005
  • Members
  • PipPipPip
  • Advanced Member
  • 943 posts

Posted 17 July 2006 - 02:13 PM

thats wat I said.. lol..

#10 ChaosXero

ChaosXero
  • Members
  • PipPipPip
  • Advanced Member
  • 80 posts

Posted 17 July 2006 - 02:14 PM

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.

#11 t.bo

t.bo
  • Members
  • PipPipPip
  • Advanced Member
  • 57 posts

Posted 17 July 2006 - 02:16 PM

Still doesn't help guys :-(...

Localhost is no problem...

U can see the example on http://www.euroclini...affildelete.php

#12 ChaosXero

ChaosXero
  • Members
  • PipPipPip
  • Advanced Member
  • 80 posts

Posted 17 July 2006 - 02:19 PM

Make $cmd $_GET['cmd'] and try again.

#13 brown2005

brown2005
  • Members
  • PipPipPip
  • Advanced Member
  • 943 posts

Posted 17 July 2006 - 02:22 PM

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

#14 t.bo

t.bo
  • Members
  • PipPipPip
  • Advanced Member
  • 57 posts

Posted 17 July 2006 - 02:33 PM

As i said.

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

#15 hvle

hvle
  • Members
  • PipPipPip
  • Advanced Member
  • 667 posts
  • Locationmelbourne, Australia

Posted 17 July 2006 - 02:46 PM

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

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

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

if it print out something like
echo "command is '', id is ''\n"; then you have some kind of error.
Life's too short for arguing.

#16 t.bo

t.bo
  • Members
  • PipPipPip
  • Advanced Member
  • 57 posts

Posted 17 July 2006 - 02:56 PM

Nothin changed..

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



#17 brown2005

brown2005
  • Members
  • PipPipPip
  • Advanced Member
  • 943 posts

Posted 17 July 2006 - 03:09 PM

<?

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

?>

#18 hvle

hvle
  • Members
  • PipPipPip
  • Advanced Member
  • 667 posts
  • Locationmelbourne, Australia

Posted 17 July 2006 - 03:10 PM

I think you really have error on something else.
Life's too short for arguing.

#19 brown2005

brown2005
  • Members
  • PipPipPip
  • Advanced Member
  • 943 posts

Posted 17 July 2006 - 03:11 PM

change ur code to that, i have tested it and it works fine...

let me know if ok

#20 t.bo

t.bo
  • Members
  • PipPipPip
  • Advanced Member
  • 57 posts

Posted 17 July 2006 - 03:16 PM

Still no change http://www.euroclini...affildelete.php

I'm really clueless on this one.
But i uploaded other php files and one had this 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";
?>


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




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users