简体   繁体   中英

MySQL/PHP Error: Input a value with an apostrophe ( ' )

So I have this particular feature in my program wherein I want it to count all the Malls with value = 2 Robinson's Manila. However, there is an error since the apostrophe is seen by the program as a closing mark for the text.

Here's my code for that particular feature:

 <form action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>" method="GET">
        <select name="formStats">
            <option value="Rob">Robinson's Manila Stores</option>
            <option value="MoA">Mall of Asia Stores</option>
            <option value="GG">Greenbelt/Glorietta Stores</option>
        </select> 

        <input type="submit" name="formSubmit" value="Submit"/>
    </form>

    switch ($varStats)
    {   
        case "Rob": $show = "Mall = '2 Robinson's Manila'"; break;
        case "MoA": $show = "Mall = '3 Mall of Asia'"; break;
        case "GG": $show = "Mall = '1 Glorietta/Greenbelt Complex '"; break;
    }

I think I need to use the ` mark but I'm not sure with the exact syntax.

the problem is the apostrophe "Robinson's" in the assignment to the $show variable in the switch case. You should escape it writing "Robinson\\'s"

您可以使用mysqli_real_escape_string()函数转义字符串中的特殊字符,以用于SQL语句。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM