Jump to content

Recommended Posts

my code

 

 

$query = "SELECT SUM(furnitureA) AS furnitureA FROM items WHERE quantity = '$codeNumber'"; 
$result = mysql_query($query); 
$rBf = mysql_fetch_array($result); // ERROR: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in....
 

 

 
This usually happens whenever there's an apostrophe (') in $codeNumber (E.g. if $codeNumber = jack's154879).
How do i overcome this?
 
 

 

http://php.net/manual/en/function.mysql-real-escape-string.php

 

 

$codeNumber = mysql_real_escape_string( $codeNumber );

 

That should fix it right up. Definitely look up the function description so you understand what's going on here.

Edited by matthew.javelet

Thanks. but now the $codeNumber is red as jack\'s154879? Not outputting the desired results whenever there is an apostrophe (') in the $codeNumber variable.?

 

Are you seeing that when looking at the code in the database? That's fine, it's supposed to do that. It's escaping the quotes. When you get the data from the database, those slashes will (should?) be removed.

Check if 'Magic Quotes' are turned on in PHP and also check for any 'addslashes' function use within your code.

 

If Magic Quotes are on then all HTTP request data (e.g. $_POST) will automatically be escaped.

 

If you're using addslashes() then additional escaping is being done there too.

 

The above two methods will actually add the backslashes when storing in the database, unlike the mysql_real_escape_string() method, so I'm guessing you're doing one of those things (hence the backslash you are seeing in the DB).

 

Ensure to just use mysql_real_escape_string() and no other methods of escaping.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.