Pudgemeister Posted May 30, 2006 Share Posted May 30, 2006 Hi AllThis is the second time now that i have wrote this out as i accidentally closed the webpage before completing it last time grrrrrrrrrrr.I am having problems getting info from a form to be posted into my database table.The database table is called "users".The fields in the table are "username", "password", "first name", "last name", and "money".I do not want anything being entered into the money field so ignore that one-unless it is something to d with that which is stopping me from getting infomation posted into the table.username, password, first name, and last name, are all varchar(20).they are all in that order with the money field at the end.These are the three files that have all the code in for posting into these fields:[b]dbinfo.inc.php[/b][!--coloro:#3333FF--][span style=\"color:#3333FF\"][!--/coloro--]<?$connect=mysql_connect ("localhost", "username", "password") or die ('You cannot connect to the database because: ' . mysql_error());mysql_select_db ("database");$disconnect=mysql_close();?>[!--colorc--][/span][!--/colorc--][b]test_mysql.php[/b][!--coloro:#3333FF--][span style=\"color:#3333FF\"][!--/coloro--]<?include("dbinfo.inc.php");$connect;echo '<center>Game Testing</center><br><br><br>';echo '<form action="process.php" method="post">';echo 'First Name:<input type="text" name="first name"><br>';echo 'Last Name:<input type="text" name="last name"><br>';echo 'Username:<input type="text" name="username"><br>';echo 'Password:<input type="text" name="password"><br>';echo '<input type="Submit"></form>';?>[!--colorc--][/span][!--/colorc--][b]process.php[/b][!--coloro:#3333FF--][span style=\"color:#3333FF\"][!--/coloro--]<?include ("dbinfo.inc.php");$connect;$first=$_POST['first name'];$last=$_POST['last name'];$username=$_POST['username'];$password=$_POST['password'];$query = "INSERT INTO users VALUES('$username','$password','$first','$last','')";mysql_query($query);$disconnect;?>[!--colorc--][/span][!--/colorc--]I do know my username and password wtc. but I have removed them for obvious reasons. I have checked them all three times to make sure this isn't the problem.All three files above are in the same place on the server and yes the server has php and mysql installed obviously.one thing i noticed while looking in the table "users" is that there is no index defined-could someone explain what this is all about and do I need an index defined?If Any More Info Is Needed I will Say.Please Help Soon [img src=\"style_emoticons/[#EMO_DIR#]/smile.gif\" style=\"vertical-align:middle\" emoid=\":smile:\" border=\"0\" alt=\"smile.gif\" /] Pudgemeister [img src=\"style_emoticons/[#EMO_DIR#]/smile.gif\" style=\"vertical-align:middle\" emoid=\":smile:\" border=\"0\" alt=\"smile.gif\" /] Quote Link to comment https://forums.phpfreaks.com/topic/10773-solved-noob-needs-help/ Share on other sites More sharing options...
poirot Posted May 30, 2006 Share Posted May 30, 2006 First, you shouldn't use $connect = .... And then simply write $connect. This is likely to result in error, and also strings are not executed (unless you use eval(), but I'd not recommend thisSimply put mysql_connect(...). And remove the $disconnect thing. Each time use require dbinfo.inc.php it will automatically connect to the database, no need to call anything.Then, remove the $connect and $disconnect from all files. TO disconect, use mysql_close() directly instead.Also, modify your query to mysql_query($query) or die(mysql_error()) so you can know if anything went wrong.As for the index, it's some kind of "id" for the tables. People often create an id field, "INT AUTO_INCREMENT PRIMARY KEY".[a href=\"http://www.mysqlfreaks.com/mysql/manual_MySQL_Optimisation.html#IDX927\" target=\"_blank\"]More information here[/a] Quote Link to comment https://forums.phpfreaks.com/topic/10773-solved-noob-needs-help/#findComment-40240 Share on other sites More sharing options...
Pudgemeister Posted May 30, 2006 Author Share Posted May 30, 2006 Hi AgainI would firstly like to say thank you very much for the fast reply! I never expected to have a reply today.ANYWAYI have edited a few things in accordance with your post and have ended up with the files now looking like this:[b]dbinfo.inc.php[/b][!--coloro:#3333FF--][span style=\"color:#3333FF\"][!--/coloro--]<?mysql_connect ("localhost", "username", "password") or die ('You cannot connect to the database because: ' . mysql_error());mysql_select_db ("database");?>[!--colorc--][/span][!--/colorc--][b]test_mysql.php[/b][!--coloro:#3333FF--][span style=\"color:#3333FF\"][!--/coloro--]<?echo '<center>Game Testing</center><br><br><br>';echo '<form action="process.php" method="post">';echo 'First Name:<input type="text" name="first name"><br>';echo 'Last Name:<input type="text" name="last name"><br>';echo 'Username:<input type="text" name="username"><br>';echo 'Password:<input type="text" name="password"><br>';echo '<input type="Submit"></form>';?>[!--colorc--][/span][!--/colorc--][b]process.php[/b][!--coloro:#3333FF--][span style=\"color:#3333FF\"][!--/coloro--]<?include ("dbinfo.inc.php");$first=$_POST['first name'];$last=$_POST['last name'];$username=$_POST['username'];$password=$_POST['password'];$query = "INSERT INTO users VALUES('$username','$password','$first','$last','')";mysql_query($query) or die(mysql_error());mysql_close();?>[!--colorc--][/span][!--/colorc--]Now I am getting shown this in big bold letters "no database selected". This happens when i have pressed the select button, and I am taken to process.php.take a look-the information is there-and I have got all the database info correct-i checked twice again.sorri to keep asking about such a simple piece of code-what have I done wrong this time?Pudgemeister Quote Link to comment https://forums.phpfreaks.com/topic/10773-solved-noob-needs-help/#findComment-40246 Share on other sites More sharing options...
poirot Posted May 30, 2006 Share Posted May 30, 2006 Maybe it's not selecting the database. Try to use mysql_select_db('database') or die(mysql_error())This will tell you if an error happens when you tried to use mysql_select_db Quote Link to comment https://forums.phpfreaks.com/topic/10773-solved-noob-needs-help/#findComment-40252 Share on other sites More sharing options...
Pudgemeister Posted May 30, 2006 Author Share Posted May 30, 2006 Ok thanx for that-It is now telling me what is wrong lolthe error I am currently getting is:Access denied for user: username@localhost' to database 'database'password, username, and database name are all correct!I don't understandPudgemeister Quote Link to comment https://forums.phpfreaks.com/topic/10773-solved-noob-needs-help/#findComment-40264 Share on other sites More sharing options...
poirot Posted May 30, 2006 Share Posted May 30, 2006 Probably because "username" has no privileges or maybe there's not even a user called "username".If you are using a server package to test on localhost [your own computer], you should try "root" as username and "root" as password (or sometimes leave the password blank). Quote Link to comment https://forums.phpfreaks.com/topic/10773-solved-noob-needs-help/#findComment-40270 Share on other sites More sharing options...
mikejarrett Posted May 30, 2006 Share Posted May 30, 2006 It sounds like your issues are database related. I would recommend that you install phpmyadmin. It is an easy-to-use php app used for managing mysql. You can test your queries outside of the php and make sure that they are all working correctly. Quote Link to comment https://forums.phpfreaks.com/topic/10773-solved-noob-needs-help/#findComment-40274 Share on other sites More sharing options...
Pudgemeister Posted May 30, 2006 Author Share Posted May 30, 2006 Hi AllI would just like to say thank you to you all for your help.Alothough i Did check my username etc. over and over again-the username was wrong. [img src=\"style_emoticons/[#EMO_DIR#]/unsure.gif\" style=\"vertical-align:middle\" emoid=\":unsure:\" border=\"0\" alt=\"unsure.gif\" /] I thought I had created Another User-I had only done so PARTIALLYI was being helped by my host for the whole time when he had a look and gave me the message that The username wasn't totally insstalled.It is now installed and my database is recieving the information.TYVM EVERYONE!Pudgemeister Quote Link to comment https://forums.phpfreaks.com/topic/10773-solved-noob-needs-help/#findComment-40297 Share on other sites More sharing options...
Pudgemeister Posted May 30, 2006 Author Share Posted May 30, 2006 ok I still have a prob with this lolusing the last copies of the files I have posted above could you possible tell me why the database is only recieving the username and password but not first name and last name?thanx againPudgemeister Quote Link to comment https://forums.phpfreaks.com/topic/10773-solved-noob-needs-help/#findComment-40304 Share on other sites More sharing options...
poirot Posted May 30, 2006 Share Posted May 30, 2006 Try to change "first name" to "first_name" and "last name" to "last_name". Avoid using spaces. Quote Link to comment https://forums.phpfreaks.com/topic/10773-solved-noob-needs-help/#findComment-40306 Share on other sites More sharing options...
Pudgemeister Posted May 30, 2006 Author Share Posted May 30, 2006 that cleared the final problem up and it is all now working fine.Thank you very much everyone!Pudgemeister Quote Link to comment https://forums.phpfreaks.com/topic/10773-solved-noob-needs-help/#findComment-40309 Share on other sites More sharing options...
Pudgemeister Posted June 2, 2006 Author Share Posted June 2, 2006 sorry ignore this post-I didn't mean to make it Quote Link to comment https://forums.phpfreaks.com/topic/10773-solved-noob-needs-help/#findComment-41176 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.