View Full Version : Help..
IAMTHEEVILBEAN
03-23-2004, 11:46 PM
Im trying to set up a login database thing for mysite. Anyways, I already made a Msql table titled ID and filled in the fields.
ID
Password
Email
anyways.....i cant figure out how to get the register.php to send the data to the mysql table and sign up the user. Can someone help.
missing-score
03-23-2004, 11:59 PM
Please read the rules before asking a question <http://www.codingforums.com/rules.htm>
IAMTHEEVILBEAN
03-24-2004, 12:02 AM
what did I do wrong?
I just had a question....so I asked.
**EDIT**
Oh...I wasnt advertising i was just seeing if someone coul dlook at my code and see what i did wrong....I guess not. I'll delete the link. I am very sorry.
Can someone please help me out?
missing-score
03-24-2004, 12:13 AM
No no no, sorry, should have directed you more. I didnt realise you were a new user (didnt check your post count) so sorry if i seemed a bit unfair. Feel free to put your link back.
Also, I made a mistake in the link, it was meant to be to the posting guidlines, sorry about that also :p
http://www.codingforums.com/postguide.htm
If you read section 2 about topic titles.
As for your question, you will need to use the mysql_connect, mysql_select_db and mysql_query functions.
First lets clean up your form a bit:
<p>
<form action="register.php" method="post">
First Name: <input type="text" name="firstname" maxlength="35" Value="Your first name here...." /><br />
Password: <input type="password" name="password" maxlength="30" /><br />
<input type="submit" name="Submit" value="Register" />
</form>
</p>
(You can put it back in tables later on if you want.)
<?php
$first_name = $_POST['firstname'];
$password = $_POST['password'];
$query = "INSERT INTO `db_table_name` (Password, Email) VALUES ('".$first_name."', '".$password."')";
$link = mysql_connect("localhost", "dbusername", "dbpassword");
mysql_select_db("dbname", $link);
if(mysql_query($query)){
echo "Inserted Data";
} else {
echo "Inserting Data Failed";
}
?>
Hope this will help you a bit
IAMTHEEVILBEAN
03-24-2004, 12:17 AM
Does the php just go right under the form? or in a seperate ducument.
oh and do I need to replace the dbname with the name of my database?
missing-score
03-24-2004, 06:52 PM
It depends.
If you set the action to insert.php (in your form (<form action="insert.php" method="post">) then you would put the content in insert.php file.
You need to replace:
dbusername - Your MySQL username
dbpassword - Your MySQL password
db_table_name - The table name in the database
dbname - The database name.
IAMTHEEVILBEAN
03-25-2004, 01:21 AM
ermmmm
well I put the PHP code you gave me right under the form. I then replaced the values you said and I still got a Inserting Data Failed message.
Do I also need to replace local host or anything else?
Also for the table name....do I just put ID or ID.something?
Steveo31
03-25-2004, 05:58 AM
If you are running mySQL locally, no... you don't need to change localhost or root unless you want to create a user and pwd, so on. The table name just needs to be one word, like ID. No "db.table" format needed.
missing-score
03-25-2004, 09:02 AM
Originally posted by IAMTHEEVILBEAN
Do I also need to replace local host or anything else?
Also for the table name....do I just put ID or ID.something?
When you set up the table in mysql, you gave it a name (correct?), that is the name that needs to go there.
IAMTHEEVILBEAN
03-25-2004, 01:00 PM
Here is what I did
Here is the form...
<p>
<form action="submit.php" method="post">
First Name: <input type="text" name="firstname" maxlength="35" Value="Your first name here...." /><br />
Password: <input type="password" name="password" maxlength="30" /><br />
<input type="submit" name="Submit" value="Register" />
</form>
</p>
And here is the PHP code, which is in a seperate document titled submit.php..
<?php
$first_name = $_POST['firstname'];
$password = $_POST['password'];
$query = "INSERT INTO `ID` (Password, Email) VALUES ('".$first_name."', '".$password."')";
$link = mysql_connect("localhost", "slankydamanky", "**********");
mysql_select_db(" tehdot_com_-_tehdot", $link);
if(mysql_query($query)){
echo "Inserted Data";
} else {
echo "Inserting Data Failed";
}
?>
and yes I have the password in there I just replaced it for obvious reasons. Am I doing anything wrong because it is not working.
missing-score
03-25-2004, 06:38 PM
You need the name of the table, not the ID field (unless your table is called ID, also, is there a space at the start of your DB name?
IAMTHEEVILBEAN
03-25-2004, 09:33 PM
Im sorry but it still doesn't work...lol
I fixed the space...and yes the table is called ID. Do I have to put action="something else" instead of submit?
because the php code file is called submit.php so I figured it would be right.
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.