zero-perfoliate
zero-perfoliate

Author Topic: php novice - inserting into a database  (Read 359 times)

Offline assid

  • New PHP Members
  • Posts: 4
  • Karma: +0/-0
php novice - inserting into a database
« on: April 09, 2010, 11:10:42 PM »
ok before i ask anything, im a complete novice so please keep that in mind.

im currently creating  registration page, i have the page "register.php" with all the imput forms etc, now i need the information sent to my database "gangste5_GAME".

ive been using this code:
Code: [Select]
<?php

mysql_connect
("localhost""gangste5_assid""password") or die(mysql_error());

mysql_select_db("gangste5_GAME") or die(mysql_error());

if (
$_POST['form_submitted'] == '1') {
} else {

}
?>

but i get the error message "access denied" or something to that extent. i found the code on a tutorial website, but for some reason, it hasnt asked me to enter the table name (which is "users" by the way) into the information, so im pretty sure that is the problem. but i have no idea what to do about it... could somebody please help? if you can, could you please post the whole code to enter information into the database? not just the table name part of it.

Offline RoseKnight

  • PHP Help Guru's
  • ****
  • Posts: 52
  • Karma: +0/-0
Re: php novice - inserting into a database
« Reply #1 on: April 10, 2010, 04:59:02 PM »
mysql_select_db("gangste5_GAME") or die(mysql_error());

should be

@mysql_select_db("gangste5_GAME") or die(mysql_error());

hotnoob

  • Guest
Re: php novice - inserting into a database
« Reply #2 on: April 10, 2010, 08:14:20 PM »
i don't think that is the issue... However, i RARELY touch connection stuff :P

So, this is just what i use, So if it doesn't work with this code, than the information you are using is wrong, or the database/server/php is configured incorrectly.

Code: [Select]
<?php

$hostname_DB_Connect 
"HostName"//example, localhost, or google.ca
$username_DB_Connect "UserName"//the login username to access the DB
$password_DB_Connect "PassWord"//the password to access the DB... don't be surprised if it isnt stared.. lol :P
$database_DB_Connect"DataBaseName"//the name of the database.



$DB_Connect mysql_connect($hostname_DB_Connect$username_DB_Connect$password_DB_Connect) or trigger_error(mysql_error(),E_USER_ERROR);
mysql_select_db($database_DB_Connect) or die(mysql_error());
?>


Offline assid

  • New PHP Members
  • Posts: 4
  • Karma: +0/-0
Re: php novice - inserting into a database
« Reply #3 on: April 13, 2010, 01:50:40 PM »
thanks for the replies.
hotnoob, ive tried your code, and i no longer get any error messages (just a white screen at the moment, which is what is supposed to happen yes?) but it doesnt seem to insert the new user into my database... anybody have any idea why?

my "verify code is exactly as hotnoob posted, but with my information added into it.
my "register.php" code is as follows:

Code: [Select]
<html>
<BODY BGCOLOR="black"
   TEXT=red
   LINK=red
   VLINK=red
   ALINK=red
   >
<h1>Register</h1>
<table><tr>

<form action="verify.php" method="post" name="register">

<td width="200">Username:</td>
<td width="247"><input name="username" size="30" autocomplete="off" value="" type="text" /></td>

</tr><tr>

<td>Password:</td>
<td><input name="password" size="30" type="password" /></td>

</tr>
<td>Re-Enter Password:</td>
<td><input name="password" size="30" type="password" /></td>

</tr>
<tr>

<td>Email Address:</td>
<td><input name="firstname" size="30" type="text" /></td>

</tr>
</table>
<input type="hidden" name="form_submitted" value="1"/>




<p><input type="submit" class="button" value="Register" /></p>
</form>

</body>
</html>

 

zero-perfoliate