Anzeo Posted August 17, 2007 Share Posted August 17, 2007 Argh, Okay i've checked my code like a thousand times and it seems to me there're no syntax errors in it, but I still don't manage to get the damn thing working. It's a script to update an event stored in a db, you can edit both the description as the date of the event. Here's my code: <?php // Formulierverwerking if($_POST) { $Auteur = $_SESSION['UID']; $EventDagNieuw = $_POST[EventDag]; $EventMaandNieuw = $_POST[EventMaand]; $EventJaarNieuw = $_POST[EventJaar]; $EventDatumNieuw = "$EventJaarNieuw-$EventMaandNieuw-$EventDagNieuw"; $BeschrijvingNieuw = $_POST[beschrijving]; echo "$EventDatumNieuw $BeschrijvingNieuw $EventID"; //maak een array aan met alle numerieke waarden van maanden die slechts 30 dagen tellen (februari uitgezondert) $KorteMaand = array("4","6","9","11"); //error handling $errors = array(); if(in_array($EventMaandNieuw,$KorteMaand) && $EventDagNieuw > 30) { $errors[] = "Het aantal dagen in $MaandVoluit[$EventMaandNieuw] bedraagt slechts 30"; } if(isLeapYear($EventJaarNieuw) == FALSE && $EventMaandNieuw == "02" && $EventDagNieuw > "28") { $errors[] = "Het aantal dagen in februari $EventJaarNieuw bedraagt slechts 28"; } if(isLeapYear($EventJaarNieuw) == TRUE && $EventMaandNieuw == "02" && $EventDagNieuw > "29") { $errors[] = "Het aantal dagen in februari $EventJaarNieuw bedraagt slechts 29"; } if(empty($BeschrijvingNieuw) || trim($BeschrijvingNieuw) == "") { $errors[] = "Je moet een beschrijving opgeven voor het event"; } if($_SESSION[Logged] !== "Y") { $errors[] = "Je hebt geen toestemming om deze actie uit te voeren"; } if(count($errors) > 0) { echo "<div class='error notificationbox'><div class='notification'>"; foreach($errors as $err) { echo "$err<br />"; } echo "</div></div>"; } else { $editeventqry = "UPDATE EVENT SET Beschrijving='$BeschrijvingNieuw', Datum='$EventDatumNieuw' WHERE ID='$EventID'"; if($result = mysql_query($editeventqry)) { echo "<div class='check notificationbox'><div class='notification'>Het event is aangepast</div></div>"; } else echo "Query mislukt <br />$sql<br />" . mysql_error(); } } // GET variabelen zodat we alle info omtrent dit event kunnen ophalen uit de DB if(!$_POST) { $EventID = $_GET['id']; $fetchqry = "SELECT * FROM EVENT WHERE ID='$EventID'"; if($result = mysql_query($fetchqry)) { if(mysql_num_rows($result)) { $fetcharray = mysql_fetch_array($result); $EventBeschrijvingOud = $fetcharray['Beschrijving']; $EventDatumOud = $fetcharray['Datum']; list($EventJaarOud,$EventMaandOud,$EventDagOud) = explode("-",$EventDatumOud); } else { echo "<div class='error notificationbox'><div class='notification'>Het event is niet aanwezig in de databank</div></div>"; } } else { echo "<div class='error notificationbox'><div class='notification'>Query mislukt <br />$sql<br />" .mysql_error()."</div></div>"; } } ?> <div class="formbox"> <form method="post" action=""> <div class="postheader"><h2>Voeg een event toe</h2></div> <div class="postbody"> <label>Datum:</label> <?php $StartJaar = date('Y'); $EindJaar = $StartJaar + 10; echo dropDownDate('EventDag', 1, 31, $EventDagOud), ' <strong>/</strong> ', dropDownDate('EventMaand', 1, 12, $EventMaandOud) , ' <strong>/</strong> ', dropDownDate('EventJaar', $StartJaar, $EindJaar, $EventJaarOud); ?> <label for="Beschrijving">Beschrijving:</label> <textarea name="Beschrijving" wrap="virtual"><?php echo "$EventBeschrijvingOud";?></textarea> <div class="buttonbox"> <input class="button" type="reset" name="reset" value="Wis"/> <input class="button" type="submit" name="submit" value="Verstuur"/> </div> <input class="formend" type="hidden" name="formend"/> <div class="postbtm"></div> </div> </form> </div> Can anyone spot a mistake? If so, you would save me from losing my mental health. In other words: Help's greatly appreciated. Thanks in advance, Anzeo Quote Link to comment https://forums.phpfreaks.com/topic/65426-solved-problem-with-editing-a-table/ Share on other sites More sharing options...
lemmin Posted August 17, 2007 Share Posted August 17, 2007 What does the mysql_error() print out? How do you mean it isn't working. If there are no errors and it just isn't updating the table, the only thing could be that there are no rows that have an ID of $EventID. Try printing out $EventID before the query to see if it does match anything. Quote Link to comment https://forums.phpfreaks.com/topic/65426-solved-problem-with-editing-a-table/#findComment-326782 Share on other sites More sharing options...
Anzeo Posted August 17, 2007 Author Share Posted August 17, 2007 I don't receive a mysql_error. I know the rows exsist, because (in the lower part of my code) it fetches all data related to the event with the id and it fills in the form as it's supposed to do. But when I change the description, it transfers correctly past the form (so we're now in the upper part of the code), i echoed it out and it are the editted variables which are printed out. I get a message saying the event is updated, however, it is not.. Quote Link to comment https://forums.phpfreaks.com/topic/65426-solved-problem-with-editing-a-table/#findComment-326824 Share on other sites More sharing options...
Anzeo Posted August 17, 2007 Author Share Posted August 17, 2007 Nevermind, got it working ^^ Sorry for wasting your time FYI: The problem was that the variable ID was undefined, though it gave a result. I added a line in the upper part of the code which uses a second get to fetch the variable id again. Quote Link to comment https://forums.phpfreaks.com/topic/65426-solved-problem-with-editing-a-table/#findComment-326915 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.