Jump to content

Two Problems


verdrm

Recommended Posts

Hi Everyone,

 

I have two issues. They are probably really simple but I'm stuck.

 

1. I want to block the input of certain text into a MySQL table coming from a text field.

 

When the user submits the form, I need something that can check the form field, and if the text matches what I want to block, it gives them an error.

 

So, if they type "Quizno's", the PHP page with the INSERT INTO code would stop "Quizno's" from being inserted.

 

Can anyone post the PHP for that?

 

 

2. I also want the above code to block names with apostrophes. I have tried \'s and some other things in my IF statement. See example below:

 

if ($restaurant=="Quizno's")

echo "Restaurant not allowed due to the policy of your organization.";

 

I can't seem to get the IF statement working with apostrophes.

 

Does anyone know the solution for that?

Link to comment
https://forums.phpfreaks.com/topic/64955-two-problems/
Share on other sites

Apostrophes should be no problem if handled correctly. If magic_quotes is ON they will be escaped automatically for you so you need to be aware of the added backslash

 

<?php
if ($_POST['restaurant'] == "Quinzo\'s")
    echo "Match";
else
    echo "No match";
?>
<form method='post'>
    <input type="text" name="restaurant" value="Quinzo's"> <br/>
    <input type="submit" name="sub" value="Click me">
</form>

Link to comment
https://forums.phpfreaks.com/topic/64955-two-problems/#findComment-324146
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.