1
<?php
if (isset($_POST['value'])) {
    $StudentFirstName = $_POST['FirstName'];
    $StudentLastName = $_POST['LastName'];
    $OrgID = $_POST['OrganizationId'];
    $AmountRaised = $_POST['AmountRaised'];
    $Captain = $_POST['Captain'];
}

$server = "mssql.up.ist.psu.edu";
$connectionInfo = array(
    'Database' => 'pjb5422',
    'UID' => 'sqlpjb5422',
    'PWD' => 'vIPY5De2',
    'Encrypt' => '0',
    'CharacterSet' => 'UTF-8');
$connection = sqlsrv_connect($server, $connectionInfo);

if (!($connection)) {
    echo "Connection could not be established.";
    die(print_r(sqlsrv_errors(), true));
} else {

    $query = "INSERT INTO STUDENT VALUES (?,?, ?, ?, ?, ?)"; //**BUILDING AN INSERT STATEMENT

    $var = array(rand(40, 100000000), $StudentFirstName, $StudentLastName, $OrgId, $AmountRaised, $Captain);

    $sendIt = sqlsrv_query($connection, $query, $var); //submit the query

    echo "<br>Thanks for Registering!!<br><br>Go <a href='MiniThon.html'>Home</a>";
}

?>

I get the following errors and it never submits to my SQL data base

Notice: Undefined variable: StudentFirstName in \UP.IST.LOCAL\WEBSITES\pjb5422\AddDancer1.php on line 50

Notice: Undefined variable: StudentLastName in \UP.IST.LOCAL\WEBSITES\pjb5422\AddDancer1.php on line 50

Notice: Undefined variable: OrgId in \UP.IST.LOCAL\WEBSITES\pjb5422\AddDancer1.php on line 50

Notice: Undefined variable: AmountRaised in \UP.IST.LOCAL\WEBSITES\pjb5422\AddDancer1.php on line 50

Notice: Undefined variable: Captain in \UP.IST.LOCAL\WEBSITES\pjb5422\AddDancer1.php on line 50

qskane
  • 481
  • 4
  • 16
  • i recommend you change your title making it more specific to your question. form your tag and this website, it is obvious it is an error with php programming – Neville Nazerane Apr 27 '18 at 03:51

3 Answers3

4

change this line

 if (isset($_POST['value'])) { 

to check other values that are required in your form since value doesn't have anything in it causing your declared variables to be null.

I also suggest that before executing your insert query you should first check if

$StudentFirstName

and other variables are not empty before you execute the insert query.

else {
    if(!empty($StudentFirstName) && !empty($StudentLastName)){
         $query = "INSERT INTO STUDENT VALUES (?,?, ?, ?, ?, ?)"; //**BUILDING AN INSERT STATEMENT

         $var = array(rand(40,100000000),$StudentFirstName, $StudentLastName, $OrgId, $AmountRaised, $Captain);

         $sendIt = sqlsrv_query($connection, $query, $var); //submit the query

         echo "<br>Thanks for Registering!!<br><br>Go <a href='MiniThon.html'>Home</a>"; 
    }else{
      echo "Failed to insert record empty variables!";

    }

}
hungrykoala
  • 1,083
  • 1
  • 13
  • 28
1

Everything inside if (isset($_POST['value'])) { seems to not be executing. You need to check that the $_POST['value'] value is actually set to something so the variables take on the required values.

Steve
  • 1,903
  • 5
  • 22
  • 30
0

when isset($_POST['value']) return a false, your $StudentFirstName should be Undefined variable obbviously

if (isset($_POST['value'])) {
    $StudentFirstName =$_POST['FirstName'];
    //...
}
qskane
  • 481
  • 4
  • 16