FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » MYSQL PHP Query Not Working
Show: Today's Messages :: Polls :: Message Navigator
Switch to threaded view of this topic Create a new topic Submit Reply
MYSQL PHP Query Not Working [message #185483] Thu, 03 April 2014 15:46 Go to next message
cuteywithlove is currently offline  cuteywithlove
Messages: 2
Registered: April 2014
Karma: 0
Junior Member
I've spent hours on this and can't understand why this doesn't work.


//////////////////// CODE

$email = strtolower(filter_input(INPUT_GET, 'email', FILTER_SANITIZE_EMAIL));
$blog_id = filter_input(INPUT_GET, 'blogId', FILTER_SANITIZE_NUMBER_INT);
$password = md5(filter_input(INPUT_GET, 'password', FILTER_SANITIZE_SPECIAL_CHARS));

$id = authenticate($email, $password, $db1);


if ($id != false) {

if (!$stmt = $db1->prepare('DELETE FROM blogs WHERE userId=? && blogId=?')) {
echo "Binding parameters failed: (" . $stmt->errno . ") " . $stmt->error;
}


// $id, $blog_Id checked here and are correct!

if (!$stmt->bind_param("ii", $id, $blog_Id)) {
echo "Binding parameters failed: (" . $stmt->errno . ") " . $stmt->error;
}


if (!$stmt->execute()) {
echo "Execute failed: (" . $stmt->errno . ") " . $stmt->error;
}else{
echo('{"status":"deleted"}');
}

$stmt->close();

}else{
echo('[{"status":"failed"}]');
}


/// COOOOOOOOOOODE END


{"status":"deleted"} is outputted but the record is not deleted.

If I copy and paste the query into phpmyadmin and run it with the values hard coded it works.

No errors are returned.

The user has privileges to delete and everything else.

Is there anyway I can check it? or see any errors any other way?
Re: MYSQL PHP Query Not Working [message #185484 is a reply to message #185483] Thu, 03 April 2014 16:18 Go to previous messageGo to next message
Salvatore is currently offline  Salvatore
Messages: 38
Registered: September 2012
Karma: 0
Member
On 2014-04-03, cuteywithlove(at)gmail(dot)com <cuteywithlove(at)gmail(dot)com> wrote:
> I've spent hours on this and can't understand why this doesn't work.
>
> [snip]
> $blog_id = filter_input(INPUT_GET, 'blogId', FILTER_SANITIZE_NUMBER_INT);
> [snip]
> if (!$stmt->bind_param("ii", $id, $blog_Id)) {
> [snip]
>
> If I copy and paste the query into phpmyadmin and run it with the values
> hard coded it works.
>
> No errors are returned.
>
> The user has privileges to delete and everything else.
>
> Is there anyway I can check it? or see any errors any other way?

The first thing I see wrong is that you mistyped "$blog_id" as
"$blog_Id".

--
Blah blah bleh...
GCS/CM d(-)@>-- s+:- !a C++$ UBL++++$ L+$ W+++$ w M++ Y++ b++
Re: MYSQL PHP Query Not Working [message #185485 is a reply to message #185484] Thu, 03 April 2014 17:08 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
On 4/3/2014 12:18 PM, Salvatore wrote:
> On 2014-04-03, cuteywithlove(at)gmail(dot)com <cuteywithlove(at)gmail(dot)com> wrote:
>> I've spent hours on this and can't understand why this doesn't work.
>>
>> [snip]
>> $blog_id = filter_input(INPUT_GET, 'blogId', FILTER_SANITIZE_NUMBER_INT);
>> [snip]
>> if (!$stmt->bind_param("ii", $id, $blog_Id)) {
>> [snip]
>>
>> If I copy and paste the query into phpmyadmin and run it with the values
>> hard coded it works.
>>
>> No errors are returned.
>>
>> The user has privileges to delete and everything else.
>>
>> Is there anyway I can check it? or see any errors any other way?
>
> The first thing I see wrong is that you mistyped "$blog_id" as
> "$blog_Id".
>

Good eye, Salvatore! Can I get you to proof my next project? :)

I would also mention that enabling E_NOTICE would have shown this error
(assuming, of course, the OP doesn't also have $blog_Id defined, of course).

--
==================
Remove the "x" from my email address
Jerry Stuckle
jstucklex(at)attglobal(dot)net
==================
Re: MYSQL PHP Query Not Working [message #185486 is a reply to message #185484] Thu, 03 April 2014 17:30 Go to previous messageGo to next message
The Natural Philosoph is currently offline  The Natural Philosoph
Messages: 993
Registered: September 2010
Karma: 0
Senior Member
On 03/04/14 17:18, Salvatore wrote:
> On 2014-04-03, cuteywithlove(at)gmail(dot)com <cuteywithlove(at)gmail(dot)com> wrote:
>> I've spent hours on this and can't understand why this doesn't work.
>>
>> [snip]
>> $blog_id = filter_input(INPUT_GET, 'blogId', FILTER_SANITIZE_NUMBER_INT);
>> [snip]
>> if (!$stmt->bind_param("ii", $id, $blog_Id)) {
>> [snip]
>>
>> If I copy and paste the query into phpmyadmin and run it with the values
>> hard coded it works.
>>
>> No errors are returned.
>>
>> The user has privileges to delete and everything else.
>>
>> Is there anyway I can check it? or see any errors any other way?
>
> The first thing I see wrong is that you mistyped "$blog_id" as
> "$blog_Id".
>
Mysql may or may not be case sensitive.

He says it works in phpmyadmin

IF its running under apache Id suggests looking at Apache error logs cos
that's typically where errors get reported. There are certainly classes
of errors that don't get reported by the upper layers of the software
that reveal themselves as errors at the base level. A typical one is
trying to process a single result on the implicit assumption that there
is any result at all.


My guess is the statement is executing correctly but not doing anything.

First test: log in as EXACTLY the same user and password under
phpmyadmin and see if it still works.

spent several hours poring over code before I realised that I hadn't
granted select rights on a table to the appropriate mysql user..

In this case does the user have delete rights to the table?

And would that throw and errors at the mysql level? Or simply return a
null result?


--
Ineptocracy

(in-ep-toc’-ra-cy) – a system of government where the least capable to
lead are elected by the least capable of producing, and where the
members of society least likely to sustain themselves or succeed, are
rewarded with goods and services paid for by the confiscated wealth of a
diminishing number of producers.
Re: MYSQL PHP Query Not Working [message #185487 is a reply to message #185486] Thu, 03 April 2014 18:38 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
On 4/3/2014 1:30 PM, The Natural Philosopher wrote:
> On 03/04/14 17:18, Salvatore wrote:
>> On 2014-04-03, cuteywithlove(at)gmail(dot)com <cuteywithlove(at)gmail(dot)com> wrote:
>>> I've spent hours on this and can't understand why this doesn't work.
>>>
>>> [snip]
>>> $blog_id = filter_input(INPUT_GET, 'blogId',
>>> FILTER_SANITIZE_NUMBER_INT);
>>> [snip]
>>> if (!$stmt->bind_param("ii", $id, $blog_Id)) {
>>> [snip]
>>>
>>> If I copy and paste the query into phpmyadmin and run it with the values
>>> hard coded it works.
>>>
>>> No errors are returned.
>>>
>>> The user has privileges to delete and everything else.
>>>
>>> Is there anyway I can check it? or see any errors any other way?
>>
>> The first thing I see wrong is that you mistyped "$blog_id" as
>> "$blog_Id".
>>
> Mysql may or may not be case sensitive.
>
> He says it works in phpmyadmin
>
> IF its running under apache Id suggests looking at Apache error logs cos
> that's typically where errors get reported. There are certainly classes
> of errors that don't get reported by the upper layers of the software
> that reveal themselves as errors at the base level. A typical one is
> trying to process a single result on the implicit assumption that there
> is any result at all.
>
>
> My guess is the statement is executing correctly but not doing anything.
>
> First test: log in as EXACTLY the same user and password under
> phpmyadmin and see if it still works.
>
> spent several hours poring over code before I realised that I hadn't
> granted select rights on a table to the appropriate mysql user..
>
> In this case does the user have delete rights to the table?
>
> And would that throw and errors at the mysql level? Or simply return a
> null result?
>
>

Your guess is wrong. And it has nothing to do with whether MySQL is
case-sensitive or not. $blog_Id is a PHP variable.

--
==================
Remove the "x" from my email address
Jerry Stuckle
jstucklex(at)attglobal(dot)net
==================
Re: MYSQL PHP Query Not Working [message #185491 is a reply to message #185487] Fri, 04 April 2014 07:48 Go to previous messageGo to next message
cuteywithlove is currently offline  cuteywithlove
Messages: 2
Registered: April 2014
Karma: 0
Junior Member
Thank you!!!!!!!!!!!!!!!!!!!!!!

That was the issue now fixed after about 10 hours of debugging, yes it was one letter wrong!!!! :D
Re: MYSQL PHP Query Not Working [message #185492 is a reply to message #185491] Fri, 04 April 2014 10:28 Go to previous messageGo to next message
Erwin Moller is currently offline  Erwin Moller
Messages: 228
Registered: September 2010
Karma: 0
Senior Member
On 4/4/2014 9:48 AM, cuteywithlove(at)gmail(dot)com wrote:
> Thank you!!!!!!!!!!!!!!!!!!!!!!
>
> That was the issue now fixed after about 10 hours of debugging, yes it was one letter wrong!!!! :D
>

When you find yourself in a situation where you are pretty something
must work, but it doesn't:
1) Make sure you see all errors/warnings/notices. (Fixes 99% of the
problems for me)
2) Delete the code, and retype it! ;-)
Seriously, that helped me out a few times.

And a big HI! to all in comp.lang.php, my favorite newsgroup I have been
neglecting now for waaay too long.

Regards,
Erwin Moller

--
"That which can be asserted without evidence, can be dismissed without
evidence."
-- Christopher Hitchens
Re: MYSQL PHP Query Not Working [message #185493 is a reply to message #185491] Fri, 04 April 2014 10:45 Go to previous messageGo to next message
bill is currently offline  bill
Messages: 310
Registered: October 2010
Karma: 0
Senior Member
On 4/4/2014 3:48 AM, cuteywithlove(at)gmail(dot)com wrote:
> Thank you!!!!!!!!!!!!!!!!!!!!!!
>
> That was the issue now fixed after about 10 hours of debugging, yes it was one letter wrong!!!! :D
>

I can't even count the number of times I have missed 1 letter
misspellings (usually an unexpected capital letter).

bill
Re: MYSQL PHP Query Not Working [message #185500 is a reply to message #185493] Sat, 05 April 2014 19:30 Go to previous message
M. Strobel is currently offline  M. Strobel
Messages: 386
Registered: December 2011
Karma: 0
Senior Member
Am 04.04.2014 12:45, schrieb bill:
> On 4/4/2014 3:48 AM, cuteywithlove(at)gmail(dot)com wrote:
>> Thank you!!!!!!!!!!!!!!!!!!!!!!
>>
>> That was the issue now fixed after about 10 hours of debugging, yes it was one
>> letter wrong!!!! :D
>>
>
> I can't even count the number of times I have missed 1 letter misspellings (usually
> an unexpected capital letter).
>
> bill

I sometimes search the variable name throughout the code to find typos. Some editors
(kate) highlight all occurences of a variable if you click on it, it helps a lot.

/Str.
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Strange but true! Working with interfaces in PHP
Next Topic: PDF extract text
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Sun Dec 01 01:12:21 GMT 2024

Total time taken to generate the page: 0.02450 seconds