 <?php 

$smsdb  =  mysql_connect("localhost", "root", "") or die(mysql_error());
	 $date= date("Y-m-d h:i:s");

	
							
							
							
								mysql_query("USE patmatt",$smsdb);
								$user_query=mysql_query("select * from  sms_in where used='0'")or die(mysql_error());
								$num_row = mysql_num_rows($user_query);
									
									if( $num_row > 0 ) {
									while($row=mysql_fetch_array($user_query)){
									
								
			 $smsid=$row['id'];
								
			 $message=$row['sms_text'];
		
		
			$phone=$row['sender_number'];
			
		  	$arrivaltime=$row['sent_dt'];
			$transactioncode=$row['code'];

	
			$amount=$row['amount'];
			$firstname=$row['firstname'];

			$lastname=$row['lastname'];
		
			$type="received";
			$status=$row['used'];
			$createdate=$date;
											//$query=("insert INTO mpesa (message,phone,arrivaltime,transactioncode,amount,firstname,lastname,type,status,createdate) values($message,$phone,$arrivaltime,$transactioncode,$amount,$firstname,$lastname,$type,$status,$createdate)");
				
				
				mysql_query("USE robipos",$smsdb);
				$query=("insert INTO mpesa (message,phone,arrivaltime,transactioncode,amount,firstname,lastname,type,status,createdate) values('$message','$phone','$arrivaltime','$transactioncode','$amount','$firstname','$lastname','$type','$status','$createdate')");

							
							$result = mysql_query($query);
								
									
									
								
									if($result) {
								mysql_query("USE lnm",$smsdb);
										mysql_query("UPDATE sms_in SET used='1' WHERE id='$smsid'");

									echo "all data saved";
									}
									else{
							echo "No all data not saved";
								}
								}
								
								
								
								
								
								
								
								
									}else{
										
																	echo "No  data avaialable";

										
									}

							?>