Jump to content

Mysql, select or die


zero_ZX

Recommended Posts

Hi! :D

I'm working out a tiny script to change status of employees in different rooms, so far it all goes good, however I have a problem.

A user goes to an edit.php?id=xxxxx where they can change their stauts, however if the id is invalid, or they don't put an id at all The script still continues.. And my html form shows :/

 

So i have 2 questions..

How would i make the script die if nothing can be found when executing the query, and can i put my forms into the php tags instead of html?

 

Also, what would be the best way to perform the edit?

Should i link to form to another page like perform.php or should i make something like edit.php?id=blabla&status=0&comment=Back in an hour

I'm not so sure of this..

Also i would like to strip off all kinds of tags and special characters in the update field, so users don't put anything silly there..

 

This is my current code

<?PHP
include("config.php");

$id = $_GET['id'];


// Create query


$query = mysql_query("SELECT * FROM medarbejder WHERE id = '".$id."' LIMIT 1") 
or die(mysql_error());


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> 

Link to comment
Share on other sites

well, before you query you could check first the id, if its empty then put die() or exit().

then after query (before the loop while) you could check the query result using mysql_num_rows() if it found anything or not and then again put die() or exit()

Link to comment
Share on other sites

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.