07 Shtimi i te dhenave ne DB

Ne kete leksion

MySQL

Faqa add.php

  1. <html>

  2. <head>

  3. <title>Add a new Category</title>

  4. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

  5. </head>

  6. <body>

  7. <form action="add1.php" method="post" >

  8. <p>

  9. catname:<input type="text" name="catname"> jepni emrin e kategorise

  10. </p>

  11. <p>

  12. catdesc:

  13. <textarea name="catdesc" rows="5" cols="40">

  14. </textarea>

  15. </p>

  16. <p>

  17. icon:<input type="text" name="icon"> jepni ikonen e kategorise

  18. </p>

  19. <p>

  20. displayorder:<input type="text" name="displayorder">

  21. jepni rendin ne te cilin doni te shfaqet kategoria</p>

  22. <p>

  23. <input type="submit" value="RUAJ">

  24. </p>

  25. </form>

  26. </body>

  27. </html>

Faqa add1.php

  1. <?php

  2. require("db.php");

  3. $catname=$_REQUEST['catname'];

  4. $catdesc=$_REQUEST['catdesc'];

  5. $icon=$_REQUEST['icon'];

  6. $displayorder=$_REQUEST['displayorder'];

  7. $sql=" insert into categories(catname,catdesc,icon,displayorder)

  8. values ('$catname','$catdesc','$icon',$displayorder);

  9. ";

  10. //echo "<pre>$sql</pre>";

  11. mysql_query($sql) or die(mysql_error());

  12. header("location:index.php");

  13. ?>

Faqa delete.php

  1. <?php

  2. require("db.php");

  3. $id=$_REQUEST['id'];

  4. $sql=" delete from categories where catid=$id ";

  5. //echo "<pre>$sql</pre>";

  6. mysql_query($sql) or die(mysql_error());

  7. header("location:index.php");

  8. ?>

Faqa edit.php

  1. <?php

  2. require("db.php");

  3. $kodi=$_REQUEST['id'];

  4. $kodi=$kodi+0; // per tu mbrojtur nga sulmet SQL Injection ose script injection

  5. $sql=" select * from categories where catid=$kodi ";

  6. $res=mysql_query($sql) or die('gabim komande');

  7. $n=mysql_num_rows($res);

  8. if($n==0)

  9. {

  10. echo '<h1>Kjo kategori nuk ekziston</h1>';

  11. include("index.php");

  12. exit();

  13. }

  14. $rresht=mysql_fetch_array($res);

  15. ?>

  16. <html>

  17. <head>

  18. <title>Modify Category <?php echo $rresht['catid']; ?> </title>

  19. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

  20. </head>

  21. <body>

  22. <p>&nbsp;</p>

  23. <form action="edit1.php" method="post" >

  24. <p>

  25. <input type="hidden" name="catid" value="<?php echo $rresht['catid']; ?>" >

  26. </p>

  27. <p>

  28. catname:<input type="text" name="catname" value="<?php echo $rresht['catname']; ?>" > jepni emrin e kategorise

  29. </p>

  30. <p>

  31. catdesc:

  32. <textarea name="catdesc" rows="5" cols="40">

  33. <?php echo $rresht['catdesc']; ?>

  34. </textarea>

  35. <!-- komentet-->

  36. </p>

  37. <p>

  38. icon:<input type="text" name="icon" value="<?php echo $rresht['icon']; ?>" > jepni ikonen e kategorise

  39. </p>

  40. <p>

  41. displayorder:<input type="text" name="displayorder" value="<?php echo $rresht['displayorder']; ?>">

  42. jepni rendin ne te cilin doni te shfaqet kategoria</p>

  43. <p>

  44. <input type="submit" value="RUAJ">

  45. </p>

  46. </form>

  47. </body>

  48. </html>

Faqa edit1.php

  1. <?php

  2. require("db.php");

  3. $catid=$_REQUEST['catid'];

  4. $catname=$_REQUEST['catname'];

  5. $catdesc=$_REQUEST['catdesc'];

  6. $icon=$_REQUEST['icon'];

  7. $displayorder=$_REQUEST['displayorder'];

  8. $sql="

  9. UPDATE categories

  10. SET

  11. catname='$catname',

  12. catdesc='$catdesc',

  13. icon='$icon',

  14. displayorder=$displayorder

  15. WHERE

  16. catid=$catid

  17. ";

  18. //echo "<pre>$sql</pre>";

  19. mysql_query($sql) or die(mysql_error());

  20. header("location:index.php");

  21. ?>

Ushtrim 1

Ndertoni faqet per modifikimin e rreshtave te tabeles users

zgjidhje

faqa edit

<?php

include('db.php');

if(!isset($_REQUEST['id']))

{

exit('cilin perdorues doni te modifikoni?');

}

$code=$_REQUEST['id'];

$code=$code+0;

if($code==0)

{

exit('kodi i pasakte');

}

$q="select * from users where code=".$code;

$res=mysql_query($q) or die(mysql_error());

$n=mysql_num_rows($res);

if($n==0) exit('nuk ka perdorues me kete kod');

$rresht=mysql_fetch_array($res);

$code=$rresht['code'];

$username=$rresht['username'];

$password=$rresht['password'];

$firstname=$rresht['firstname'];

$lastname=$rresht['lastname'];

$email=$rresht['email'];

$accountstatus=$rresht['accountstatus'];

?>

<html>

<head>

<title>Add a new user</title>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

</head>

<body>

<form name="form1" method="post" action="editusersql.php">

<p>code :

<input type="text" name="code" value="<?php echo $code; ?>" readonly>

</p>

<p>username :

<input type="text" name="username" value="<?php echo $username; ?>" >

</p>

<p>password :

<input type="password" name="password" value="<?php echo $password; ?>">

</p>

<p>emri:

<input type="text" name="emri" value="<?php echo $firstname; ?>">

</p>

<p>mbiemri:

<input type="text" name="mbiemri" value="<?php echo $lastname; ?>">

</p>

<p>email:

<input type="text" name="email" value="<?php echo $email; ?>">

</p>

<p>account status:

<input type="text" name="accountstatus" value="<?php echo $accountstatus; ?>" >

</p>

<input name="Ruaj" type="submit" value="SAVE">

</form>

</body>

</html>

faqa edit1.php

<?php

include('db.php');

$code=$_REQUEST['code'];

$username=$_REQUEST['username'];

$password=$_REQUEST['password'];

$firstname=$_REQUEST['emri'];

$lastname=$_REQUEST['mbiemri'];

$email=$_REQUEST['email'];

$accountstatus=$_REQUEST['accountstatus'];

$q="

update users

set

username='".$username."',password='".$password."',

firstname='".$firstname."', lastname='".$lastname."',

email='".$email."',accountstatus=".$accountstatus."

where code=".$code;


mysql_query($q) or die('gabim ne shtim');

header("location:index.php");

?>