Jump to content

Recommended Posts

Hi All

This 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\" /]
Link to comment
https://forums.phpfreaks.com/topic/10773-solved-noob-needs-help/
Share on other sites

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 this

Simply 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]
Link to comment
https://forums.phpfreaks.com/topic/10773-solved-noob-needs-help/#findComment-40240
Share on other sites

Hi Again

I would firstly like to say thank you very much for the fast reply! I never expected to have a reply today.

ANYWAY

I 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
Link to comment
https://forums.phpfreaks.com/topic/10773-solved-noob-needs-help/#findComment-40246
Share on other sites

Ok thanx for that-It is now telling me what is wrong lol

the 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 understand

Pudgemeister
Link to comment
https://forums.phpfreaks.com/topic/10773-solved-noob-needs-help/#findComment-40264
Share on other sites

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).
Link to comment
https://forums.phpfreaks.com/topic/10773-solved-noob-needs-help/#findComment-40270
Share on other sites

Hi All

I 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 PARTIALLY

I 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
Link to comment
https://forums.phpfreaks.com/topic/10773-solved-noob-needs-help/#findComment-40297
Share on other sites

ok I still have a prob with this lol

using 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 again

Pudgemeister
Link to comment
https://forums.phpfreaks.com/topic/10773-solved-noob-needs-help/#findComment-40304
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.