I've copied the code exactly and adapted it to being on my machine...I am getting no errors etc but when I try register nothing get's entered into my database :-S
Are there any common issues or code pages you want to look at?
Thank you, love the tutorials!!
No data being populated in database..
Re: No data being populated in database..
I'm not sure I understand what the problem is.
Is this your code not inserting info in the db or is your actual db malfunctioning?
If it's your code, post it here.
Is this your code not inserting info in the db or is your actual db malfunctioning?
If it's your code, post it here.
Re: No data being populated in database..
Probably something wrong with your query.
Re: No data being populated in database..
So yea I'll hit register and I'll get no errors or anything, just doesn't store the registered user in my database at all..
Here is my code...
REGISTER.PHP
Here is my code...
REGISTER.PHP
<?php include ('core/init.inc.php'); $errors = array(); if (isset($_POST['username'], $_POST['password'], $_POST['repeat_password'])){ if (empty($_POST['username'])){ $errors[] = 'The username cannot be empty'; } if (empty($_POST['password']) || empty($_POST['repeat_password'])){ $errors[] = 'The password cannot be empty.'; } if ($_POST['password'] !== $_POST['repeat_password']){ $errors[] = 'Passwords not the same.'; } if (user_exists($_POST['username'])){ $errors[] = 'The username already exists'; } if (empty($errors)){ add_user($_POST['username'], $_POST['password']); $_SESSION['username'] = htmlentities($_POST['username']); header('Location: protected.php'); die(); } } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <div> <?php if (empty($errors) === false){ ?> <ul> <?php foreach ($errors as $error){ echo "<li>{$error}</li>"; } ?> </ul> <?php } ?> </div> <form action"" method="post"> <p> <label for="username">Username:</label> <input type="text" name="username" id="username" value="<?php if (isset($_POST['username'])) echo htmlentities($_POST['username']); ?>" /> </p> <p> <label for="password">Password:</label> <input type="password" name="password" id="password" /> </p> <p> <label for="repeat_password">Repeat Password:</label> <input type="password" name="repeat_password" id="repeat_password" /> </p> <p> <input type="submit" value="Register" /> </p> </body> </html>INIT.INC.PHP
<?php session_start(); echo $_SERVER['SCRIPT_NAME']; ?>USER.INC.PHP[/u]
<?php //checks if the given username exists in the database function user_exists($user){ $user = mysql_real_escape_string($user); $total = mysql_query("SELECT COUNT('user_id') FROM 'users' WHERE 'user_name' = '{$user}'"); return (mysql_result($total, 0) === '1') ? true : false; } // checks if the given username and password combination is valid function valid_credentials($user, $pass){ $user = mysql_real_escape_string($user); $pass = sha1($pass); $total = mysql_query("SELECT COUNT('user_id') FROM 'users' WHERE 'user_name' = '{$user}' AND 'user_password' = '($pass)'"); return (mysql_result($total, 0) == '1') ? true : false; } //adds a user to the database. function add_user($user, $pass){ $user = mysql_real_escape_string(htmlentities($user)); $pass = sha1($pass); mysql_query("INSERT INTO 'users' ('user_name', 'user_password') VALUES ('{$user}','{$pass}')"); } ?>
Last edited by jacek on Mon Nov 21, 2011 6:02 pm, edited 2 times in total.
Reason: code tags...
Reason: code tags...
Re: No data being populated in database..
please, use the code tags.
[syntax=php]<?php code in here ?>[/syntax]
-
- Posts: 534
- Joined: Thu May 05, 2011 8:19 pm
Re: No data being populated in database..
Im going to hazard a guess.. Have you connected to the database?
<?php mysql_connect(host, username, password); mysql_select_db(database_name); ?>if you have, then do:
<?php echo mysql_error(); ?>Anywhere below where you do your call in add_users() function
I don't like to brag, but I wasn't circumcised. I was circumnavigated. 
Want to learn something new? Or maybe reinforce what you already know? Or just help out? Please subscribe to my videos: http://goo.gl/58pN9

Want to learn something new? Or maybe reinforce what you already know? Or just help out? Please subscribe to my videos: http://goo.gl/58pN9
Re: No data being populated in database..
Pretty common problem nowadays.
mysql_query("INSERT INTO 'users' ('user_name', 'user_password') VALUES ('{$user}','{$pass}')");You're using quotes around the table and field names whereas you should use backticks (or nothing, if you prefer).
mysql_query("INSERT INTO `users` (`user_name`, `user_password`) VALUES ('{$user}','{$pass}')");
Please check out my CodeCanyon items.