mostafa581 Posted January 18, 2011 Share Posted January 18, 2011 i could connect to the database and i dod nothing but to go through privileges in phpmyadmin by selecting privileges of the data base i design and by using the icon (action) it gave me a page to edit user i selected all check boxes mentioned in the global privileges then pressed go and for resource limits i read a note that said setting these options to zero removes the limit i set then to 1 and by using the connection function i could connect to the data base <?php $connectdb = mysql_connect('localhost','root','') or die("not connected"); $selectdb = mysql_select_db("koora", $connectdb); if($selectdb) { echo "ok you,re now connected to table "; }else die("couldn,t connect to the database"); when refreshing my page it showed a message that said ok you,re now connected to table but i got another problem which is by using this form <form action="admins.php" method='post'> <table align="center" valign="center"> <tr> <td> Admin,s name: </td> <td><input type="text" name="adminname" /><br /></td></tr> <td>Admin,s Password: </td> <td><input type="password" name="adminpassword" /></td></tr> <td><input type="submit" value="Add New Admin" /></td></tr> </form> </tr> </table> to enter user name and password and by using the following code to get the data to the page the form directs to $admin = $_POST['adminname']; $password = $_POST['adminpassword']; if($admin&&$password){ mysql_query("INSERT INTO 'admin'('','admin','password') VALUES('','$admin','$password');"); echo "admin was added"; }else die("not added"); every time i enter a name and password to the text box and press enter it shows the message that admin was added and by checking the table which data are entered and stored i find nothing was added and the table is empty i guess that this problem is because of something wrong with the database may be something with settings or some like that i need your help with this problem Thanks in advance Quote Link to comment https://forums.phpfreaks.com/topic/224896-problem-with-mysql-need-your-help/ Share on other sites More sharing options...
mostafa581 Posted January 18, 2011 Author Share Posted January 18, 2011 Friends i,m having something wrong with mysql database first i tried to connect to the database but i couldn,t i posted such problem and someone advised me to go to privileges of the database and i did what he said then i succesfully connected to it and after connection i established a form <form action="admins.php" method='post'> <table align="center" valign="center"> <tr> <td> Admin,s name: </td> <td><input type="text" name="adminname" /><br /></td></tr> <td>Admin,s Password: </td> <td><input type="password" name="adminpassword" /></td></tr> <td><input type="submit" value="Add New Admin" /></td></tr> </form> </tr> </table> then i established the page admins.php to direct the data to it i tried to add obtained data to the table by this code <?php $admin = $_POST['adminname']; $password = $_POST['adminpassword']; if($admin&&$password){ mysql_query("INSERT INTO 'admin'('','admin','password') VALUES('','$admin','$password');"); echo "admin was added"; }else die("not added"); by entering the name and password to the form textboxes and press the form button it shows the message that admin was added and by checking the table i find that there is nothing was added and it is as it was created include no data at all how can i solve this problem MOD Edit: code tags added. Quote Link to comment https://forums.phpfreaks.com/topic/224896-problem-with-mysql-need-your-help/#findComment-1161604 Share on other sites More sharing options...
Pikachu2000 Posted January 18, 2011 Share Posted January 18, 2011 You already have a thread on this topic here: http://www.phpfreaks.com/forums/php-coding-help/problem-with-database-connection/ Quote Link to comment https://forums.phpfreaks.com/topic/224896-problem-with-mysql-need-your-help/#findComment-1161608 Share on other sites More sharing options...
Muddy_Funster Posted January 19, 2011 Share Posted January 19, 2011 mysql_query("INSERT INTO 'admin'('','admin','password') VALUES('','$admin','$password');"); OK, when using INSERT you need to use the following syntax : INSERT INTO [table name] (field_name_1, field_name_2...) VALUES (value1, value2...) so: 1. you don't need to declare auto increment fields in the INSERT, and certainly don't declare them as an empty values 2. you don't need to use quotes or back ticks to enclose table names or field names that have no spaces in them. 3. always always have an or die statement when debugging sql queries that includes the mysql error as an output. So, that said, you should end up with something like this : $query = 'INSERT INTO admin (admin, password) VALUES (\''.$admin.'\', \''.$password.'\'); mysql_query($query) or die (mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/224896-problem-with-mysql-need-your-help/#findComment-1161685 Share on other sites More sharing options...
mostafa581 Posted January 19, 2011 Author Share Posted January 19, 2011 yes it is but that topic was about the database connection and it was solved but this topic here is about adding data to the database so i thought that it is because of the phpmyadmin settings or something like that this is why i posted this topic here and you see it is not the same one you told me about Quote Link to comment https://forums.phpfreaks.com/topic/224896-problem-with-mysql-need-your-help/#findComment-1162027 Share on other sites More sharing options...
Pikachu2000 Posted January 19, 2011 Share Posted January 19, 2011 You continued that thread to include this problem, then only 13 minutes later, you posted this one. The other thread has received at least one response, so I'm going to split it off that thread and add it here. Also, when you post code, please enclose it in the forum's . . . BBCode tags for readability. Quote Link to comment https://forums.phpfreaks.com/topic/224896-problem-with-mysql-need-your-help/#findComment-1162053 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.