SitePoint Sponsor

User Tag List

Results 1 to 13 of 13
  1. #1
    SitePoint Zealot
    Join Date
    Sep 2003
    Location
    NY
    Posts
    141
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Can't add to MySQL, doing two dbs in one script

    Here's my code... (the part that's causing error).
    Code:
    $query = "SELECT handle FROM users WHERE (handle='$handle')";
    $checkhandle = mysql_query($query);
    if(mysql_num_rows($checkhandle))
    {teX("$handle already exists, please click your browser's back button and choose a different user name.","verify2");}
    else
    {
    		$im = $_POST['imname']."|".$_POST['imservice'];
    		
    		include('i_aeskey.php'); //sets $AES_key variable
    		
    		$query = "INSERT INTO `users` ( `email` , `name` , `phone` , `im` , `date` , `password` , `handle` )
    					VALUES ( '$email', '$name', '$phone', '$im', CURDATE( ) , AES_ENCRYPT('$pass','$AES_key'), '$handle' );";
    		
    
    		//Add a forum account for user...
    
    			$rzdb = mysql_connect('localhost', 'username', 'password');
    			mysql_select_db("haydur_phpb1");
    			$getmax = mysql_query("SELECT MAX(user_id) FROM phpbb_users", $rzdb);
    			$user_id = $getmax + 1;		
    			$rccreg = mysql_query("INSERT INTO phpbb_users ( 'user_id', `user_email` , `user_regdate` , `user_password` , `username` ) VALUES ('$user_id', '$email', time() , md5($password), '$handle' ), $db2);", $rzdb);
    			mysql_close($rzdb);
    
    		//End forum edit
    
    		$result = mysql_query($query); 
    
    		if($result) 
    			{teX("User $handle has been added.","verify2");}
    		else
    			{teX("Error. If problem persists please contact system administrator.","caution");}
    	}
    }
    When this is run it shows the last error message (Error. If problem persists...). I know that the problem is in the forum edit area because I just added it and the script works fine without it.

    Also note that the user_id variable is a phpBB field unique to each user. For some reason it is scriptically incremented instead of being auto incremented. And that's what I need to do, in addition to getting the data written to the table.
    Last edited by neodur; Dec 22, 2004 at 22:52.

  2. #2
    SitePoint Wizard swdev's Avatar
    Join Date
    Oct 2004
    Location
    UK
    Posts
    1,053
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Does your database haydur_phpb1 really exist on a different MySQL server to all the other tables / databsae you use?

    I would guess not, so you don't need to connect again to add a fiorum account. All you need to do is to select the new database and run the query, not forgetting to reselect the original database to rung the existing queries.#

    Hope this helps

  3. #3
    SitePoint Zealot
    Join Date
    Sep 2003
    Location
    NY
    Posts
    141
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Did that... didn't work!

    I did what I think you said...
    Code:
    	// Add a forum account for user...
    
    	mysql_select_db("haydur_phpb1");
    	$getmax = mysql_query("SELECT MAX(user_id) FROM phpbb_users");
    	$user_id = $getmax + 1;		
    	mysql_query("INSERT INTO phpbb_users ( `user_email` , `user_regdate` , `user_password` , `username` ) VALUES ( '$email', time() , md5($password), '$handle' ),");
    	mysql_select_db("haydur_rccx");
    
    	//End forum edit
    I don't get any errors, but nothing gets written to the forum db. ?!@?!@$%?
    Last edited by neodur; Dec 23, 2004 at 10:21.

  4. #4
    SitePoint Addict Adam A Flynn's Avatar
    Join Date
    Jul 2004
    Location
    Canada
    Posts
    251
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try this:
    mysql_query("INSERT INTO phpbb_users ( `user_email` , `user_regdate` , `user_password` , `username` ) VALUES ( '$email', time() , md5($password), '$handle' ),") or print(mysql_error());

    That'll print any MySQL error out for you.

  5. #5
    SitePoint Zealot
    Join Date
    Sep 2003
    Location
    NY
    Posts
    141
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here's the modified code:
    Code:
    // Add a forum account for user...
    
    	mysql_select_db("haydur_phpb1");
    	$getmax = mysql_query("SELECT MAX(user_id) FROM phpbb_users");
    	$user_id = $getmax + 1;
    	$new_password = md5($password);	
    	mysql_query("INSERT INTO phpbb_users ( `user_email` , `user_regdate` , `user_password` , `username` ) VALUES ( '$email', time(), '$new_password', '$handle' ),") or print(mysql_error());;
    	mysql_select_db("haydur_rccx");
    
    //End forum edit
    And here's the 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 '(), 'd41d8cd98f00b204e9800998ecf8427e', 'fsucker' ),' at line 1 Error. If problem persists please contact system administrator.

  6. #6
    <? echo "Kick me"; ?> petesmc's Avatar
    Join Date
    Nov 2000
    Location
    Hong Kong
    Posts
    1,508
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    You can't be time() inside the query, so

    PHP Code:
    mysql_query("INSERT INTO phpbb_users ( `user_email` , `user_regdate` , `user_password` , `username` ) VALUES ( '$email', " time() . ", '$new_password', '$handle' ),") or print(mysql_error());; 
    Try that,
    -Peter

  7. #7
    SitePoint Zealot
    Join Date
    Sep 2003
    Location
    NY
    Posts
    141
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Error!

    Did exactly that, here's the error now"
    Code:
    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
    But, the other db activity on the bottom goes through... User gets added.

  8. #8
    <? echo "Kick me"; ?> petesmc's Avatar
    Join Date
    Nov 2000
    Location
    Hong Kong
    Posts
    1,508
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    mysql_query("INSERT INTO phpbb_users ( `user_email` , `user_regdate` , `user_password` , `username` ) VALUES ( '$email', '" time() . "', '$new_password', '$handle' )") or print(mysql_error());; 
    -Peter

  9. #9
    SitePoint Zealot
    Join Date
    Sep 2003
    Location
    NY
    Posts
    141
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok... thank God! It's working now... writing everything to the db... except it doesn't ge the user_id field properly, and puts a zero there, instead of incrementing the largest number... ???
    Last edited by neodur; Dec 23, 2004 at 18:15.

  10. #10
    SitePoint Wizard swdev's Avatar
    Join Date
    Oct 2004
    Location
    UK
    Posts
    1,053
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That's becasue, although you calculate the next user_id ($user_id) you never use that value in the INSERT SQL statement. Try adding the column name and the value to the correct places in the SQL statment.

  11. #11
    SitePoint Zealot
    Join Date
    Sep 2003
    Location
    NY
    Posts
    141
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok, sorry about that.

    Everything is working. Except for that I cannot get the right value of user_id from the table. It's a medium integer, btw.

    I tried modifying it to the following, but it doesn't work...
    Code:
    $sql = mysql_query("SELECT MAX(user_id) AS total FROM phpbb_users");
    $user_id = $row['total'] + 1;
    It simply doesn't get the value...

    (For some reason it keeps reading the value of user_id as 3, where as it already has a record number 7.)

  12. #12
    SitePoint Wizard swdev's Avatar
    Join Date
    Oct 2004
    Location
    UK
    Posts
    1,053
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Merry Xmas to you

    Whenever you call the mysql_query function, you must call one of the mysql_fetch_* functions to actually get the data.

    In this one particular case, as you are retrieving only 1 row and 1 cell, you can use the mysql_result call like this

    PHP Code:
      $result mysql_query("SELECT MAX(user_id) AS total FROM phpbb_users");
      
    $user_id  mysql_result($result00); 
    Hope this helps

  13. #13
    SitePoint Zealot
    Join Date
    Sep 2003
    Location
    NY
    Posts
    141
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Merry Xmas to you too! :santa1:

    That worked like a charm... thanks alot


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •