Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

Variable empty

php if statement variable

  • Please log in to reply
3 replies to this topic

#1 Dorgon

Dorgon

    CC Regular

  • Member
  • PipPipPip
  • 37 posts

Posted 07 November 2012 - 12:12 PM

Good evening,

I already posted it in the html forum but i think this fits better in the PHP forum.
At the moment I am making a simple interface to use a small part of my application.
The problem is that in the last if statement $CurrentStudent is just an empty object of Student while it should be filled by the first if statement.
I tried infinity things but nothing worked.

here is my code:
<?php
// ALLE classes includen
$Folder = '../Classes/';
if ($Handle = opendir($Folder)) {
    while (false !== ($Entry = readdir($Handle))) {
	    if ($Entry != "." && $Entry != "..") {
		    require_once($Folder.$Entry);
	    }
    }
    closedir($Handle);
}
// eind
require_once('../Datalayer/Utilities/DAOFactory.php');
require_once('../Datalayer/Utilities/DBObject.php');
require_once('../Datalayer/MYSQL/MYSQLDAOFactory.php');
require_once('../Datalayer/MYSQL/MYSQLStudentDAO.php');
include('../TemplateHTML/bovenkant.tpl.html');

DAOFactory::setCurrentFactory(new MYSQLDAOFactory());
$Email = '';
$Voornaam = '';
$Achternaam = '';
$TussenVoegsel = '';
$Wachtwoord = '';
$Geslacht = '';
$OVnummer = '';
$CurrentStudent = new Student($Voornaam, $Achternaam, $TussenVoegsel, $Wachtwoord, $Email, $Geslacht, $OVnummer);
?>

<form name="form1" method="post" action="">
    <center>
    Voer het E-mail adres in van de student:<br />
    <input name="email" type="text" maxlength="50" /> <br />
    <input type="submit" name="submit" value="Haal op">
    </center>
</form>


<?php
// SUBMIT BUTTON
if (isset($_POST['submit']) && !empty($_POST['email'])){
    $Email = $_POST['email'];
    $CurrentStudent->setEmail($Email);
    $CurrentStudent->loadStudent($CurrentStudent);
    
    ?>
    <form method="post" action="">
        <center>
        <b>Voornaam:</b><br />
        <?php echo $CurrentStudent->getVoornaam();?><br />
        <b>Achternaam</b>:<br />
        <?php echo $CurrentStudent->getAchternaam();?><br />
        <b>Tussenvoegsel:</b><br />
        <?php echo $CurrentStudent->getTussenVoegsel();?><br />
        <b>Email:</b><br />
        <?php echo $CurrentStudent->getEmail();?><br />
        <b>Geslacht:</b><br />
        <?php
        //
        $Geslacht = $CurrentStudent->getGeslacht();
        if($Geslacht == 1){
            echo 'man';
        }
        else{
            echo 'vrouw';
        }
        // OMZETTEN VAN BOOLEAN NAAR MAN/VROUW.
        ?><br />
        <b>Ovnummer:</b><br />
        <?php echo $CurrentStudent->getOVnummer();?><br />
        <input type="submit" name="delete" value="Delete">
        </center>
    </form><?php
}

if( isset($_POST['delete'])) {
    $CurrentStudent->deleteStudent($CurrentStudent);
}

include('../TemplateHTML/onderkant.tpl.html');

thanks in advance.
  • 0

#2 WingedPanther73

WingedPanther73

    A spammer's worst nightmare

  • Moderator
  • 17757 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others

Posted 08 November 2012 - 06:20 AM

Have you confirmed that you're getting into your if statement?
  • 0

Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

My MineCraft server site: http://banishedwings.enjin.com/


#3 wim DC

wim DC

    Roar

  • Expert Member
  • PipPipPipPipPipPipPipPip
  • 2681 posts
  • Programming Language:Java, JavaScript, PL/SQL
  • Learning:Python

Posted 08 November 2012 - 06:44 AM

Both if-statements will never be BOTH true. Either you click on the button named 'submit', or you click on the button named 'delete'.
  • 0

#4 Dorgon

Dorgon

    CC Regular

  • Member
  • PipPipPip
  • 37 posts

Posted 08 November 2012 - 08:49 AM

Thanks for the reactions, but i'd solved it by my self.
I still have to make the object $CurrentStudent a session variable so I don't need te make an other object of student to delete it.
<?php
// ALLE classes includen
$Folder = '../Classes/';
if ($Handle = opendir($Folder)) {
    while (false !== ($Entry = readdir($Handle))) {
	    if ($Entry != "." && $Entry != "..") {
		    require_once($Folder.$Entry);
	    }
    }
    closedir($Handle);
}
// eind
require_once('../Datalayer/Utilities/DAOFactory.php');
require_once('../Datalayer/Utilities/DBObject.php');
require_once('../Datalayer/MYSQL/MYSQLDAOFactory.php');
require_once('../Datalayer/MYSQL/MYSQLStudentDAO.php');
include('../TemplateHTML/bovenkant.tpl.html');
session_start()
?>

<form name="form1" method="post" action="">
    <center>
    Voer het E-mail adres in van de student:<br />
    <input name="email" type="text" maxlength="50" /> <br />
    <input type="submit" name="submit" value="Haal op">
    </center>
</form>


<?php
DAOFactory::setCurrentFactory(new MYSQLDAOFactory());
// SUBMIT BUTTON
if (isset($_POST['submit']) && !empty($_POST['email'])){
    
    $Email = '';
    $Voornaam = '';
    $Achternaam = '';
    $TussenVoegsel = '';
    $Wachtwoord = '';
    $Geslacht = '';
    $OVnummer = '';
    $CurrentStudent = new Student($Voornaam, $Achternaam, $TussenVoegsel, $Wachtwoord, $Email, $Geslacht, $OVnummer);
    $_SESSION['email'] = $_POST['email'];
    $Email = $_POST['email'];
    $CurrentStudent->setEmail($Email);
    $CurrentStudent->loadStudent($CurrentStudent);
    $OVnummer = $CurrentStudent->getOVnummer();
    
    if ($OVnummer != ""){
        ?>
        <form method="post" action="">
            <center>
            <b>Voornaam:</b><br />
            <?php echo $CurrentStudent->getVoornaam();?><br />
            <b>Achternaam</b>:<br />
            <?php echo $CurrentStudent->getAchternaam();?><br />
            <b>Tussenvoegsel:</b><br />
            <?php echo $CurrentStudent->getTussenVoegsel();?><br />
            <b>Email:</b><br />
            <?php echo $CurrentStudent->getEmail();?><br />
            <b>Geslacht:</b><br />
            <?php
            //
            $Geslacht = $CurrentStudent->getGeslacht();
            if($Geslacht == 1){
                echo 'man';
            }
            else{
                echo 'vrouw';
            }
            // OMZETTEN VAN BOOLEAN NAAR MAN/VROUW.
            ?><br />
            <b>Ovnummer:</b><br />
            <?php echo $CurrentStudent->getOVnummer();?><br />
            <input type="submit" name="delete" value="Delete" onclick="Javascript:alert('Student deleted!')">
            </center>
        </form><?php
    }
    else {
        ?><SCRIPT language="Javascript">
            alert('Student not found!');
        </SCRIPT> <?php
    }
}
if( isset($_POST['delete'])) {
    $Email = $_SESSION['email'];
    $Voornaam = '';
    $Achternaam = '';
    $TussenVoegsel = '';
    $Wachtwoord = '';
    $Geslacht = '';
    $OVnummer = '';
    $NewStudent = new Student($Voornaam, $Achternaam, $TussenVoegsel, $Wachtwoord, $Email, $Geslacht, $OVnummer);

    $NewStudent->deleteStudent($NewStudent);
}

include('../TemplateHTML/onderkant.tpl.html');
 

  • 0





Also tagged with one or more of these keywords: php, if, statement, variable

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download