zero_ZX Posted May 31, 2010 Share Posted May 31, 2010 Hi, I got the following two files, where emplyees can update their current status The following works just fine, no errors show: <?PHP session_start(); include("config.php"); $id = $_GET['id']; $_SESSION["id"] = $_GET['id']; // Create query $query = mysql_query("SELECT * FROM medarbejder WHERE id = '".$id."' LIMIT 1") or die(mysql_error()); if (!mysql_num_rows($query)) { die("Det indtastede ID er ugyldigt.");} while($row = mysql_fetch_array($query)) IF ($row['status']==1) { Echo "Du redigere nu status for " . $row['medarbejder'] . " "; Echo "<br> <br>"; echo "<TABLE border=1 bgcolor=#00FF00>"; echo "<tr>"; echo "<th width=700>Du er til stede</th>"; echo "</tr>"; echo "</table>"; } Else { Echo "Du redigere nu status for " . $row['medarbejder'] . " "; Echo "<br> <br>"; echo "<TABLE border=1 bgcolor=#FF0000>"; echo "<tr>"; echo "<th width=700>Du er ikke til stede</th>"; echo "</tr>"; echo "</table>"; } Echo "<br>"; Echo "Her kan du ændre din stauts:"; mysql_close($con); ?> <html> <body> <form action="opdater.php" method="post"> Status: <input type="radio" name="status" value="1" checked> Til stede <input type="radio" name="status" value="2"> Ikke til stede <br> Kommentar (maks 100 bogstaver): <input type="text" name="kommentar" style='width:300px;' MAXLENGTH=100 /> <input type="submit" /> </form> </body> </html> The following comes with this error: "Parse error: syntax error, unexpected T_STRING in C:\xampp\htdocs\kontor\opdater.php on line 19" and script looks like this: <?PHP session_start(); /*if (!$_SESSION["id"]) { // User haven't been at the edit page die ("Der kunne ikke findes en gyldig session, eller den er udløbet. Gå tilbage og prøv igen.") } */ include("config.php"); $status = mysql_real_escape_string($_POST['status']); $kommentar = mysql_real_escape_string($_POST['kommentar']); mysql_query("UPDATE medarbejder SET status = '".$status."' WHERE id = '".$_SESSION["id"]."'; mysql_query("UPDATE medarbejder SET kommentar = '".$kommentar."' WHERE id = '".$_SESSION["id"]."'; /* Echo "Din status er blevet opdateret!"; Echo "<br> <br>"; Echo "Du kan nu gå til <a href='oversigt.php'>Oversigt over medarbejdere</a>"; */ session_destroy(); ?> Any idia of what i could have done wrong? Link to comment https://forums.phpfreaks.com/topic/203419-unable-to-update-sql-via-session/ Share on other sites More sharing options...
riwan Posted May 31, 2010 Share Posted May 31, 2010 you didn't close it correctly mysql_query("UPDATE medarbejder SET status = '".$status."' WHERE id = '".$_SESSION["id"]."'"); mysql_query("UPDATE medarbejder SET kommentar = '".$kommentar."' WHERE id = '".$_SESSION["id"]."'"); Link to comment https://forums.phpfreaks.com/topic/203419-unable-to-update-sql-via-session/#findComment-1065690 Share on other sites More sharing options...
trq Posted May 31, 2010 Share Posted May 31, 2010 Also, those two queries ought be combined into one. Link to comment https://forums.phpfreaks.com/topic/203419-unable-to-update-sql-via-session/#findComment-1065693 Share on other sites More sharing options...
zero_ZX Posted May 31, 2010 Author Share Posted May 31, 2010 Thanks.. I tried to fix my code up a bit, so i got the following: <?PHP session_start(); include("config.php"); $id = $_SESSION["id"]; $status = mysql_real_escape_string($_POST['status']); $kommentar = mysql_real_escape_string($_POST['kommentar']); $sql = "UPDATE medarbejder SET status='$status', kommentar='$kommentar'WHERE '$id'"; $result = mysql_query($sql) or die(mysql_error()); echo "Din status er nu blevet opdateret."; /*IF ($oversigt==1) echo "<br>"; echo "<a href='oversigt.php'>Klik her for at gå til oversigten</a><br />"; */ session_destroy(); mysql_close($con); ?> Now it works, when you update.. or it doesn't display any error.. stil nothing is updated in the database :/ Link to comment https://forums.phpfreaks.com/topic/203419-unable-to-update-sql-via-session/#findComment-1065711 Share on other sites More sharing options...
zero_ZX Posted May 31, 2010 Author Share Posted May 31, 2010 nvm, i have miss seen my id = lol Link to comment https://forums.phpfreaks.com/topic/203419-unable-to-update-sql-via-session/#findComment-1065718 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.