Jump to content


Photo

*SOLVED* Noob Needs Help


  • Please log in to reply
11 replies to this topic

#1 Pudgemeister

Pudgemeister
  • Members
  • PipPipPip
  • Advanced Member
  • 94 posts
  • LocationCornwall, England, UK,

Posted 30 May 2006 - 01:32 PM

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:

dbinfo.inc.php

[!--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--]


test_mysql.php

[!--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--]


process.php

[!--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\" /]
[div align="center"][a href="http://imageshack.us" target="_blank"][/a]
[/div]

#2 poirot

poirot
  • Members
  • PipPipPip
  • Advanced Member
  • 646 posts
  • LocationAustin, TX

Posted 30 May 2006 - 02:08 PM

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]
~ D Kuang

#3 Pudgemeister

Pudgemeister
  • Members
  • PipPipPip
  • Advanced Member
  • 94 posts
  • LocationCornwall, England, UK,

Posted 30 May 2006 - 02:26 PM

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:

dbinfo.inc.php

[!--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--]


test_mysql.php

[!--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--]


process.php

[!--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
[div align="center"][a href="http://imageshack.us" target="_blank"][/a]
[/div]

#4 poirot

poirot
  • Members
  • PipPipPip
  • Advanced Member
  • 646 posts
  • LocationAustin, TX

Posted 30 May 2006 - 03:03 PM

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
~ D Kuang

#5 Pudgemeister

Pudgemeister
  • Members
  • PipPipPip
  • Advanced Member
  • 94 posts
  • LocationCornwall, England, UK,

Posted 30 May 2006 - 03:27 PM

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
[div align="center"][a href="http://imageshack.us" target="_blank"][/a]
[/div]

#6 poirot

poirot
  • Members
  • PipPipPip
  • Advanced Member
  • 646 posts
  • LocationAustin, TX

Posted 30 May 2006 - 03:30 PM

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).
~ D Kuang

#7 mikejarrett

mikejarrett
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 30 May 2006 - 03:44 PM

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.

#8 Pudgemeister

Pudgemeister
  • Members
  • PipPipPip
  • Advanced Member
  • 94 posts
  • LocationCornwall, England, UK,

Posted 30 May 2006 - 04:57 PM

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
[div align="center"][a href="http://imageshack.us" target="_blank"][/a]
[/div]

#9 Pudgemeister

Pudgemeister
  • Members
  • PipPipPip
  • Advanced Member
  • 94 posts
  • LocationCornwall, England, UK,

Posted 30 May 2006 - 05:22 PM

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
[div align="center"][a href="http://imageshack.us" target="_blank"][/a]
[/div]

#10 poirot

poirot
  • Members
  • PipPipPip
  • Advanced Member
  • 646 posts
  • LocationAustin, TX

Posted 30 May 2006 - 05:25 PM

Try to change "first name" to "first_name" and "last name" to "last_name". Avoid using spaces.
~ D Kuang

#11 Pudgemeister

Pudgemeister
  • Members
  • PipPipPip
  • Advanced Member
  • 94 posts
  • LocationCornwall, England, UK,

Posted 30 May 2006 - 05:31 PM

that cleared the final problem up and it is all now working fine.

Thank you very much everyone!

Pudgemeister
[div align="center"][a href="http://imageshack.us" target="_blank"][/a]
[/div]

#12 Pudgemeister

Pudgemeister
  • Members
  • PipPipPip
  • Advanced Member
  • 94 posts
  • LocationCornwall, England, UK,

Posted 02 June 2006 - 02:39 PM

sorry ignore this post-I didn't mean to make it
[div align="center"][a href="http://imageshack.us" target="_blank"][/a]
[/div]




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users