-3

i'm a beginner

i get this error

Parse error: syntax error, unexpected '"idnumber"' (T_CONSTANT_ENCAPSED_STRING) in /storage/h6/783/918783/public_html/add_student_info.php on line 8

this is my code--->>

    <?php

    $host = "mmsis.000webhostapp.com";
    $user = "id918783_mdb";
    $password = "";
    $db = "id918783_mmsisdb";

    $id_number = $_POST"idnumber";
    $first_name = $_POST"firstname";
    $middle_name = $_POST"middlename";
    $last_name = $_POST"lastname";
    $course = $_POST"course";
    $password = $_POST"password";
    $confirm_password = $_POST"confirmpassword";
    $barangay = $_POST"barangay";
    $zip_code = $_POST"zipcode";

    $query = "insert into tblStudentInfo values ('$first_name','$middle_name','$last_name','$course','$password','$confirm_password','$barangay','$zip_code'); ";

    mysqli_query(mysqli_connect($host,$user,$password,$db),$query)
    ?>

what might be the problem??please help

2 Answers2

1

$_POST is an associated array. You would access $_POST as you would have access any other associated array. Which is like the following: $_POST["some_key"].

In your code, you are missing the brackets '[]' to access the variables stored in the $_POST.

Your code should look more like this (assuming all the keys existing, otherwise you will get error):

    $id_number = $_POST["idnumber"];
    $first_name = $_POST["firstname"];
    $middle_name = $_POST["middlename"];
    $last_name = $_POST["lastname"];
    $course = $_POST["course"];
    $password = $_POST["password"];
    $confirm_password = $_POST["confirmpassword"];
    $barangay = $_POST["barangay"];
    $zip_code = $_POST["zipcode"];`
MaD
  • 780
  • 7
  • 19
  • $_POST is not just used like an array, it is an associated array, see here: http://php.net/manual/en/reserved.variables.post.php – Lajos Arpad Mar 19 '17 at 07:18
  • Mad, $_POST is not only like an associated array, it is an associated array. Your answer still compares $_POST to an (associated) array which is misleading to beginners, who will not understand that $_POST is an array. You need to fix that to earn my upvote. – Lajos Arpad Mar 19 '17 at 07:39
  • Did not compare the two. Just mentioned that you can access both the same way. The "association" just slipped my mind though. – MaD Mar 19 '17 at 07:52
  • Now it's a nice answer. – Lajos Arpad Mar 19 '17 at 08:00
1

Replace $_POST"idnumber" with $_POST["idnumber"] and other also.

<?php

$host = "mmsis.000webhostapp.com";
$user = "id918783_mdb";
$password = "";
$db = "id918783_mmsisdb";

$id_number = $_POST["idnumber"];
$first_name = $_POST["firstname"];
$middle_name = $_POST["middlename"];
$last_name = $_POST["lastname"];
$course = $_POST["course"];
$password = $_POST["password"];
$confirm_password = $_POST["confirmpassword"];
$barangay = $_POST["barangay"];
$zip_code = $_POST["zipcode"];

$query = "insert into tblStudentInfo values ('$first_name','$middle_name','$last_name','$course','$password','$confirm_password','$barangay','$zip_code'); ";

mysqli_query(mysqli_connect($host,$user,$password,$db),$query)
?>
Rafiqul Islam
  • 1,636
  • 1
  • 12
  • 25