Inserting multiple rows from a php form into the database

后端 未结 3 1606
[愿得一人]
[愿得一人] 2021-01-16 19:43

my form as the following table (of textfeild). I am feeding the values into these textfeild. How can i enter these values into my database? plz help.

3条回答
  •  南笙
    南笙 (楼主)
    2021-01-16 20:36

    Multiple row inserts in SQL are simply multiple parenthesis with commas, (), (), ();

    You are also NOT escaping your data! You must escape ALL your data regardless of text or binary. It is simple and you must never fail to escape data. I escape data even if it's come directly out of my database, a hacker could post code in say a blog comment, it gets commented out, but then for some reason if I handle that comment it could later execute.

    $roll = mysql_real_escape_string($_POST['roll');
    

    So just do this...

    INSERT INTO table (roll, name, unit_test, prelims, average, attendance, file, interm) VALUES 
    ('$roll','$name','$unit_test','$prelims','$average'=(('$unit_test' + '$prelims')/125) *10,'$attendance','$file','$average'+'$attendance'+'$file'),
    ('$roll','$name','$unit_test','$prelims','$average'=(('$unit_test' + '$prelims')/125) *10,'$attendance','$file','$average'+'$attendance'+'$file'),
    ('$roll','$name','$unit_test','$prelims','$average'=(('$unit_test' + '$prelims')/125) *10,'$attendance','$file','$average'+'$attendance'+'$file'),
    ('$roll','$name','$unit_test','$prelims','$average'=(('$unit_test' + '$prelims')/125) *10,'$attendance','$file','$average'+'$attendance'+'$file');
    

提交回复
热议问题