[PHP] Help with code to database please!

Newbie Spellweaver
Joined
May 10, 2004
Messages
24
Reaction score
0
Hey guys, I'd like some help with making a code on a webpage to access a database. The code i have so far doesen't seem to work because it gives me an error and never creates the account. The code i'm using

Config:

<?php

//MSSQL Host IP
$db_host = 'localhost';

//MSSQL Username
$db_user = 'sa';

//MSSQL Password
$db_pass = '';

//MSSQL Database
$db_name = 'redmoon';

$conn = mssql_connect($db_host,$db_user,$db_pass);
mssql_select_db($db_name,$conn);
?>


Addacount.php

<?php

include("config.php");

if (isset($_POST['AddAccount'])) {
if ($_POST['Username'] > "" && $_POST['Password'] > "") {
$validchars = "abcdefghijklmnopqrstuvwxyz0123456789";
$valid = true;

for ($i = 0; $i < strlen($_POST['username']); $i++) {
if (strpos($validchars,strtolower(substr($_POST['username'],$i,1))) === false){
$valid = false;
**
**

for ($i = 0; $i < strlen($_POST['Password']); $i++) {
if (strpos($validchars,strtolower(substr($_POST['Password'],$i,1))) === false){
$valid = false;
**
**

if ($valid == true) {
$query = "SELECT BillID FROM tblBillID WHERE BillID = '".$_POST['Username']."'";
$result = mssql_query($query,$conn);
if (mssql_num_rows($result) > 0) {
echo "<b>Account name in use.</b>";
** else {
$accquery = "INSERT INTO tblBillID (BillID,Password) VALUES('".$_POST['Username']."','".$_POST['Password']."')";
$accresult = mssql_query($accquery,$conn);
echo "<b>Account Added</b>";
**

** else {
echo "<b>You didn't fill out all the required fields.</b>";
**
** else {
echo "dont try to hack me biatch!";
**
echo "<br><br>";
**

?>
<table border="0">

<tr>
<td class="mytext">
<u>Add an Account</u><br>
<form action="addaccount.php" method="post">
<table border="0">
<tr>
<td>Username</td>

<td><input type="text" name="Username" height="5" maxlength="12" style="width: 100px;"></td>
</tr>
<tr>
<td>Password</td>
<td><input type="text" name="Password" height="5" maxlength="10" style="width: 100px;"></td>
</tr>
<tr>
<td></td>

<td><input type="submit" value="Add" name="AddAccount"></td>
</tr>
</table>
</form>
</td>
</tr>
</table

Does anyone see anything wrong with this? Thanks for your time...


~Shoki
 
Initiate Mage
Joined
May 6, 2005
Messages
4
Reaction score
0
last line, </table
missing ">" or wrong copied
just test it, so you know if it works or not
if theres an error, you'll see the line and post it here
for me, i would crypt the password for the database
 
Newbie Spellweaver
Joined
May 10, 2004
Messages
24
Reaction score
0
No such luck, I just copied it to the site wrong. When i load the actual page this appears at the top of the page

"" && $_POST['Password'] > "") { $validchars = "abcdefghijklmnopqrstuvwxyz0123456789"; $valid = true; for ($i = 0; $i < strlen($_POST['username']); $i++) { if (strpos($validchars,strtolower(substr($_POST['username'],$i,1))) === false){ $valid = false; ** ** for ($i = 0; $i < strlen($_POST['Password']); $i++) { if (strpos($validchars,strtolower(substr($_POST['Password'],$i,1))) === false){ $valid = false; ** ** if ($valid == true) { $query = "SELECT BillID FROM tblBillID WHERE BillID = '".$_POST['Username']."'"; $result = mssql_query($query,$conn); if (mssql_num_rows($result) > 0) { echo "Account name in use."; ** else { $accquery = "INSERT INTO tblBillID (BillID,Password) VALUES('".$_POST['Username']."','".$_POST['Password']."')"; $accresult = mssql_query($accquery,$conn); echo "Account Added"; ** ** else { echo "You didn't fill out all the required fields."; ** ** else { echo "dont try to hack me biatch!"; ** echo "

"; ** ?>

and when i enter an ID or Password nothing happens, the same page just reloads.

Maybe you can try for yourself?



I know almost nothing about PHP but I did read a setup guide about how to setup apache and php and I followed it to the dot. What do you mean crypt the password to the database?
 
Initiate Mage
Joined
May 6, 2005
Messages
4
Reaction score
0
account added, no problems
immo pw: test ^^

to crypt it:
MD5('".$_POST['Password']."'); or something
 
Custom Title Activated
Loyal Member
Joined
Dec 31, 2004
Messages
4,091
Reaction score
25
I added an account and it just said nothing :s
 
Newbie Spellweaver
Joined
May 10, 2004
Messages
24
Reaction score
0
I was able to get this to work [Yay] but if anyone can help me with the rest of the PHP for the site [erm!!] i'd be greatful.. maybe even willing to pay? :eh: hit me up at RedmoonSupport on AIM or GMShoki@Hotmail.com on msn !!

daydream.shoki@gmail.com is my email address

I need to code the website to be able to change passwords, change contact info, make a ranking page and that's about it Thanks!!

Glenn