Forum Moderators: coopster
<?
include 'db.php';
$sql = mysql_query("SELECT email_address, username, password FROM users");
$data= mysql_fetch_array($sql);
while($row = mysql_fetch_array($sql)){
foreach($row AS $key => $val){ $$key = stripslashes($val);}
echo "<p>$email_address, $username, $password </p>";
mysql_query("INSERT INTO Test (user_email, username, password, user_regdate) VALUES ($email_address, $username, $password, time())");
echo "added";
}
?> So I query my users table and get the information I want and that is fine. When I loop through the array and echo the data each line comes out as it should do and tells me that it has been 'added'. But when I check the db nothing has been inserted and I cant figure out why.
I get no errors but nothing happens. I've checked the table name and its correct, as well as the capitalisation and thats all fine. I've tried inserting into 2 different tables and it just wont go.
I know its probably something small and stupid I've overlooked but I cant figure it out.
TIA for your help.
You could also echo the insert statement and see if it is formatting correctly.
Here's the mySql_Query method documentation page [us2.php.net] if you want to take a look at some examples.
One more thing:
If you're inserting a string, you need to wrap it with apostrophes. I think your statement is erroring out.
It should be something like... actually the next post took care of that
-=casey=-
[edited by: CaseyRyan at 7:06 pm (utc) on Dec. 6, 2004]
mysql_query("INSERT INTO Test (user_email, username, password, user_regdate) VALUES ('$email_address', '$username', '$password', time())"); I'd suggest putting your query into a variable that you can print for debugging purposes prior to adding. Sounds like you aren't getting your error messages, need some error checking.
basil
instead of ..."VALUES ($var1, time())";
it would be ..."VALUES ($var1, " . time() . ")";
I think MySQL has an equivalent function (possibly UNIX_TIMESTAMP())you *could* use like you have it but I don't think it is called time().
baze
I dont know if any of you are familiar with phpbb but I'm modifying usercp_register and this is a snippet including the bit I added.
$sql = "UPDATE " . USERS_TABLE . "
SET " . $username_sql . $passwd_sql . "user_email = '" . str_replace("\'", "''", $email) ."', user_icq = '" . str_replace("\'", "''", $icq) . "', user_website = '" . str_replace("\'", "''", $website) . "', user_occ = '" . str_replace("\'", "''", $occupation) . "', user_from = '" . str_replace("\'", "''", $location) . "', user_interests = '" . str_replace("\'", "''", $interests) . "', user_sig = '" . str_replace("\'", "''", $signature) . "', user_sig_bbcode_uid = '$signature_bbcode_uid', user_viewemail = $viewemail, user_aim = '" . str_replace("\'", "''", str_replace(' ', '+', $aim)) . "', user_yim = '" . str_replace("\'", "''", $yim) . "', user_msnm = '" . str_replace("\'", "''", $msn) . "', user_attachsig = $attachsig, user_allowsmile = $allowsmilies, user_allowhtml = $allowhtml, user_allowbbcode = $allowbbcode, user_allow_viewonline = $allowviewonline, user_notify = $notifyreply, user_notify_pm = $notifypm, user_popup_pm = $popup_pm, user_timezone = $user_timezone, user_dateformat = '" . str_replace("\'", "''", $user_dateformat) . "', user_lang = '" . str_replace("\'", "''", $user_lang) . "', user_style = $user_style, user_active = $user_active, user_actkey = '" . str_replace("\'", "''", $user_actkey) . "'" . $avatar_sql . "
WHERE user_id = $user_id";$NJsql = mysql_query("SELECT user_password, username FROM phbb_users WHERE user_id = $user_id");
mysql_query("UPDATE users SET password='$user_password' WHERE username='$username'");
Now it finds the right record in the users table but instead of inserting the password it blanks it out and I dont understand why.
$NJsql = mysql_query("SELECT user_password, username
FROM phbb_users WHERE user_id = $user_id");
[b]need to set $user_password = user_password you get from select above. otherwise it doesn't appear to have a value to update below.[/b]
mysql_query("UPDATE users SET password='$user_password' WHERE username='$username'"); baze