Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

Works in localhost but not in remote host

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

Works in localhost but not in remote host

Postby MikeSpider » Fri Jun 07, 2013 3:16 am

Hi guys,

I have this script looping through database data:

Code: Select all
foreach ($getService->data as $s){
 echo " <p>Name: ".$s['name]."</p>"
 echo "<img style=\"cursor:pointer;\" src=\"images/icons/mapicon.png\"
            width=\"32\"  alt=\"Find in map\" onclick=\"alert('".$s['address']."')\">
                         <img style=\"cursor:pointer;\" src=\"images/icons/mapiconDis.png\"
                               width=\"32\" alt=\"Close map\"  onclick=\"UnloadMap();\">";


}


Everything works fine in my localhost but in remote host the alert() function only works for the first
item displayed (first iteration), the others the onclick does not work. However, if i remove the parameters inside the alert()
Code: Select all
... onclick=\"alert()\"  ...


it does work!

I've been pulling my hairs on this one 2 days in a row.
Any help?
Will be very thankful.

Mike
MikeSpider
New php-forum User
New php-forum User
 
Posts: 49
Joined: Sun Feb 05, 2012 12:48 pm

Re: Works in localhost but not in remote host

Postby macek » Mon Jun 10, 2013 12:44 am

Hi,

send us a piece of source code. At least the first images ,.. thanks
User avatar
macek
php-forum Active User
php-forum Active User
 
Posts: 277
Joined: Wed Aug 25, 2010 10:42 am

Re: Works in localhost but not in remote host

Postby MikeSpider » Thu Jun 13, 2013 3:22 pm

macek wrote:Hi,

send us a piece of source code. At least the first images ,.. thanks


Thanks for replying. I dont understand what you mean by "the first images" The images appear fine. no problem.


the PHP code is:


Code: Select all

 public function getAllServices($type){
        try{
           
             if($type == "PickUP"){
                 $serviceTbl = 'pickUpServices';
             }elseif($type == "Delivery"){
                   $serviceTbl = 'deliveryServices';
             }elseif($type == "Dining"){
                   $serviceTbl = 'diningServices';
             }
           
            $sql = "SELECT * FROM $serviceTbl ORDER BY name ASC";
            $result = $this->db->mysqli->query($sql);
           
            if(!$result){
               
                       throw new Exception("Query failed: " . $sql . " - " . $this->db->mysqli->error);

                }else{
                    while ($s = $result->fetch_assoc()){
                        $this->data[] = array('id' => $s['id'],
                                              'name' => $s['name'],
                                              'description' => $s['description'],
                                              'address' => $s['address'],
                                              'phone' => $s['phone'],
                                              'email' => $s['email'],
                                              'website' => $s['website'],
                                              'date' => $s['date']);   
                           
                       
                    }
                    return $this->data;
                }
                                       
        } catch (Exception $e){
            echo 'Message: ' . $e->getMessage();
        }
   
    }

MikeSpider
New php-forum User
New php-forum User
 
Posts: 49
Joined: Sun Feb 05, 2012 12:48 pm

Re: Works in localhost but not in remote host

Postby johnj » Thu Jun 13, 2013 9:52 pm

$s['address'] does not have a proper value and hence your alert is not working. Are you sure that you have the same set of records both on local and remote host??
johnj
php-forum Super User
php-forum Super User
 
Posts: 1805
Joined: Thu Mar 10, 2011 5:07 pm

Re: Works in localhost but not in remote host

Postby MikeSpider » Sun Jun 16, 2013 6:31 am

Hi John,

The values coming from db are all correct, as a matter of fact i use the same $s['address'] and the same loop to display the data on page before a user clicks and the $s['address] is passed into a javascript function. A I said previously it only gets first item. As if the data breaks out of the loop when called in javascript function. This is weird because I have the same script but that fetches data from other table and it works!
MikeSpider
New php-forum User
New php-forum User
 
Posts: 49
Joined: Sun Feb 05, 2012 12:48 pm

Re: Works in localhost but not in remote host

Postby MikeSpider » Mon Jun 17, 2013 3:38 am

I've just eliminated a few more possible causes, what is happening,
is only with the 'address' field in table, as I put other fields data in the alert function, it works
for every record, the address field only works in one of the records. And it is not random! it targets a specific record! I tried to run a query in another order just for the sake of troubleshooting to see if it was targeting only the first iteration in the loop. But not! it was always the same record.


Having eliminating this, the only thing left is data field itself ! Which, I dont see nothing wrong. The Table structure is:

/////////////////////////
id int not null auto_increment primary key,
name varchar(255) not null,
description varchar(255) not null,
address varchar(255) not null, // this is the field giving problems
phone varchar(16),
email varchar(60),
website varchar(100),
date datetime not null);
//////////////////////////////////

I have data in the address field in the following format:

9 Caledonian Road,London, EC1 6RA

I tried to escape the slashes with stripslashes as some names like St Ann's may mess up things
in the javascript function. Still no success!!! I'm clueless!
MikeSpider
New php-forum User
New php-forum User
 
Posts: 49
Joined: Sun Feb 05, 2012 12:48 pm

Re: Works in localhost but not in remote host

Postby johnj » Thu Jun 20, 2013 9:45 pm

Try - replace comma in the address with a space.
johnj
php-forum Super User
php-forum Super User
 
Posts: 1805
Joined: Thu Mar 10, 2011 5:07 pm


Return to PHP coding => General

Who is online

Users browsing this forum: Google [Bot] and 4 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.