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
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
Share on other sites

Thanks, but that doesn't really resolve either one of my questions.

 

I want to stop the user from inserting "Quizno's" into the database, not echo whether they do or not. This "Quinzo\'s" does not work for me as far as showing the apostrophe.

 

Any ideas?

Link to comment
Share on other sites

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.