Jump to content

I might be a newbie...


TeaseM

Recommended Posts

you still have one of the same errors we've pointed out, and I think a new one

 $sql = "INSERT INTOusers(user_name, user_pass, user_email ,user_date,);   // extra comma after date, and why is there a semicolon in the query?VALUES('" . mysql_real_escape_string($_POST['user_name']) . "',  '" . sha1($_POST['user_pass']) . "',  '" . mysql_real_escape_string($_POST['user_email']) . "',NOW())";

I'm pretty sure we suggested echoing out the query. you should do that to see that it's formatted correctly. Also, you can test it by running it in phpMyAdmin and tweaking it there to make sure you've got it just right, rather than having to debug through a form all the time.

Link to comment
Share on other sites

I tried to echo out the query and all I still get is "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') VALUES"So. Could we please start to see where that problem is and maybe solve it? I think it is essential to do that first since that is my main problem at the moment. I use Dreamweaver to write the code and I don't get any syntax errors in there so I'm pretty much clueless at the moment. Still thank you for your willingness to help me out!

Link to comment
Share on other sites

I tried to echo out the query and all I still get is "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') VALUES"So. Could we please start to see where that problem is and maybe solve it? I think it is essential to do that first since that is my main problem at the moment. I use Dreamweaver to write the code and I don't get any syntax errors in there so I'm pretty much clueless at the moment. Still thank you for your willingness to help me out!
did you read my post? I just told you two things to fix, and a couple ways to debug. You didn't say at all what you tried? did you actually echo out your query and look at it? did you test in phpMyAdmin?
echo $sql;

Link to comment
Share on other sites

Sorry. I was a bit unclear. And. I missed the thing you wrote about the semicolon. It workds. However. I got something strange instead. When I echoed out the query I got told there was a duplicate of the username from the form.I somehow managed to get around it though so I guess I'm good for now. Thank you very much for all the help, I guess it wasnt easy getting me to understand all the way.You really helped a lot. Thank you! The code that actually works in case you have some comments. <?phpsession_start();$server ='localhost';$username ='MYUSERNAME';$password ='MYPASSWORD';$database ='TEST'; if(!mysql_connect($server, $username, $password)){exit('Error: could not establish database connection');}if(!mysql_select_db($database)){exit('Error: could not select the database');} echo '<h3>Sign up</h3><br />'; if($_SERVER['REQUEST_METHOD'] != 'POST'){ //Form echo '<form method="post" action=""> Username: <input type="text" name="user_name" /><br /> Password: <input type="password" name="user_pass"><br />Password again: <input type="password" name="user_pass_check"><br />E-mail: <input type="email" name="user_email"><br /> <input type="submit" value="Add category" /> </form>';}else{ $errors = array(); if(isset($_POST['user_name'])){//the user name existsif(!ctype_alnum($_POST['user_name'])){$errors[] = 'The username can only contain letters and digits.';}if(strlen($_POST['user_name']) > 30){$errors[] = 'The username cannot be longer than 30 characters.';}}else{$errors[] = 'The username field must not be empty.';} if(isset($_POST['user_pass'])){if($_POST['user_pass'] != $_POST['user_pass_check']){$errors[] = 'The two passwords did not match.';}}else{$errors[] = 'The password field cannot be empty.';} if(!empty($errors)) {echo 'Uh-oh.. a couple of fields are not filled in correctly..<br /><br />';echo '<ul>';foreach($errors as $key => $value) {echo '<li>' . $value . '</li>'; }echo '</ul>';}else{ $sql = "INSERT INTOusers(user_name, user_pass, user_email ,user_date)VALUES('" . mysql_real_escape_string($_POST['user_name']) . "', '" . sha1($_POST['user_pass']) . "', '" . mysql_real_escape_string($_POST['user_email']) . "',NOW())"; $result = mysql_query($sql);echo $sql;if(!$result){//something went wrong, display the errorecho 'Something went wrong while registering. Please try again later.<br />';echo mysql_error(); //debugging purposes, uncomment when needed}else{echo 'Succesfully registered.';}}} ?>

Edited by TeaseM
Link to comment
Share on other sites

I got something strange instead. When I echoed out the query I got told there was a duplicate of the username from the form.
I'm not sure what you mean. It would be helpful to provide the actual error message you received, and where in the code the error was referencing, along with that portion of the code. Then we could probably try and fix it.
Link to comment
Share on other sites

I managed to solve it myself actually. I messed up a bit and when I reviewed my code I saw that I actually made the same query twice. Hence the duplicate in the DB table wich I don't allow:-)My bad. Again. Thank you!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...