By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,968 Members | 1,620 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,968 IT Pros & Developers. It's quick & easy.

mysql-php error message

P: 3
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $todb            = 'localhost';
  3. $fromdb          = 'test1.deftlogic.com';
  4. $smstable        = sms;
  5. $paid_bribetable = bd_paidabribe;
  6. $countertable    = tab3;
  7.  
  8. //connecting to the local database
  9. $con = mysql_pconnect($todb, 'dtestfor_ipab', 'IaMzieU3#b%$'); //servername,username,password
  10. if (!$con) {
  11.     die("couldn't connect");
  12. }
  13.  
  14. mysql_select_db("dtestfor_IPAB_db", $con); //databasename
  15.  
  16. $rs2 = mysql_query("select sms_index as 'ma' from " . $countertable . "", $con);
  17.  
  18. $max = mysql_fetch_assoc($rs2);
  19.  
  20. print_r($max['ma']);
  21. //connecting to the local database ends
  22. //connecting to the remote database
  23. $dblink2 = mysql_pconnect($fromdb, 'dtestone_ipab', '!*D-pD)g5)FJ'); // connect server 2
  24.  
  25. mysql_select_db('dtestone_db_2025', $dblink2); // select database 2
  26.  
  27. //echo $dblink2;
  28.  
  29. if (!$dblink2) {
  30.     echo "not connected";
  31. } else
  32.     echo "db2 connected";
  33.  
  34. $rs    = mysql_query("select Message from " . $smstable . " where sms_index >" . $max['ma'], $dblink2);
  35. $msgs  = mysql_fetch_assoc($rs);
  36. $msgs2 = array();
  37. //connecting to the remot database ends
  38. //connecting to the local database
  39. do {
  40.     array_push($msgs2, $msgs['Message']);
  41. } while ($msgs = mysql_fetch_assoc($rs));
  42.  
  43. $con = mysql_pconnect($todb, 'dtestfor_ipab', 'IaMzieU3#b%$'); //servername,username,password
  44. if (!$con) {
  45.     die("couldn't connect");
  46. }
  47.  
  48. mysql_select_db("dtestfor_IPAB_db", $con); //databasename
  49.  
  50. foreach ($msgs2 as $m) {
  51.     $m2 = explode(",", $m);
  52.     mysql_query("insert into " . $paid_bribetable . "(city,dept,amount) values('" . $m2[0] . "','" . $m2[1] . "','" . $m2[2] . "')", $con);
  53. }
  54. //connecting to the local database ends
  55. //connecting to the remot database  
  56. $dblink2 = mysql_pconnect($fromdb, 'dtestone_ipab', '!*D-pD)g5)FJ'); // connect server 2
  57.  
  58. mysql_select_db('dtestone_db_2025', $dblink2); // select database 2
  59.  
  60. $rs4  = mysql_query("select max(sms_index) as 'ma' from " . $smstable . "");
  61. $max2 = mysql_fetch_assoc($rs4);
  62. //connecting to the remot database ends
  63. //connecting to the local database
  64. $con  = mysql_pconnect($todb, 'dtestfor_ipab', 'IaMzieU3#b%$'); //servername,username,password
  65. if (!$con) {
  66.     die("couldn't connect");
  67. }
  68.  
  69. mysql_select_db("dtestfor_IPAB_db", $con);
  70.  
  71. mysql_query("UPDATE '" . $countertable . "' SET sms_index = " . $max2['ma']);
  72. //connecting to the local database ends
  73. ?>

Hi all.....i am trying to get the values from sms table which is on one server and insert those values into another table in another server. while doing that i'm using another table that will check the max value in sms table accordingly it will insert the values. all the code seems fine but when i execute the code i'm getting the error message as Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource on (url) in line no 37,45,67. i think the wrong is there with the syntax. any help will be much appreciated.....thanks in advance...
Apr 25 '12 #1
Share this Question
Share on Google+
4 Replies


100+
P: 1,059
everything is right with syntax but some thing is wrong with your Query that you didnt write.

here is it
Expand|Select|Wrap|Line Numbers
  1. $Query="...";
  2. $res=mysql_query($Query);//here is Query is incorrect or query is not suppose to return any resource such as update query, insert query or delete query. 
  3. //now if you try this
  4. $row=mysql_fetch_assoc($res); // you will get error.
  5.  
  6.  
  7.  
Apr 25 '12 #2

Dormilich
Expert Mod 5K+
P: 8,639
Id hazard a guess at 'ma' (invalid context for a string)
Apr 25 '12 #3

P: 3
@dormilich 'ma' is just used as a temporary value to store the details collected from the table...
Apr 25 '12 #4

Dormilich
Expert Mod 5K+
P: 8,639
check the SQL error message then. I wouldn’t be the least bit surprised if that’s the position where the error is occuring.
Apr 25 '12 #5

Post your reply

Sign in to post your reply or Sign up for a free account.