fortnox007 Posted December 30, 2010 Share Posted December 30, 2010 Hi all i bet this is going to be obvious, but I ran out of ideas. I have the following script but it's not inserting. I gave the user database specific insert update and select rights but something is not working. maybe someone could help me out. $dbc = mysqli_connect('localhost','slave','password','mydatabase') or die ('error connecting to mysql server'); //display stuff $query = "SELECT * FROM mydatabase"; $result = mysqli_query($dbc, $query); while($row = mysqli_fetch_array($result)) { echo 'id: '.$row['ID']. ' and firstname is: '.$row['firstname']. ' and lastname is: '.$row['lastname'].'<br />'; } //insert stuff $query = "INSERT INTO `mydatabase`.`users` (`firstname`, `lastname`) VALUES ('john', 'doe')"; $result = mysqli_query($dbc, $query); mysqli_close($dbc); -edit ok i think i fixed it, i tried the root user and it worked. gave the slave user more rights. apperently besides database specific i ahve to give the slave user global insert update and select rights too. Can someone confirm that? Quote Link to comment https://forums.phpfreaks.com/topic/222995-really-noobie-sql-query-problem/ Share on other sites More sharing options...
mikosiko Posted December 30, 2010 Share Posted December 30, 2010 what is `mydatabase` ... a variable?.... why you are using backticks on it? Quote Link to comment https://forums.phpfreaks.com/topic/222995-really-noobie-sql-query-problem/#findComment-1152977 Share on other sites More sharing options...
fortnox007 Posted December 30, 2010 Author Share Posted December 30, 2010 hi mikosiko, I usually test my query in phpmyadmin and copy it to php that way i know its a good query phpmyadmin uses those backticks. mydatabase is the name of the database. mysqli_connect('host','user','password','database'); Do you maybe if i am right with what i found out that i have to give global insert rights besides database specific? i attached a print of phpmyadmin to make it more clear. Any help and tips are wlecome btw. It was my first test in working with a slave user with limited rights _edit, this is just a noobie script anyays just to test, i would never hard copy the variables that would be inserted ofcourse hehe [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/222995-really-noobie-sql-query-problem/#findComment-1152979 Share on other sites More sharing options...
Zurev Posted December 30, 2010 Share Posted December 30, 2010 Under grant it says No, so I don't think you granted the rights to that user. You should test the query under root just to make sure that's the issue. Quote Link to comment https://forums.phpfreaks.com/topic/222995-really-noobie-sql-query-problem/#findComment-1152980 Share on other sites More sharing options...
fortnox007 Posted December 30, 2010 Author Share Posted December 30, 2010 thanks Zurev, If i hover over Grant in the privelidges menu i get the following title "Allows adding users and privileges without reloading the privilege tables." I think i don't want to grant a slave user with that ('grant')right just to make it clear, i am able now to insert stuff ith the slave user, so in that wway the problem is fixed, but in addition i was wondering if it is necesary to grant global rights besides database specific, like i just did. If someone know i would love to hear it. I just wanted to make a stupid user that is only able to insert and select and update without dropping my tables. (not that i will not take extra measurements to prevent that) Quote Link to comment https://forums.phpfreaks.com/topic/222995-really-noobie-sql-query-problem/#findComment-1152981 Share on other sites More sharing options...
fortnox007 Posted December 30, 2010 Author Share Posted December 30, 2010 Ill put this on solved since the initial problem is fixed but if anyone knows if it is necessary to grant global rights besides database specific, like i just did. I would love to hear. And thanks mikosiko and zurev for you help! Quote Link to comment https://forums.phpfreaks.com/topic/222995-really-noobie-sql-query-problem/#findComment-1152989 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.