t.bo Posted July 17, 2006 Share Posted July 17, 2006 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 outThanks in advance Link to comment https://forums.phpfreaks.com/topic/14847-deleting-rows-only-works-on-localhost-and-not-online/ Share on other sites More sharing options...
ChaosXero Posted July 17, 2006 Share Posted July 17, 2006 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. Link to comment https://forums.phpfreaks.com/topic/14847-deleting-rows-only-works-on-localhost-and-not-online/#findComment-59353 Share on other sites More sharing options...
redarrow Posted July 17, 2006 Share Posted July 17, 2006 add a & ok!example okecho "<a href='affildelete.php?&cmd=delete&idfield=$id'>$title - Delete</a>"; Link to comment https://forums.phpfreaks.com/topic/14847-deleting-rows-only-works-on-localhost-and-not-online/#findComment-59359 Share on other sites More sharing options...
t.bo Posted July 17, 2006 Author Share Posted July 17, 2006 [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 belowmysql_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... Link to comment https://forums.phpfreaks.com/topic/14847-deleting-rows-only-works-on-localhost-and-not-online/#findComment-59368 Share on other sites More sharing options...
brown2005 Posted July 17, 2006 Share Posted July 17, 2006 u might want to make posts without ur username, etc... in them mate, easy for people to steal.. Link to comment https://forums.phpfreaks.com/topic/14847-deleting-rows-only-works-on-localhost-and-not-online/#findComment-59371 Share on other sites More sharing options...
brown2005 Posted July 17, 2006 Share Posted July 17, 2006 $id = $_GET['idfield'];u have stated that but not$cmd = $_GET['delete']; Link to comment https://forums.phpfreaks.com/topic/14847-deleting-rows-only-works-on-localhost-and-not-online/#findComment-59373 Share on other sites More sharing options...
brown2005 Posted July 17, 2006 Share Posted July 17, 2006 $cmd = $_GET['cmd'];sorry that Link to comment https://forums.phpfreaks.com/topic/14847-deleting-rows-only-works-on-localhost-and-not-online/#findComment-59375 Share on other sites More sharing options...
hvle Posted July 17, 2006 Share Posted July 17, 2006 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 Link to comment https://forums.phpfreaks.com/topic/14847-deleting-rows-only-works-on-localhost-and-not-online/#findComment-59381 Share on other sites More sharing options...
brown2005 Posted July 17, 2006 Share Posted July 17, 2006 thats wat I said.. lol.. Link to comment https://forums.phpfreaks.com/topic/14847-deleting-rows-only-works-on-localhost-and-not-online/#findComment-59382 Share on other sites More sharing options...
ChaosXero Posted July 17, 2006 Share Posted July 17, 2006 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. Link to comment https://forums.phpfreaks.com/topic/14847-deleting-rows-only-works-on-localhost-and-not-online/#findComment-59385 Share on other sites More sharing options...
t.bo Posted July 17, 2006 Author Share Posted July 17, 2006 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] Link to comment https://forums.phpfreaks.com/topic/14847-deleting-rows-only-works-on-localhost-and-not-online/#findComment-59386 Share on other sites More sharing options...
ChaosXero Posted July 17, 2006 Share Posted July 17, 2006 Make $cmd $_GET['cmd'] and try again. Link to comment https://forums.phpfreaks.com/topic/14847-deleting-rows-only-works-on-localhost-and-not-online/#findComment-59393 Share on other sites More sharing options...
brown2005 Posted July 17, 2006 Share Posted July 17, 2006 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.. Link to comment https://forums.phpfreaks.com/topic/14847-deleting-rows-only-works-on-localhost-and-not-online/#findComment-59394 Share on other sites More sharing options...
t.bo Posted July 17, 2006 Author Share Posted July 17, 2006 As i said.I already tried changing cmd to $_GET['cmd'] Link to comment https://forums.phpfreaks.com/topic/14847-deleting-rows-only-works-on-localhost-and-not-online/#findComment-59407 Share on other sites More sharing options...
hvle Posted July 17, 2006 Share Posted July 17, 2006 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. Link to comment https://forums.phpfreaks.com/topic/14847-deleting-rows-only-works-on-localhost-and-not-online/#findComment-59418 Share on other sites More sharing options...
t.bo Posted July 17, 2006 Author Share Posted July 17, 2006 Nothin changed..It did not even output anything from that echo "command is..." Link to comment https://forums.phpfreaks.com/topic/14847-deleting-rows-only-works-on-localhost-and-not-online/#findComment-59427 Share on other sites More sharing options...
brown2005 Posted July 17, 2006 Share Posted July 17, 2006 <? 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!";}?> Link to comment https://forums.phpfreaks.com/topic/14847-deleting-rows-only-works-on-localhost-and-not-online/#findComment-59437 Share on other sites More sharing options...
hvle Posted July 17, 2006 Share Posted July 17, 2006 I think you really have error on something else. Link to comment https://forums.phpfreaks.com/topic/14847-deleting-rows-only-works-on-localhost-and-not-online/#findComment-59438 Share on other sites More sharing options...
brown2005 Posted July 17, 2006 Share Posted July 17, 2006 change ur code to that, i have tested it and it works fine...let me know if ok Link to comment https://forums.phpfreaks.com/topic/14847-deleting-rows-only-works-on-localhost-and-not-online/#findComment-59439 Share on other sites More sharing options...
t.bo Posted July 17, 2006 Author Share Posted July 17, 2006 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 Link to comment https://forums.phpfreaks.com/topic/14847-deleting-rows-only-works-on-localhost-and-not-online/#findComment-59447 Share on other sites More sharing options...
brown2005 Posted July 17, 2006 Share Posted July 17, 2006 <? 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... Link to comment https://forums.phpfreaks.com/topic/14847-deleting-rows-only-works-on-localhost-and-not-online/#findComment-59448 Share on other sites More sharing options...
brown2005 Posted July 17, 2006 Share Posted July 17, 2006 http://www.fantasy-comps.com/affildelete.phpsee it here Link to comment https://forums.phpfreaks.com/topic/14847-deleting-rows-only-works-on-localhost-and-not-online/#findComment-59450 Share on other sites More sharing options...
hvle Posted July 17, 2006 Share Posted July 17, 2006 look like it works Link to comment https://forums.phpfreaks.com/topic/14847-deleting-rows-only-works-on-localhost-and-not-online/#findComment-59451 Share on other sites More sharing options...
AndyB Posted July 17, 2006 Share Posted July 17, 2006 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. Link to comment https://forums.phpfreaks.com/topic/14847-deleting-rows-only-works-on-localhost-and-not-online/#findComment-59452 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.