• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

PHP problem

ElDonAntonio

Senior member
Hi guys,

I don't know much about PHP and MySQL, but a guy did a job for me and I found a bug I need to eliminate myself.

Here it is basically:

The page allows you to put books on sale on the site. So I have a form with some text fields and a submit button.

I have a text field with the name of a book for example:

"Algebra, student's textbook"

Problem is, as soon there's an apostrophe (this character -> '), an error occurs when you click on submit. Instead of inserting the info in the database, the following output occurs:

INSERT INTO livre (SchoolID, Name, Author, Year, Edition, Price) VALUES ('92', 'Flight 314, student's logbook, cahier', '', '0', 'Lidec', '0', '23')

Of course, that's because there's a confusion between the closing apostrophe and the apostrphe in "student's".

So in my form, how do I convert the apostrophe entered in the textfield to something acceptable before it is submitted and sent to the database?
 
before inserting the variable into the database, do:

$yournewstr = addslashes($youroldstr);

then insert $yournewstr into the database.
 
Back
Top