1

i'm trying to insert values from fields to the database, i have 10 fields 5 of them is dynamic

when i insert write the values in the fields, only the static values that add to the database but the dynamic doesn't

i'm using Dreamweaver to do this project for school

the insert query

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
    $sRoom = $_POST['sRoom'];
    $sDay = $_POST['sDay'];
    $sStartTime = $_POST['sStartTime'];
    $sLateTime = $_POST['sLateTime'];
    $sEndTime = $_POST['sEndTime'];

    for($i=0;$i<count($sDay);$i++){
  $insertSQL = sprintf("INSERT INTO `section` (sNumber, sStartTime, sLateTime, sEndTime, sRoom, sInstructor, sCourseCode, sStartDate, sEndDate, `day`) VALUES (%s, '$sStartTime[i]', '$sLateTime[i]', '$sEndTime[i]', '$sRoom[i]', %s, %s, %s, %s, '$sDay[i]')",
                       GetSQLValueString($_POST['sNumber'], "int"),
                       GetSQLValueString($_POST['sInstractor'], "text"),
                       GetSQLValueString($_POST['sCourse'], "text"),
                       GetSQLValueString($_POST['date'], "date"),
                       GetSQLValueString($_POST['date2'], "date"));

  mysql_select_db($database_dbc, $dbc);
  $Result1 = mysql_query($insertSQL, $dbc) or die(mysql_error());}}
  • 1
    your code is too long, try to minimize it and only show the necessary parts – Masivuye Cokile Apr 04 '17 at 13:13
  • Every time you use [the `mysql_`](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php) database extension in new code **[this happens](http://2.bp.blogspot.com/-zCT6jizimfI/UjJ5UTb_BeI/AAAAAAAACgg/AS6XCd6aNdg/s1600/luna_getting_strangled.jpg)** it is deprecated and has been for years and is gone for ever in PHP7. If you are just learning PHP, spend your energies learning the `PDO` or `mysqli` database extensions and prepared statements. [Start here](http://php.net/manual/en/book.pdo.php) – RiggsFolly Apr 04 '17 at 13:14
  • You dont need to select_db all over the place, once per script is enough – RiggsFolly Apr 04 '17 at 13:15
  • Some sensible code indentation would be a good idea. It helps us read the code and more importantly it will help **you debug your code** [Take a quick look at a coding standard](http://www.php-fig.org/psr/psr-2/) for your own benefit. You may be asked to amend this code in a few weeks/months and you will thank me in the end. – RiggsFolly Apr 04 '17 at 13:15
  • `get_magic_quotes_gpc()` What version of PHP are you using? – RiggsFolly Apr 04 '17 at 13:16
  • Please read [What topics can I ask about](http://stackoverflow.com/help/on-topic) and [How to ask a good question](http://stackoverflow.com/help/how-to-ask) and [the perfect question](http://codeblog.jonskeet.uk/2010/08/29/writing-the-perfect-question/) and how to create a [Minimal, Complete and Verifiable example](http://stackoverflow.com/help/mcve) – RiggsFolly Apr 04 '17 at 13:17
  • sorry i update the question and remove most of the code – Mohammed Alabdullatif Apr 04 '17 at 13:34

0 Answers0