0

I have a simple form to insert data to a mysql database. Data is added in both English and Russian

 <form class="form" action="add.php" accept-charset="UTF-8" method="POST">
    
    <p class="username">
      <input type="text" name="name" id="name" >
      <label for="name">product name</label>
    </p>
    
    <p class="description">
      <input type="text" name="description" >
      <label for="description">description</label>
    </p>
    
    <p class="usersubmit">
      <input type="submit" name="submit" value="Send" >
    </p>
  </form>

PHP

//fetching and storing the form data in variables
$name = $con->real_escape_string($_POST['name']);
$description = $con->real_escape_string($_POST['description']);
  //query to insert the variable data into the database
$sql="INSERT INTO products (name, description) VALUES ('".$name."','".$description ."')";

name is set to varchar(255) utf8_general_ci
description text utf8_general_ci

The above form works fine, but the problem occurs when i try to add certain Russian words.

For example, when I try to add Тегеран as the name and submit it gives me a 404 page not found error. But when I remove Т it works fine and data gets inserted. Another example is 35 Луи де Фюнес, when I submit with that, it gives a 404 error but when I remove Л it works perfectly. There are many other words with the same problem.

Can someone let me know what's causing this and how can I fix this?

Shahriar
  • 1,855
  • 2
  • 21
  • 45
LiveEn
  • 3,193
  • 12
  • 59
  • 104
  • could you try adding a `die("test")` to the top of `add.php` and check if the php file is reached when submitting the form? – MaartenDev Oct 02 '21 at 19:11
  • @MaartenDev yes. It shows ` test` actually the complete form works perfectly and it also adds the values to the database. It get the 404 error only when certain Russian characters/words are added to the name field – LiveEn Oct 02 '21 at 19:18
  • Does it also show a 404 if you put a `die();` on the first line of `add.php` and submit russian characters? – MaartenDev Oct 02 '21 at 19:23
  • @MaartenDev yes..it shows a 404 error – LiveEn Oct 02 '21 at 19:57
  • Possible duplicate: https://stackoverflow.com/questions/9046325/form-field-using-utf-8-characters-results-in-error-404-when-the-form-is-submitte – user2190492 Oct 02 '21 at 20:29
  • What happens if you just remove the form attribute `accept-charset`? – user2190492 Oct 02 '21 at 20:30
  • Did you use your browser's debug network pane to check which page is not found? Is it 'POST add.php' or a page redirected to after that POST page? – PaulH Oct 02 '21 at 21:36
  • Did you use HTML 5 by starting the document containing the form with ` ` – PaulH Oct 02 '21 at 21:41
  • @user2190492 it remains the same.. just gives the 404 – LiveEn Oct 03 '21 at 04:54
  • @PaulH console shows add.php as 404 when posting. in my case `localhost/form/add.php` is the url. so when i fill in the form and hit submit `localhost/form/add.php` shows the success message but with those Russian characters/words filled `localhost/form/add.php` shows 404. i have added on top – LiveEn Oct 03 '21 at 05:01

0 Answers0