woodsonoversoul Posted August 7, 2007 Share Posted August 7, 2007 Hello. Small problem I need some help with. I can't fiqure out why my delete function isn't working. I have a listing of rows in my database with an option to delete an individual row at the end: echo "<div id=\"navcontainer\">"; echo "<ul>"; echo "<li><a href=#>".$row[2]."</li>"; echo "<li><a href=#>".$row[3]."</li>"; echo "<li><a href=#>$".$row[4]."</li>"; echo "<li><a href=".$_SERVER['PHP_SELF']."?id=".$row[1].">x</a></li>"; echo "</ul>"; echo "</div>"; The page start up checking to see if an id has been specified (I belive this is where the proble is): // if id provided, then delete that record if (isset($_GET['id'])) { // create query to delete record $query = "DELETE FROM purchase WHERE sale_id = ".$_GET['id']; And the content of my database looks like this: +-----------+-------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +-----------+-------------+------+-----+---------+----------------+ | user_name | varchar(11) | NO | | | | | sale_id | int(11) | NO | PRI | NULL | auto_increment | | category | varchar(11) | YES | | NULL | | | location | varchar(11) | YES | | NULL | | | price | float(7,2) | YES | | NULL | | +-----------+-------------+------+-----+---------+----------------+ Where did I go wrong? All help is greatly appreciated Quote Link to comment https://forums.phpfreaks.com/topic/63804-deleting-a-row-from-a-database/ Share on other sites More sharing options...
wildteen88 Posted August 7, 2007 Share Posted August 7, 2007 You have to run $query through mysql_query in order for the query to execute. PHP wont execute queries with out mysql_query // if id provided, then delete that record if (isset($_GET['id'])) { // create query to delete record $query = "DELETE FROM purchase WHERE sale_id = ".$_GET['id']; mysql_query($query); Quote Link to comment https://forums.phpfreaks.com/topic/63804-deleting-a-row-from-a-database/#findComment-317974 Share on other sites More sharing options...
woodsonoversoul Posted August 7, 2007 Author Share Posted August 7, 2007 awesome. That got the row deleted but, even though the row disapeared on the page, when I delete a row I get access denied and a link to the server could not be established warnings. How does that work if I just obviously connected to my database to preform those operations? Should I reconnect somewhere? Quote Link to comment https://forums.phpfreaks.com/topic/63804-deleting-a-row-from-a-database/#findComment-317981 Share on other sites More sharing options...
clanstyles Posted August 7, 2007 Share Posted August 7, 2007 The user that is used to CONNECT to the database might not have access to "Delete" rows. mabye only insert or modify. Quote Link to comment https://forums.phpfreaks.com/topic/63804-deleting-a-row-from-a-database/#findComment-317982 Share on other sites More sharing options...
woodsonoversoul Posted August 7, 2007 Author Share Posted August 7, 2007 I'm the only user and the db isn't password protected. I'll try to grant all privleges to myself though... Quote Link to comment https://forums.phpfreaks.com/topic/63804-deleting-a-row-from-a-database/#findComment-317984 Share on other sites More sharing options...
woodsonoversoul Posted August 7, 2007 Author Share Posted August 7, 2007 Looking through some other literature, all other sources say that root user has all privleges. Do I need to make up a password and username and grant myself total access? Quote Link to comment https://forums.phpfreaks.com/topic/63804-deleting-a-row-from-a-database/#findComment-317994 Share on other sites More sharing options...
teng84 Posted August 8, 2007 Share Posted August 8, 2007 maybe the data base is not specified Quote Link to comment https://forums.phpfreaks.com/topic/63804-deleting-a-row-from-a-database/#findComment-318027 Share on other sites More sharing options...
woodsonoversoul Posted August 8, 2007 Author Share Posted August 8, 2007 I'm using the code suggested by wildteen mixed with code using mysqli - I know mysql/mysqli connect in different ways, could that be a problem? Quote Link to comment https://forums.phpfreaks.com/topic/63804-deleting-a-row-from-a-database/#findComment-318032 Share on other sites More sharing options...
teng84 Posted August 8, 2007 Share Posted August 8, 2007 im not using mysqli but heres to check try to include the db name sample select * from BDNAME.TBLNAME a where a.field = BEHHH something like that Quote Link to comment https://forums.phpfreaks.com/topic/63804-deleting-a-row-from-a-database/#findComment-318035 Share on other sites More sharing options...
woodsonoversoul Posted August 8, 2007 Author Share Posted August 8, 2007 no luck with that Quote Link to comment https://forums.phpfreaks.com/topic/63804-deleting-a-row-from-a-database/#findComment-318038 Share on other sites More sharing options...
teng84 Posted August 8, 2007 Share Posted August 8, 2007 can you do a die(mysql_error()) and post here the whole message Quote Link to comment https://forums.phpfreaks.com/topic/63804-deleting-a-row-from-a-database/#findComment-318040 Share on other sites More sharing options...
woodsonoversoul Posted August 8, 2007 Author Share Posted August 8, 2007 Before doing a mysql error I get: Warning: mysql_query() [function.mysql-query]: Access denied for user 'www-data'@'localhost' (using password: NO) in /var/www/spindex/display.php on line 31 Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in /var/www/spindex/display.php on line 31 line 31 is: // run the query mysql_query($query); If you could give me any more instruction on how to form a die(mysql_error()) I'll do that(still a novice). I'm assuming it involves if statments and I'm not sure what I should be testing in those statments... Quote Link to comment https://forums.phpfreaks.com/topic/63804-deleting-a-row-from-a-database/#findComment-318053 Share on other sites More sharing options...
teng84 Posted August 8, 2007 Share Posted August 8, 2007 copy the query and paste it i the db then run it there and see if the error message will occur because in suspecting you have limited previlage Quote Link to comment https://forums.phpfreaks.com/topic/63804-deleting-a-row-from-a-database/#findComment-318058 Share on other sites More sharing options...
woodsonoversoul Posted August 8, 2007 Author Share Posted August 8, 2007 you're totally right. I logged in through terminal and deleted the row, using the exact same code as the code on the site, with no errors, no problems. However when I tried to grant myself (the root user, I still don't understand why I don't have complete privleges) total privleges I used the code: GRANT ALL ON spindex.* TO root @ localhost; and recieved: ERROR 1064 (42000): 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 'localhost' at line 1 Quote Link to comment https://forums.phpfreaks.com/topic/63804-deleting-a-row-from-a-database/#findComment-318082 Share on other sites More sharing options...
teng84 Posted August 8, 2007 Share Posted August 8, 2007 are you saying the Db is in the local machine? Quote Link to comment https://forums.phpfreaks.com/topic/63804-deleting-a-row-from-a-database/#findComment-318088 Share on other sites More sharing options...
woodsonoversoul Posted August 8, 2007 Author Share Posted August 8, 2007 yes Quote Link to comment https://forums.phpfreaks.com/topic/63804-deleting-a-row-from-a-database/#findComment-318102 Share on other sites More sharing options...
woodsonoversoul Posted August 14, 2007 Author Share Posted August 14, 2007 Bump - 'cause I'm still having trouble with this: the row deleted but, even though the row disapeared on the page, when I delete a row I get access denied and a link to the server could not be established warnings. How does that work if I just obviously connected to my database to preform those operations? All assistance is appreciated Quote Link to comment https://forums.phpfreaks.com/topic/63804-deleting-a-row-from-a-database/#findComment-324028 Share on other sites More sharing options...
woodsonoversoul Posted August 15, 2007 Author Share Posted August 15, 2007 Any suggestions? Quote Link to comment https://forums.phpfreaks.com/topic/63804-deleting-a-row-from-a-database/#findComment-324204 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.