SolveErrors
PHP

PHP-General - Variabses wont load

48 views

I've made an form in php but it wont load all variables from text fields,it loads just 7 of 9 variables..
I wanted to post download and example link but its against the rules so ill just copy the code here...
index.php
PHP Code:
<html>
<
head>
    <
title>Upitniktitle>
    <
script type="text/javascript" src="jquery.min.js">










Ime: 
" size="35" />
Starost: 
" size="2" maxlength="2" />



Fakultet ili druga skola koju si konkurisao: 
Navedi naziv i mesto obrazovne ustanove(Grad i drzavu ako je u inostranstvu).
" size="35" />
Smer/Odsek: 
" size="35" />
Vrsta skole: ">
   
  Drzavna
  Privatna
  Ostalo
     

 Da li je to bila tvoja "Prva Zelja"?

 ">
   
  Da
  Ne
    


Uspek na upisu: 

 ">
   
  Primljen/a sam na budzet
  Primljen/a sam na samofinansiranje
  Upisao-la sam se na privatni fakultet/skolu
  Nisam uspeo/la da se upisem
  Necu nigde konkurisati
    
Tvoje mesto na rang listi: " size="35" />






Napisi nesto sto zelis a da nismo pitali:  
" size="35" />








 

process.php
PHP Code:
$allowedFields = array(
    
'Name',
    
'Starost',
    
'Skola',
    
'Smer',
    
'Vrsta',
    
'Zelja',
    
'Uspeh',
    
'Rang',
    
'comment',
);


$requiredFields = array(
    
'Name',
    
'Starost',
    
'Skola',
    
'Smer',
    
'Vrsta',
    
'Zelja',
    
'Uspeh',
    
'Rang',
);
$errors = array();
foreach(
$_POST AS $key => $value)
{
    
// first need to make sure this is an allowed field
    
if(in_array($key, $allowedFields))
    {
        $
$key = $value;
        
        
// is this a required field?
        
if(in_array($key, $requiredFields) && $value == '')    
        {
            
$errors[] = "The field $key is required.";
        }
    }    
}


if(
count($errors) > 0)
{
    
$errorString = '

There was an error processing the form.

'
;
    
$errorString .= '
    ';
        foreach(
    $errors as $error)
        {
            
    $errorString .= "
  • $error
  • "
    ;
        }
        
    $errorString .= '
'
;
    
    
// display the previous form
    
include 'index.php';
}
else
    
{
/*    $filename = "$Name.txt";
    if (file_exists($filename)) {
    echo "The file $filename already exists";
    echo  "Back";
    } else {
    $filename = "$Name.txt";
    $myFile = $filename;
    $fh = fopen($myFile, 'w') or die("can't open file");
    fwrite($fh, "Ime:");
    fwrite($fh, " ".$Name."\r\n");
    fwrite($fh, "Starost:");
    fwrite($fh, " ".$Starost."\r\n");
    fwrite($fh, "Skola:");
    fwrite($fh, " ".$Skola."\r\n");    
    fwrite($fh, "Vrsta:");
    fwrite($fh, " ".$Vrsta."\r\n");    
    fwrite($fh, "Prva Zelja:");
    fwrite($fh, " ".$Zelja1."\r\n");    
    fwrite($fh, "Uspeh:");
    fwrite($fh, " ".$Uspeh."\r\n");    
    fwrite($fh, "Mesto na rang listi:");
    fwrite($fh, " ".$Rang."\r\n");    
    fwrite($fh, "Komentar:");
    fwrite($fh, " ".$comment."\r\n");    
    fclose($fh);*/
    
echo "$Name,$Starost,$Skola,$Smer,$Vrsta,$Zelja,$Uspeh,$Rang,$comment";
    }
}
,
Thanks, it was a stupid mistake with case sensitive letters :S

More PHP fixes

PHP-General - Header tag not directing to specified pageindex.php wont load index.html will loadHow to cut down the size of a URL?Warning: oci_free_statement(): 3 is not a valid oci8 statement resourcePage 2 - str_replaceSyntax help - $random_name