Jump to content

Recommended Posts

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

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 :/

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.