googlexx Posted June 1, 2009 Share Posted June 1, 2009 So i wrote this script to add a .mdb database to a mysql database but im getting a parse error on line 29... Any ideas? <?php $dbhost = 'localhost'; $dbuser = 'xxx'; $dbpass = 'xxx'; $dbname = 'forum'; $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql'); $conn2 = new COM("ADODB.Connection") or die("Cannot start ADO"); mysql_select_db($dbname); $sql = "SELECT username, money FROM forumuser"; $result = mysql_query($sql); // Microsoft Access connection string. $conn2->Open("DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=C:\Documents and Settings\Brown\Desktop\Trivia\plugins\ST_users.mdb"); $rs = $conn2->Execute("SELECT Money, Username"); while (!$rs->EOF) { $score = $rs->Fields("Money"); $username = $rs->Fields("Username"); while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $username2=$row["username"]; $score2=$row["money"]; if ($username == $username2) { $dbquery = "INSERT INTO $score2 VALUES ('$score')" $dbresult = mysql_query ($dbquery, $conn); } } $rs->MoveNext(); } mysql_free_result($result); $rs->Close(); ?> Quote Link to comment Share on other sites More sharing options...
trq Posted June 1, 2009 Share Posted June 1, 2009 You rmissing a colon from.... $dbquery = "INSERT INTO $score2 VALUES ('$score')" Quote Link to comment Share on other sites More sharing options...
googlexx Posted June 1, 2009 Author Share Posted June 1, 2009 ok that fixed the error but its not update the table: and on the echo part its reading all the values correctly. <?php $dbhost = 'localhost'; $dbuser = 'xxx'; $dbpass = 'xxx'; $dbname = 'forum'; $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql'); $conn2 = new COM("ADODB.Connection") or die("Cannot start ADO"); mysql_select_db($dbname); $sql = "SELECT username, money FROM forumuser"; $result = mysql_query($sql); // Microsoft Access connection string. $conn2->Open("DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=C:\Documents and Settings\Brown\Desktop\Trivia\plugins\ST_users.mdb"); $rs = $conn2->Execute("SELECT Money, Username FROM users"); while (!$rs->EOF) { $score = $rs->Fields("Money"); $username = $rs->Fields("Username"); while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $username2=$row["username"]; $score2=$row["money"]; if ($username == $username2) { mysql_query("UPDATE users SET $score2 = '$username' WHERE $username2 = '$score'"); echo "Importing money from trivia: ".$score." from name: ".$username." to: ".$username2." old score: ".$score2; } } $rs->MoveNext(); } mysql_free_result($result); $rs->Close(); ?> Quote Link to comment Share on other sites More sharing options...
googlexx Posted June 1, 2009 Author Share Posted June 1, 2009 alright, i've managed to get it working except i have one little error... it only updates the first line or the .mdb file.... <?php $dbhost = 'localhost'; $dbuser = 'xxx'; $dbpass = 'xxx'; $dbname = 'forum'; $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql'); $conn2 = new COM("ADODB.Connection") or die("Cannot start ADO"); mysql_select_db($dbname); $sql = "SELECT username, money FROM forumuser"; $result = mysql_query($sql); // Microsoft Access connection string. $conn2->Open("DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=C:\Documents and Settings\Brown\Desktop\Trivia\plugins\ST_users.mdb"); $rs = $conn2->Execute("SELECT Money, Username FROM users"); while (!$rs->EOF) { $score = $rs->Fields("Money"); $username_old = $rs->Fields("Username"); $username = strtolower($username_old); while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $username2_old=$row["username"]; $score2=$row["money"]; $username2 = strtolower($username2_old); if ($username == $username2) { mysql_query("UPDATE forumuser SET money = '$score' WHERE '$username2' = '$username'"); echo "Importing money from trivia: ".$score." from name: ".$username." to: ".$username2." old score: ".$score2; } } $rs->MoveNext(); } mysql_free_result($result); $rs->Close(); ?> 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.