Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.php > #15140 > unrolled thread

Why do I get error when same code works elsewhere?

Started byrichard <noreply@example.com>
First post2015-03-29 21:47 -0400
Last post2015-03-31 23:23 +0200
Articles 18 — 10 participants

Back to article view | Back to comp.lang.php


Contents

  Why do I get error when same code works elsewhere? richard <noreply@example.com> - 2015-03-29 21:47 -0400
    Re: Why do I get error when same code works elsewhere? Doug Miller <doug_at_milmac_dot_com@example.com> - 2015-03-30 02:14 +0000
    Re: Why do I get error when same code works elsewhere? Denis McMahon <denismfmcmahon@gmail.com> - 2015-03-30 03:21 +0000
    Re: Why do I get error when same code works elsewhere? Richard Yates <richard@yatesguitar.com> - 2015-03-29 20:35 -0700
      Re: Why do I get error when same code works elsewhere? richard <noreply@example.com> - 2015-03-29 23:53 -0400
        Re: Why do I get error when same code works elsewhere? Richard Yates <richard@yatesguitar.com> - 2015-03-29 21:12 -0700
          Re: Why do I get error when same code works elsewhere? richard <noreply@example.com> - 2015-03-31 12:01 -0400
      Re: Why do I get error when same code works elsewhere? Jerry Stuckle <jstucklex@attglobal.net> - 2015-03-30 08:21 -0400
        Re: Why do I get error when same code works elsewhere? "Beauregard T. Shagnasty" <a.nony.mous@example.invalid> - 2015-03-30 13:17 +0000
        Re: Why do I get error when same code works elsewhere? Denis McMahon <denismfmcmahon@gmail.com> - 2015-03-30 17:06 +0000
        Re: Why do I get error when same code works elsewhere? richard <noreply@example.com> - 2015-03-31 12:02 -0400
    Re: Why do I get error when same code works elsewhere? bill <william@TechServSys.com> - 2015-03-31 08:11 -0400
      Re: Why do I get error when same code works elsewhere? "Christoph M. Becker" <cmbecker69@arcor.de> - 2015-03-31 14:24 +0200
        Re: Why do I get error when same code works elsewhere? bill <william@TechServSys.com> - 2015-04-01 08:27 -0400
          Re: Why do I get error when same code works elsewhere? ꧁꧂ <vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvva@hotmail.com> - 2023-05-14 08:53 -0700
      Re: Why do I get error when same code works elsewhere? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-03-31 22:38 +0200
        Re: Why do I get error when same code works elsewhere? "Christoph M. Becker" <cmbecker69@arcor.de> - 2015-03-31 22:55 +0200
          Re: Why do I get error when same code works elsewhere? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-03-31 23:23 +0200

#15140 — Why do I get error when same code works elsewhere?

Fromrichard <noreply@example.com>
Date2015-03-29 21:47 -0400
SubjectWhy do I get error when same code works elsewhere?
Message-ID<18bbb34ftm658$.1tgigatbgo67j$.dlg@40tude.net>
																																																
$num=count($numone);
																																																
shuffle($numone);
$x=0; $y=0;
while($x<$num){

$mp=$numone[$x];
$mp=substr($mp,0,6);
$sql = "SELECT * FROM sixty where sid='$mp'";
$result = $mysqli->query($sql);<<<<<<<<<<< error here
$row = $result->fetch_assoc(); 

echo$mp;
echo "<div style='width:300px; height:60px; border:solid 1px #00f;
overflow:hidden;';>";
$y=$x+1;
echo $y.") ".$row['title'];
echo "<br>";
$x++;

echo "</div>";
}

Fatal error: Call to a member function query() on a non-object

[toc] | [next] | [standalone]


#15141

FromDoug Miller <doug_at_milmac_dot_com@example.com>
Date2015-03-30 02:14 +0000
Message-ID<XnsA46CE232C10ECdougmilmaccom@213.239.209.88>
In reply to#15140
richard <noreply@example.com> wrote in news:18bbb34ftm658$.1tgigatbgo67j$.dlg@
40tude.net:

> [...]
> $sql = "SELECT * FROM sixty where sid='$mp'";
> [...]
> Fatal error: Call to a member function query() on a non-object
> 
This may help:
http://bit.ly/1G1a3vr

[toc] | [prev] | [next] | [standalone]


#15142

FromDenis McMahon <denismfmcmahon@gmail.com>
Date2015-03-30 03:21 +0000
Message-ID<mfafgc$j9l$1@dont-email.me>
In reply to#15140
On Sun, 29 Mar 2015 21:47:09 -0400, richard wrote:

> $result = $mysqli->query($sql);<<<<<<<<<<< error here
> Fatal error: Call to a member function query() on a non-object

I know what's causing that. I imagine most of the other people here do 
too. The error message is actually very explicit in describing the exact 
problem. However, for your benefit, I will try and rephrase the error 
message: The object that you're trying to call the member function query 
on does not exist.

-- 
Denis McMahon, denismfmcmahon@gmail.com

[toc] | [prev] | [next] | [standalone]


#15143

FromRichard Yates <richard@yatesguitar.com>
Date2015-03-29 20:35 -0700
Message-ID<20hhha9eugacoteq09tmr3mu9tr7fknu5h@4ax.com>
In reply to#15140
On Sun, 29 Mar 2015 21:47:09 -0400, richard <noreply@example.com>
wrote:

>																																																
>$num=count($numone);
>																																																
>shuffle($numone);
>$x=0; $y=0;
>while($x<$num){
>
>$mp=$numone[$x];
>$mp=substr($mp,0,6);
>$sql = "SELECT * FROM sixty where sid='$mp'";
>$result = $mysqli->query($sql);<<<<<<<<<<< error here
>$row = $result->fetch_assoc(); 
>
>echo$mp;
>echo "<div style='width:300px; height:60px; border:solid 1px #00f;
>overflow:hidden;';>";
>$y=$x+1;
>echo $y.") ".$row['title'];
>echo "<br>";
>$x++;
>
>echo "</div>";
>}
>
>Fatal error: Call to a member function query() on a non-object


$result=mysqli_query($sql);
$row=mysqli_fetch_assoc($connection, $result);

[toc] | [prev] | [next] | [standalone]


#15144

Fromrichard <noreply@example.com>
Date2015-03-29 23:53 -0400
Message-ID<1ohg6f8ub6nbz.8jaywywcrl68$.dlg@40tude.net>
In reply to#15143
On Sun, 29 Mar 2015 20:35:40 -0700, Richard Yates wrote:

> On Sun, 29 Mar 2015 21:47:09 -0400, richard <noreply@example.com>
> wrote:
> 
>>																																																
>>$num=count($numone);
>>																																																
>>shuffle($numone);
>>$x=0; $y=0;
>>while($x<$num){
>>
>>$mp=$numone[$x];
>>$mp=substr($mp,0,6);
>>$sql = "SELECT * FROM sixty where sid='$mp'";
>>$result = $mysqli->query($sql);<<<<<<<<<<< error here
>>$row = $result->fetch_assoc(); 
>>
>>echo$mp;
>>echo "<div style='width:300px; height:60px; border:solid 1px #00f;
>>overflow:hidden;';>";
>>$y=$x+1;
>>echo $y.") ".$row['title'];
>>echo "<br>";
>>$x++;
>>
>>echo "</div>";
>>}
>>
>>Fatal error: Call to a member function query() on a non-object
> 
> 
> $result=mysqli_query($sql);
> $row=mysqli_fetch_assoc($connection, $result);

Thanks. Tried different values for $connection and still get the same
error.

[toc] | [prev] | [next] | [standalone]


#15145

FromRichard Yates <richard@yatesguitar.com>
Date2015-03-29 21:12 -0700
Message-ID<e8jhhap21g7hlvj3a8uo3omq1dq31vbnqv@4ax.com>
In reply to#15144
On Sun, 29 Mar 2015 23:53:32 -0400, richard <noreply@example.com>
wrote:

>On Sun, 29 Mar 2015 20:35:40 -0700, Richard Yates wrote:
>
>> On Sun, 29 Mar 2015 21:47:09 -0400, richard <noreply@example.com>
>> wrote:
>> 
>>>																																																
>>>$num=count($numone);
>>>																																																
>>>shuffle($numone);
>>>$x=0; $y=0;
>>>while($x<$num){
>>>
>>>$mp=$numone[$x];
>>>$mp=substr($mp,0,6);
>>>$sql = "SELECT * FROM sixty where sid='$mp'";
>>>$result = $mysqli->query($sql);<<<<<<<<<<< error here
>>>$row = $result->fetch_assoc(); 
>>>
>>>echo$mp;
>>>echo "<div style='width:300px; height:60px; border:solid 1px #00f;
>>>overflow:hidden;';>";
>>>$y=$x+1;
>>>echo $y.") ".$row['title'];
>>>echo "<br>";
>>>$x++;
>>>
>>>echo "</div>";
>>>}
>>>
>>>Fatal error: Call to a member function query() on a non-object
>> 
>> 
>> $result=mysqli_query($sql);
>> $row=mysqli_fetch_assoc($connection, $result);
>
>Thanks. Tried different values for $connection and still get the same
>error.

"$connection" is standing in for whatever you named the resource that
is the connection to your database.

[toc] | [prev] | [next] | [standalone]


#15155

Fromrichard <noreply@example.com>
Date2015-03-31 12:01 -0400
Message-ID<12051ul463ndd$.uj802ulwik3l.dlg@40tude.net>
In reply to#15145
On Sun, 29 Mar 2015 21:12:56 -0700, Richard Yates wrote:

> On Sun, 29 Mar 2015 23:53:32 -0400, richard <noreply@example.com>
> wrote:
> 
>>On Sun, 29 Mar 2015 20:35:40 -0700, Richard Yates wrote:
>>
>>> On Sun, 29 Mar 2015 21:47:09 -0400, richard <noreply@example.com>
>>> wrote:
>>> 
>>>>																																																
>>>>$num=count($numone);
>>>>																																																
>>>>shuffle($numone);
>>>>$x=0; $y=0;
>>>>while($x<$num){
>>>>
>>>>$mp=$numone[$x];
>>>>$mp=substr($mp,0,6);
>>>>$sql = "SELECT * FROM sixty where sid='$mp'";
>>>>$result = $mysqli->query($sql);<<<<<<<<<<< error here
>>>>$row = $result->fetch_assoc(); 
>>>>
>>>>echo$mp;
>>>>echo "<div style='width:300px; height:60px; border:solid 1px #00f;
>>>>overflow:hidden;';>";
>>>>$y=$x+1;
>>>>echo $y.") ".$row['title'];
>>>>echo "<br>";
>>>>$x++;
>>>>
>>>>echo "</div>";
>>>>}
>>>>
>>>>Fatal error: Call to a member function query() on a non-object
>>> 
>>> 
>>> $result=mysqli_query($sql);
>>> $row=mysqli_fetch_assoc($connection, $result);
>>
>>Thanks. Tried different values for $connection and still get the same
>>error.
> 
> "$connection" is standing in for whatever you named the resource that
> is the connection to your database.

That's what I finally figured out where the error was actually coming from.
Use the right variable and it works.

[toc] | [prev] | [next] | [standalone]


#15146

FromJerry Stuckle <jstucklex@attglobal.net>
Date2015-03-30 08:21 -0400
Message-ID<mfbf24$bvj$1@dont-email.me>
In reply to#15143
On 3/29/2015 11:35 PM, Richard Yates wrote:
> On Sun, 29 Mar 2015 21:47:09 -0400, richard <noreply@example.com>
> wrote:
> 
>> 																																																
>> $num=count($numone);
>> 																																																
>> shuffle($numone);
>> $x=0; $y=0;
>> while($x<$num){
>>
>> $mp=$numone[$x];
>> $mp=substr($mp,0,6);
>> $sql = "SELECT * FROM sixty where sid='$mp'";
>> $result = $mysqli->query($sql);<<<<<<<<<<< error here
>> $row = $result->fetch_assoc(); 
>>
>> echo$mp;
>> echo "<div style='width:300px; height:60px; border:solid 1px #00f;
>> overflow:hidden;';>";
>> $y=$x+1;
>> echo $y.") ".$row['title'];
>> echo "<br>";
>> $x++;
>>
>> echo "</div>";
>> }
>>
>> Fatal error: Call to a member function query() on a non-object
> 
> 
> $result=mysqli_query($sql);
> $row=mysqli_fetch_assoc($connection, $result);
> 

No, the code he posted is correct.  He is using the OO interface, not
the functional interface.  But his problem is before this.

Denis has the correct clue to where richard's problem is.  Doug's
response is also correct, although I'm not sure about richard's ability
to understand the results of the search.

-- 
==================
Remove the "x" from my email address
Jerry Stuckle
jstucklex@attglobal.net
==================

[toc] | [prev] | [next] | [standalone]


#15147

From"Beauregard T. Shagnasty" <a.nony.mous@example.invalid>
Date2015-03-30 13:17 +0000
Message-ID<mfbidp$r30$1@dont-email.me>
In reply to#15146
Jerry Stuckle wrote:

> although I'm not sure about richard's ability to understand the results
> of the search.

No surprise there. All Richard the Sto0pid can do is copy the code of 
others, and then wonder why it doesn't work. This happens every time he 
fiddles with his toy web site.

-- 
   -bts
   -This space for rent, but the price is high

[toc] | [prev] | [next] | [standalone]


#15148

FromDenis McMahon <denismfmcmahon@gmail.com>
Date2015-03-30 17:06 +0000
Message-ID<mfbvqp$puj$1@dont-email.me>
In reply to#15146
On Mon, 30 Mar 2015 08:21:09 -0400, Jerry Stuckle wrote:

> Denis has the correct clue to where richard's problem is.  Doug's
> response is also correct, although I'm not sure about richard's ability
> to understand the results of the search.

I was going to try and write an analogy that he might understand, but it 
didn't really work as it's the object "richard" that wouldn't exist, 
rather than the member functions "write_code_that_works" and 
"intelligently_analyse_error_message". "richard" of course exists, it's 
those member functions that don't exist in class st00pid. ;)

-- 
Denis McMahon, denismfmcmahon@gmail.com

[toc] | [prev] | [next] | [standalone]


#15156

Fromrichard <noreply@example.com>
Date2015-03-31 12:02 -0400
Message-ID<9a455d9hy1ov.r4yoegd15k5j$.dlg@40tude.net>
In reply to#15146
On Mon, 30 Mar 2015 08:21:09 -0400, Jerry Stuckle wrote:

> On 3/29/2015 11:35 PM, Richard Yates wrote:
>> On Sun, 29 Mar 2015 21:47:09 -0400, richard <noreply@example.com>
>> wrote:
>> 
>>> 																																																
>>> $num=count($numone);
>>> 																																																
>>> shuffle($numone);
>>> $x=0; $y=0;
>>> while($x<$num){
>>>
>>> $mp=$numone[$x];
>>> $mp=substr($mp,0,6);
>>> $sql = "SELECT * FROM sixty where sid='$mp'";
>>> $result = $mysqli->query($sql);<<<<<<<<<<< error here
>>> $row = $result->fetch_assoc(); 
>>>
>>> echo$mp;
>>> echo "<div style='width:300px; height:60px; border:solid 1px #00f;
>>> overflow:hidden;';>";
>>> $y=$x+1;
>>> echo $y.") ".$row['title'];
>>> echo "<br>";
>>> $x++;
>>>
>>> echo "</div>";
>>> }
>>>
>>> Fatal error: Call to a member function query() on a non-object
>> 
>> 
>> $result=mysqli_query($sql);
>> $row=mysqli_fetch_assoc($connection, $result);
>> 
> 
> No, the code he posted is correct.  He is using the OO interface, not
> the functional interface.  But his problem is before this.
> 
> Denis has the correct clue to where richard's problem is.  Doug's
> response is also correct, although I'm not sure about richard's ability
> to understand the results of the search.

Bursting your bubble Jerry, I did figure it out and works just fine now.

[toc] | [prev] | [next] | [standalone]


#15151

Frombill <william@TechServSys.com>
Date2015-03-31 08:11 -0400
Message-ID<mfe2t4$md2$1@speranza.aioe.org>
In reply to#15140
On 3/29/2015 9:47 PM, richard wrote:
> 																																																
> $num=count($numone);
> 																																																
> shuffle($numone);
> $x=0; $y=0;
> while($x<$num){
>
> $mp=$numone[$x];
> $mp=substr($mp,0,6);
> $sql = "SELECT * FROM sixty where sid='$mp'";
> $result = $mysqli->query($sql);<<<<<<<<<<< error here
> $row = $result->fetch_assoc();
>
> echo$mp;
> echo "<div style='width:300px; height:60px; border:solid 1px #00f;
> overflow:hidden;';>";
> $y=$x+1;
> echo $y.") ".$row['title'];
> echo "<br>";
> $x++;
>
> echo "</div>";
> }
>
> Fatal error: Call to a member function query() on a non-object
>

Let me (uncharacteristically) defend richard this time.
He is being polite
He posted actual code

He is still copying and pasting without understanding, but that 
might be repairable.

Richard,
before one can invoke a method of an object, one must create the 
object (usually using the "new" constructor or an explicit 
constructor)
Now, your task is to read the introductory chapters about PDO
http://us1.php.net/manual/en/class.pdo.php

-bill

[toc] | [prev] | [next] | [standalone]


#15152

From"Christoph M. Becker" <cmbecker69@arcor.de>
Date2015-03-31 14:24 +0200
Message-ID<mfe3l5$3hm$1@solani.org>
In reply to#15151
bill wrote:

> On 3/29/2015 9:47 PM, richard wrote:                                                                                                                                                                
>
>> $result = $mysqli->query($sql);<<<<<<<<<<< error here
>>
>> Fatal error: Call to a member function query() on a non-object
>
> Now, your task is to read the introductory chapters about PDO
> http://us1.php.net/manual/en/class.pdo.php

Err, why PDO?  Apparently, richard is using mysqli, what would be fine.

-- 
Christoph M. Becker

[toc] | [prev] | [next] | [standalone]


#15175

Frombill <william@TechServSys.com>
Date2015-04-01 08:27 -0400
Message-ID<mfgo7h$oee$1@speranza.aioe.org>
In reply to#15152
On 3/31/2015 8:24 AM, Christoph M. Becker wrote:
> bill wrote:
>
>> On 3/29/2015 9:47 PM, richard wrote:
>>
>>> $result = $mysqli->query($sql);<<<<<<<<<<< error here
>>>
>>> Fatal error: Call to a member function query() on a non-object
>>
>> Now, your task is to read the introductory chapters about PDO
>> http://us1.php.net/manual/en/class.pdo.php
>
> Err, why PDO?  Apparently, richard is using mysqli, what would be fine.
>
Whoops, my fingers are faster than my mind.
Yes, mysqli:
http://us1.php.net/manual/en/class.mysqli.php

-bill

[toc] | [prev] | [next] | [standalone]


#19458

From꧁꧂ <vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvva@hotmail.com>
Date2023-05-14 08:53 -0700
Message-ID<a52fe61e-c42a-48bb-aac3-45add235e389n@googlegroups.com>
In reply to#15175
No problem, Bill, happens to everyone time to time.


On Wednesday, April 1, 2015 at 2:27:38 PM UTC+2, bill wrote:
> On 3/31/2015 8:24 AM, Christoph M. Becker wrote: 
> > bill wrote: 
> > 
> >> On 3/29/2015 9:47 PM, richard wrote: 
> >> 
> >>> $result = $mysqli->query($sql);<<<<<<<<<<< error here 
> >>> 
> >>> Fatal error: Call to a member function query() on a non-object 
> >> 
> >> Now, your task is to read the introductory chapters about PDO 
> >> http://us1.php.net/manual/en/class.pdo.php 
> > 
> > Err, why PDO? Apparently, richard is using mysqli, what would be fine. 
> >
> Whoops, my fingers are faster than my mind. 
> Yes, mysqli: 
> http://us1.php.net/manual/en/class.mysqli.php 
> 
> -bill

[toc] | [prev] | [next] | [standalone]


#15163

FromThomas 'PointedEars' Lahn <PointedEars@web.de>
Date2015-03-31 22:38 +0200
Message-ID<2662856.hcR7piWQrz@PointedEars.de>
In reply to#15151
bill wrote:

> Let me (uncharacteristically) defend richard this time.
> He is being polite

He is not blatantly impolite (yet), which is different from being polite.  
Politeness would include a demonstratation of the appreciation of other’s
time, which did not happen again.

See also <http://www.catb.org/~esr/faqs/smart-questions.html>.

> Richard,
> before one can invoke a method of an object, one must create the
> object

So far, so good.

> (usually using the "new" constructor or an explicit constructor)

“new” is not a constructor, it is a keyword of an operation.  What do you 
think is an “explicit constructor” and how would it differ from your “‘new’ 
constructor”?

> Now, your task is to read the introductory chapters about PDO
> http://us1.php.net/manual/en/class.pdo.php

Although it is a good idea to use pdo_mysql instead of mysqli or (do not 
even think about it) mysql (PDO has a common OO-API for all DBMSs), there
is no reason why he should do that in order to solve *his* problem.

-- 
PointedEars
Zend Certified PHP Engineer
Twitter: @PointedEars2
Please do not cc me. / Bitte keine Kopien per E-Mail.

[toc] | [prev] | [next] | [standalone]


#15164

From"Christoph M. Becker" <cmbecker69@arcor.de>
Date2015-03-31 22:55 +0200
Message-ID<mff1js$kaj$1@solani.org>
In reply to#15163
Thomas 'PointedEars' Lahn wrote:

> bill wrote:
> 
>> (usually using the "new" constructor or an explicit constructor)
> 
> “new” is not a constructor, it is a keyword of an operation.  What do you 
> think is an “explicit constructor” and how would it differ from your “‘new’ 
> constructor”?

Read "factory method" instead of "explicit constructor". :)

-- 
Christoph M. Becker

[toc] | [prev] | [next] | [standalone]


#15165

FromThomas 'PointedEars' Lahn <PointedEars@web.de>
Date2015-03-31 23:23 +0200
Message-ID<2138233.0o5ikWLTFx@PointedEars.de>
In reply to#15164
Christoph M. Becker wrote:

> Thomas 'PointedEars' Lahn wrote:
>> bill wrote: 
>>> (usually using the "new" constructor or an explicit constructor)
>> “new” is not a constructor, it is a keyword of an operation.  What do you
>> think is an “explicit constructor” and how would it differ from your
>> “‘new’ constructor”?
> 
> Read "factory method" instead of "explicit constructor". :)

Perhaps.  It is up to “bill” to explain his uncommon terminology.

-- 
PointedEars
Zend Certified PHP Engineer
Twitter: @PointedEars2
Please do not cc me. / Bitte keine Kopien per E-Mail.

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.php


csiph-web