Jump to content

TeaseM

Members
  • Posts

    16
  • Joined

  • Last visited

TeaseM's Achievements

Newbie

Newbie (1/7)

0

Reputation

  1. 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!
  2. 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.';}}} ?>
  3. 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!
  4. Ok. Here one of the codes I can't get to work. It is mostly taken from a tutorial I found online and is solely for my educational purpose. <?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);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.';}}} ?> Might be a bit hard to read here but anyhow. There it is.
  5. That is part of the problem. I don't get an error message. Everything looks fine but nothing gets inserted to the Database. And When I try to get it to do anything after the query, say let me know that it worked i.e. echo '1 entry added'; I get this "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"instead The code I use is the same as I've posted before in this topic.
  6. The final code is the same. I just added a closing bracket after the NOW() statement. Still can't get the script to write to the DB. Wich is my main problem.
  7. Hi again all you helpful. Sorry for my late reply on my own topic. It really doesn't matter what I do in the code. I tried it several times and either I get the synax failure or it just doens't do anything to the database.I tried all of the things you tipped me about here and I also tried to re write the whole script again and still nothing happens to de DB.
  8. Yes. I saw that after my post. Removed it and the problem is still there.
  9. This is what I get when trying to post information using INSERT INTO and VALUES.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 ') VALUESI use the same syntax as in the tutorial and as far as I know it should work. Yes?This is the code I use, there is more to it but here is where the syntax problem comes in. $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); I'm using a form to retrieve the data from the user.
  10. Of course. I just didn't want to publish it here:-) I have put my username and my password in there when I run it on my server.
  11. Hmmm. Tried it once again without my editing of the code more then database and table names and now I can't even get the php to connect to the server. This is getting wierd. I don't even get an sql_error message. $con = mysql_connect('localhost','MyUserName',''MyPassword);if (!$con);{die('could not connect:' .mysql_error());}
  12. Yes. I tried it and it says I have a problem with my syntax and to chek the reference on my sql version... I don't see where the syntax would fail even when I check the reference though. I use MySQL 5.5.20. The syntax that is causing the problem is after the VALUES or SET statement.
  13. Not really. Nothing happens at all when I run the page. And the database, even when I create it in PHPMyAdmin gets updated with information.
  14. http://www.w3schools.com/php/php_mysql_create.aspandhttp://www.w3schools.com/php/php_mysql_insert.asp
  15. I used the one where you set up a HTML form and then use a php script to INSERT INTO the sql database. The problem is that my php wont communicate with my sql server. I also tried to getthe php to CREATE DATABASE (wich worked), CREATE TABLE (wich wont work).
×
×
  • Create New...