-1

column namesI am getting error Line of insert state marked with -->

   $result = mysql_query("INSERT INTO NamazTiming 
(`FajarAzan`,`FajarZamat`,`ZoharAzan`,`ZoharJamat`,`AsarAzan`,`AsarJamat`,`Maghrib`,`IshaAzan`,`IshaJamat`,`JumaAzan`,`JumaJamat`,`Taraweeh`,`FromDate`,`ToDate`,`MasjidID_FK`)
VALUES
('$FajarAzan',
'$FajarJamat',
'$ZoharAzan',
'$ZoharJamat',
'$AsarAzan',
'$AsarJamat',
'$Maghrib',
'$IshaAzan',
'$IshaJamat',
'$JumaAzan',
'$JumaJamat',
'$Taraweeh',
'$FromDate',
'$ToDate',

--> '$MasjidID'") or die mysql_error();

Please suggest solution!!

    <?php
/*
 * Following code will create a new product row
 * All product details are read from HTTP Post Request
 */

// array for JSON response
$response = array();

// check for required fields
if (isset($_POST['FajarAzan']) && isset($_POST['FajarJamat']) && isset($_POST['ZoharAzan'])&& isset($_POST['ZoharJamat'])&& isset($_POST['AsarAzan'])&& isset($_POST['AsarJamat'])&& isset($_POST['Maghrib'])&& isset($_POST['IshaAzan'])&& isset($_POST['IshaJamat'])&& isset($_POST['JumaAzan'])&& isset($_POST['JumaJamat'])&& isset($_POST['Taraweeh'])&& isset($_POST['FromDate'])&& isset($_POST['ToDate'])&& isset($_POST['MasjidID']) && isset($_POST['MasjidID']) ) {

    $FajarAzan = $_POST['FajarAzan'];
    $FajarJamat = $_POST['FajarJamat'];
    $ZoharAzan = $_POST['ZoharAzan'];
    $ZoharJamat = $_POST['ZoharJamat'];
    $AsarAzan = $_POST['AsarAzan'];
    $AsarJamat = $_POST['AsarJamat'];
    $Maghrib = $_POST['Maghrib'];
    $IshaAzan = $_POST['IshaAzan'];
    $IshaJamat = $_POST['IshaJamat'];
    $JumaAzan = $_POST['JumaAzan'];
    $JumaJamat = $_POST['JumaJamat'];
    $Taraweeh = $_POST['Taraweeh'];
    $FromDate = $_POST['FromDate'];
    $ToDate = $_POST['ToDate'];
    $MasjidID = $_POST['MasjidID'];


    // include db connect class
//    require_once __DIR__ . '/db_connect.php';
require_once dirname(__FILE__ ). '/db_connect.php';;

    // connecting to db
    $db = new DB_CONNECT();

    // mysql inserting a new row
    $result = mysql_query("INSERT INTO NamazTiming 
(`FajarAzan`,`FajarZamat`,`ZoharAzan`,`ZoharJamat`,`AsarAzan`,`AsarJamat`,`Maghrib`,`IshaAzan`,`IshaJamat`,`JumaAzan`,`JumaJamat`,`Taraweeh`,`FromDate`,`ToDate`,`MasjidID_FK`)
VALUES
('$FajarAzan',
'$FajarJamat',
'$ZoharAzan',
'$ZoharJamat',
'$AsarAzan',
'$AsarJamat',
'$Maghrib',
'$IshaAzan',
'$IshaJamat',
'$JumaAzan',
'$JumaJamat',
'$Taraweeh',
'$FromDate',
'$ToDate',
'$MasjidID'") or die mysql_error();

    // check if row inserted or not
    if ($result) {
        // successfully inserted into database
        $response["success"] = 1;
        $response["message"] = "masjid successfully created.";

        // echoing JSON response
        echo json_encode($response);
    } else {
        // failed to insert row
        $response["success"] = 0;
        $response["message"] = "Oops! An error occurred.";

        // echoing JSON response
        echo json_encode($response);
    }
} else {
    // required field is missing
    $response["success"] = 0;
    $response["message"] = "Required field(s) is missing";

    // echoing JSON response
    echo json_encode($response);
}
?>
Lionel Chan
  • 7,894
  • 5
  • 40
  • 69
user3671032
  • 211
  • 2
  • 16

1 Answers1

2

You are missing a pair of opening and closing bracket in your die function, and hence the unexpected 'mysql_error' (T_STRING) because PHP is expecting a opening bracket.

Original

'$MasjidID'") or die mysql_error();


Solution

'$MasjidID')") or die(mysql_error());


Additional Note

You code is susceptible to query injection if you did not escape your variables properly. Take $MasjidID for example. If this variable contains a quote ", it will fail your query, and more dangerously, leak your database and further lost your server.

Try doing mysql_real_escape_string first before passing it straight to the query may help preventing it.

Lionel Chan
  • 7,894
  • 5
  • 40
  • 69
  • that worked butn now I am getting the 'required fields missing' message for the post url c/add_new_from_to_date_masjidid.php?FajarAzan=20:20:00&FajarJamat=20:20:00&ZoharAzan=20:20:00&ZoharJamat=20:20:00&AsarAzan=11:11:11&AsarJamat=22:22:22&Maghrib=00:00:12&IshaAzan=11:11:33&IshaJamat=13:13:13&JumaAzan=00:00:00&JumaJamat=00:00:33&Taraweeh=11:11:00&FromDate=2014-06-11&ToDate=2014-05-16&MasjidID=32 – user3671032 Jun 22 '14 at 03:28
  • If the URL formed like that, it means you are doing a `
    ` with GET. Add a `
    ` in your form to trigger a POST instead of GET.
    – Lionel Chan Jun 22 '14 at 03:29
  • 1
    Don't use `mysql_*`, use "mysqli api" or PDO: http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php – Protomen Jun 22 '14 at 04:01
  • @GuilhermeNascimento no choice. OP already used mysql_*, so try not to off topic too much ;) – Lionel Chan Jun 22 '14 at 04:05