bobleny Posted February 18, 2007 Author Share Posted February 18, 2007 Going on the assumption, do to my inexperience with MySQL, that "!$rows" = "$rows = 0", I have changed the script a bit more. Latest version, yet again: <?php if(isset($_POST['sign_username']) == TRUE) { $connect = mysql_connect($database_hostname, $database_username, $database_password); if(!$connect) { $_SESSION['error_message'] = mysql_error(); $_SESSION['error_location'] = "Line: 106"; mysql_close(); sendem(error, .1); die(); } $selectdb = mysql_select_db("testy"); if(!$selectdb) { $_SESSION['error_message'] = mysql_error(); $_SESSION['error_location'] = "Line: 116"; mysql_close(); sendem(error, .1); die(); } $query = mysql_query("SELECT `name` FROM `users` WHERE `name`='{$_POST['sign_username']}'"); if(!$query) { $_SESSION['error_message'] = mysql_error(); $_SESSION['error_location'] = "Line: 126"; mysql_close(); sendem(error, .1); die(); } $rows = mysql_num_rows($query); if(!$rows) { if($_POST['sign_password'] == $_POST['sign_varpassword']) { $md5 = md5($_POST['sign_password']); $sign_password = SHA1($md5); $sign_username = $_POST['sign_username']; $sign_lvl = "Super Noob"; $sign_date = date('l, F jS\, Y'); $query = mysql_query("INSERT INTO `users` (`name`, `password`, `level`, `signup`) VALUES ('{$sign_username}','{$sign_password}','{$sign_level}','{$sign_date}'"); if(!$query) { $_SESSION['error_message'] = mysql_error(); $_SESSION['error_location'] = "Line: 156"; mysql_close(); sendem(error, .1); die(); } else { mysql_close(); $_SESSION['now_sign'] = TRUE; sendem(signup, .1); } } else { $_SESSION['wrong_sign_password'] = TRUE; sendem(signup, .1); } } else { $_SESSION['wrong_sign_username'] = TRUE; sendem(signup, .1); } } ?> My new error: 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 '' at line 1 My script returned "Line: 156" which is this statement: <?php $query = mysql_query("INSERT INTO `users` (`name`, `password`, `level`, `signup`) VALUES ('{$sign_username}','{$sign_password}','{$sign_level}','{$sign_date}'"); if(!$query) { $_SESSION['error_message'] = mysql_error(); $_SESSION['error_location'] = "Line: 156"; mysql_close(); sendem(error, .1); die(); } else { mysql_close(); $_SESSION['now_sign'] = TRUE; sendem(signup, .1); } ?> Quote Link to comment Share on other sites More sharing options...
desithugg Posted February 18, 2007 Share Posted February 18, 2007 Access denied for user 'www-data'@'localhost' (using password: NO) that means that the user was denied access to the database are you including the config.php or whatever file connects to the database and is it right. Quote Link to comment Share on other sites More sharing options...
superuser2 Posted February 18, 2007 Share Posted February 18, 2007 On line 156 we're going to take a look at the query that is actually run: edit->cut the part in quotes and set $sql right before the query to that value. Then change the query to mysql_query($sql). Right between the query and $sql, let's do die($sql) and see what it shows us. Quote Link to comment Share on other sites More sharing options...
bobleny Posted February 18, 2007 Author Share Posted February 18, 2007 Uh, I'm sorry superuser2, I don't understand what your asking me to try.... And desithugg, I am past that part now, lol Quote Link to comment Share on other sites More sharing options...
superuser2 Posted February 18, 2007 Share Posted February 18, 2007 Change $query = mysql_query("INSERT INTO `users` (`name`, `password`, `level`, `signup`) VALUES ('{$sign_username}','{$sign_password}','{$sign_level}','{$sign_date}'"); to this $sql = "INSERT INTO `users` (`name`, `password`, `level`, `signup`) VALUES ('{$sign_username}','{$sign_password}','{$sign_level}','{$sign_date}'"; die($sql); $query = mysql_query($sql); Run it, it should give you the sql statement. See if everything looks right there. If not, fix it and take out the die($sql) line and the query will run again. Quote Link to comment Share on other sites More sharing options...
bobleny Posted February 18, 2007 Author Share Posted February 18, 2007 Wow! That worked! How cool! Thanks!!! I don't understand though... whats the difference between this: <?php $sql = "INSERT INTO `users` (`name`, `password`, `level`, `signup`) VALUES ('{$sign_username}','{$sign_password}','{$sign_level}','{$sign_date}'"; $query = mysql_query($sql); ?> and this?: <?php $query = mysql_query(INSERT INTO `users` (`name`, `password`, `level`, `signup`) VALUES ('{$sign_username}','{$sign_password}','{$sign_level}','{$sign_date}'); Thanks to everyone! Quote Link to comment Share on other sites More sharing options...
superuser2 Posted February 18, 2007 Share Posted February 18, 2007 There is no difference. We used it so that we could isolate the sql statement and echo it so we see what's wrong with it. So everything is working now? Quote Link to comment Share on other sites More sharing options...
bobleny Posted February 18, 2007 Author Share Posted February 18, 2007 Yes all is good, however, after I got it to work with this: <?php $sql = "INSERT INTO `users` (`name`, `password`, `level`, `signup`) VALUES ('{$sign_username}','{$sign_password}','{$sign_level}','{$sign_date}'"; $query = mysql_query($sql); ?> I tried this: <?php $query = mysql_query(INSERT INTO `users` (`name`, `password`, `level`, `signup`) VALUES ('{$sign_username}','{$sign_password}','{$sign_level}','{$sign_date}'); I got the syntax error again... However, it does work and I appreciate your help! Quote Link to comment Share on other sites More sharing options...
superuser2 Posted February 18, 2007 Share Posted February 18, 2007 On your second, you have to put it in double-quotes, not just loose. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.