0

I have a html form that amens 4 fields which are populated from a database. I have my sql update statment inside an if statment but the but I am never gtting inti the if statment. I have been looking at this code now for ages and can not see my mistake. Any help would be greatfully appreciated. Thanks in advance.

                <form action="" method="post">
                    Name: <input type="text" name="eventNameAmd" value="<?php echo $row['Location'];?>" size="29">
                    Start Date: <input type="text" name="eventSDateAmd" id="datepicker3" value="<?php echo $row['Start_Date'];?>" size="17">
                    Finish Date: <input type="text" name="eventFDateAmd" value="<?php echo $row['Finish_Date'];?>" id="datepicker4" size="17">
                    Number of Stages: <input type="text" name="numStagesAmd" size="3" value="<?php echo $row['No_Stages'];?>">
                <input type="submit" name="submitEventAmd" value="Edit Event">
                </form> 
            <?php
                if(isSet($_POST['submitEventAmd']) && !empty($_POST['eventNameAmd']) && !empty($_POST['eventSDateAmd']) && 
                                        !empty($_POST['eventFDateAmd']) && !empty($_POST['numStagesAmd']))
                {
                    $nameAmd = $_POST['eventNameAmd'];
                    $sDateAmd = date("Y-m-d", strtotime($_POST['eventSDateAmd']));
                    $fDateAmd = date("Y-m-d", strtotime($_POST['eventFDateAmd']));
                    $numStagesAmd = $_POST['numStagesAmd'];

                    $sql="UPDATE Event SET Location = '$nameAmd'
                          WHERE Event_Id = '$id'";

                    if (!mysqli_query($con,$sql))
                    {
                        die('Error: ' . mysqli_error($con));
                    }
                    else
                    {
                        ?>
                        <div id="toggle">
                        <?php
                        echo "1 Event Amended";
                        ?>
                        </div>
                        <?php
                    }
Drixson Oseña
  • 3,631
  • 3
  • 23
  • 36
Alan Mulligan
  • 1,107
  • 2
  • 16
  • 35
  • first is your `isSet()` it should be `isset()` all in lowercase – Drixson Oseña Nov 05 '13 at 22:17
  • @DrixsonOseña Isn't PHP case insensitive? – kapa Nov 05 '13 at 22:23
  • 1
    Try adding a `var_dump($_POST)` call before the if-statement to see which parameters are actually set and which values they have. On a side node: Your code is vulnerable to both [SQL injection](http://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php) and [Cross-Site Scripting](http://stackoverflow.com/questions/129677/whats-the-best-method-for-sanitizing-user-input-with-php) attacks; you might want to check up on that. – helmbert Nov 05 '13 at 22:24
  • @bažmegakapa could be because he will get error for the unknown function but OP should know about it and i believe in php instead of using camelback names it should be separated in underscores `_` – Drixson Oseña Nov 05 '13 at 22:28
  • This code is vulnerable to SQL injection! – kapa Nov 05 '13 at 22:32
  • @DrixsonOseña As far as I remember PHP, you could write `isset()`, `ISSET()`, `isSet()` or `iSsEt()` and it should still be the same thing. – kapa Nov 05 '13 at 22:34
  • @bažmegakapa Alright, `it not should be all in lowercase` but for formality and the majority how dev uses the function :) – Drixson Oseña Nov 05 '13 at 22:42
  • 1
    @DrixsonOseña The best practice is to write it `isset()` of course. But this is the smallest problem in this code :). – kapa Nov 05 '13 at 22:47

2 Answers2

0

Change this:

if(isSet($_POST['submitEventAmd']) && !empty($_POST['eventNameAmd']) && !empty($_POST['eventSDateAmd']) && 
                                        !empty($_POST['eventFDateAmd']) && !empty($_POST['numStagesAmd']))

to this:

if(isset($_POST['submitEventAmd']) && !empty($_POST['eventNameAmd']) && !empty($_POST['eventSDateAmd']) && 
                                        !empty($_POST['eventFDateAmd']) && !empty($_POST['numStagesAmd']))

After that try to debug your variable to understand which of that are empty or not the value that you expected

Alessandro Minoccheri
  • 35,521
  • 22
  • 122
  • 171
0

remove your

isSet($_POST['submitEventAmd']) &&

?

I wouldn't check this value in if statement. if it still not working, check each value inside the form by echoing it. Hope it helps.

SCV
  • 406
  • 2
  • 14