• 0

Php error help


Question

I have came across an error on my website, I wondered if anyone could help? I have the word Banks O'Dee in my php database ($buyfrom) and I receive this error when accessing my page..

select location from opposition_team where opposition='Banks O'Dee'You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Dee'' at line 1

And this is the code I use on my php page for this part


$q4="select location from opposition_team where opposition='$buyfrom'";
$qr4=mysql_query($q4,$ccppdbc)or die($q4.mysql_error());
$r4=mysql_fetch_object($qr4);
$location=$r4->location;
[/CODE]

Can I not make this work without changing the word Banks O'Dee so it doesn't have the [b]' [/b]as I believe that is whats causing it.

Link to comment
https://www.neowin.net/forum/topic/1133392-php-error-help/
Share on other sites

6 answers to this question

Recommended Posts

  • 0

php has a function addslashes you could do something like:

$q4="select location from opposition_team where opposition='" . addslashes($buyfrom) . "'";
$qr4=mysql_query($q4,$ccppdbc)or die($q4.mysql_error());
$r4=mysql_fetch_object($qr4);
$location=$r4->location;[/CODE]

  • 0

I have came across an error on my website, I wondered if anyone could help? I have the word Banks O'Dee in my php database ($buyfrom) and I receive this error when accessing my page..

And this is the code I use on my php page for this part


$q4="select location from opposition_team where opposition='$buyfrom'";
$qr4=mysql_query($q4,$ccppdbc)or die($q4.mysql_error());
$r4=mysql_fetch_object($qr4);
$location=$r4->location;
[/CODE]

Can I not make this work without changing the word Banks O'Dee so it doesn't have the [b]' [/b]as I believe that is whats causing it.

Hi marklcfc,

What others have said is true about needing to escape your queries, I would recommend the using [b]mysql_real_escape_string[/b] function as [b]mysql_escape_string[/b] has been depreciated since [b]php 5.3[/b] in [u]June 30, 2009[/u].

Since this is an issue showing up in your site there is also the possibility that there are other [i]unescaped [/i]queries in your website application. I would recommend updating your code to use [b]PDO and prepared statements[/b] to help increase the security of your site and help protect from SQL Injection.

I would also recommend validating your data before accepting it from the end user or from a storage system and using something like HTMLPurifier to run your data through to assist with XSS protection.

Please take some time checking out the [b]OWASP Top 10[/b] to get a good idea of some of the security issues to look into. This should help you review your current site security level and see where it needs to be improved.

  • 0

I used that escape line, the page loads but it appears as Banks O\'Dee instead of Banks O'Dee

Firey's works well though..

To fix this issue, you just need to run stripslashes on your strings before echoing them out:


$buyfrom = mysql_real_escape_string($buyfrom);
$q4="select location from opposition_team where opposition='" . $buyfrom . "'";
$qr4=mysql_query($q4,$ccppdbc)or die($q4.mysql_error());
$r4=mysql_fetch_object($qr4);
$location=stripslashes($r4->location);
[/CODE]

The escaping is only necessary when inserting data into your database. Once you retrieve it, you can strip the slashes to return your data to normal. Hope that answers your questions!

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

    • They keep your data encrypted too. Including the calendar.
    • Microsoft makes billions redirecting people to use Bing in Microsoft Edge and selling OneDrive space. All thanks to Windows.
    • Teams is cancer, ebola and aids combined.
    • Claude on Windows is eating up massive amounts of RAM, with no way to stop it by Usama Jawad Anthropic has been in the headlines a lot lately, primarily due to its latest revenue and valuation figures, along with its release of its state-of-the-art (SOTA) Fable model. While its flagship product, Claude, may be very popular among millions of users, a lot of them are now reporting memory issues when using the tool. Over on Claude Code's GitHub repository, an issue raised in February has been gaining traction once again. Basically, Claude Desktop on Windows spins up a 1.8GB Hyper-V virtual machine if you use Claude Cowork or agent mode even once. This happens on each launch of Claude Code even if you plan to use the tool in chat mode only. Several users have upvoted this bug and stated that it's happening on their machine as well. However, it seemingly affects only Claude desktop users on Windows, not customers of the CLI or any other platform. Once the bug is triggered, it also shows a Vmmem process in Task Manager, indicating CPU usage of 0% and RAM utilization of a whopping ~1.8GB. Claude users complain that this process should only spin up when you explicitly launch agent mode or Cowork in Claude, with session files efficiently cleaned up after use. Additionally, they are calling for Claude to gracefully handle the absence of virtual machine-based infrastructure, without compromising on chat performance. It's unclear when this issue originated or what the root cause behind it is, but people are once again actively engaging in the GitHub thread as well as Hacker News. You can also find other technical details and log events over on GitHub. It's unclear if Anthropic will look into this issue, especially since it's already been reported for a few months. However, the bug is also causing major annoyance for users, with many claiming that it has led them to uninstall Claude Code on desktop, as a concrete workaround is not yet known.
    • "The US innovates, China replicates, Europe regulates" -- let's see who makes the cut
  • Recent Achievements

    • One Month Later
      Sopa flores earned a badge
      One Month Later
    • First Post
      StaticMatrix earned a badge
      First Post
    • Week One Done
      StaticMatrix earned a badge
      Week One Done
    • Rookie
      lamborghiniv10 went up a rank
      Rookie
    • One Month Later
      pinnclepd earned a badge
      One Month Later
  • Popular Contributors

    1. 1
      +primortal
      534
    2. 2
      PsYcHoKiLLa
      209
    3. 3
      +Edouard
      154
    4. 4
      Steven P.
      100
    5. 5
      ATLien_0
      84
  • Tell a friend

    Love Neowin? Tell a friend!