Jump to content

mysql_query(UPDATE)

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
7 replies to this topic

#1
VakhoQ

VakhoQ

    Programmer

  • Members
  • PipPipPipPip
  • 127 posts
Hello, How are you? :)


I'm trying to make AdminPanel In PHP MYSQL. Now I'm at editing function. I want to edit my Letter, that I have already added in SQL.

I have 3 php file.


edit.php. There I'm connecting to Data Base and I'm taking out "title", "description"


<?php

$result = mysql_query ("SELECT * FROM C_lessons", $db);

$row = mysql_fetch_array ($result);


do{

printf  ("

         <table class='lesson_table' width='840px' >

         <tr><td>

         <div    class='lesson'>

         <a href='editing.php?id=%s'>  

         %s <br>         

         აღწერა: %s </a> 

	 </div> 

         </td></Tr> </table> ", $row["id"], $row["title"], $row["description"]);

} while ($row = mysql_fetch_array ($result));

?>








editing.php


<?php

$id = $_GET['id'];

$result = mysql_query ("SELECT * FROM C_lessons WHERE id='$id'", $db);

$row = mysql_fetch_array ($result);

?>




<form method="post" action="edited.php" >

<table width="100%" >

<tr> 

<td width="15%"> <em><strong>title</strong></em></td>

<td><input type="text" name="title"  value="<?php echo $row['title'] ?>">  </td>

</tr>


<tr> 

<td> <em><strong>description</strong></em></td>

<td><textarea   name="description" cols="70" rows="10" > <?php echo $row['description']; ?> </textarea></td>

</tr>


<tr> 

<td> <em><strong>text</strong></em></td>

<td><textarea   name="text" cols="70" rows="20" > <?php echo $row['text']; ?> </textarea></td>

</tr>


<tr> 

<td><input name="add" type="submit"  value="textს add"></td>

</tr>

</table>

</form>



edited.php



<?php


if (isset($_POST['title'])) {$title = $_POST['title'];} 

 else {echo "line 1 Var Isset Error"; exit();}



if (isset($_POST['description']))  {$description = $_POST['description'];}  

 else {echo "line 2 Var Isset Error"; exit();}



if (isset($_POST['text']))  {$text = $_POST['text'];}  

else {echo "line  3 Var Isset Error"; exit();}





?>




<?php


$db = mysql_connect ("mysql6.000webhost.com","a3729878_vakho","******");


mysql_select_db ("a3729878_site",$db);




if (isset($title) && isset($description) && isset($text))   // line "if Var Is not set"




               if ($title!=="" && $title!=="" && $text!=="")                       


               {                 	 


                   $damateba = mysql_query ("UPDATE C_lessons set title = '$title',  description='$description', text='$text'  WHERE id='$id'");


                   if($damateba =='true'){ echo "EDITED";}


                   else                  {echo "MYSQL ERROR NONT EDITED;}


               }


               else if ($title=="" || $description=="" || $text=="") {echo "you should fill all the grap"; }    


           


 else {echo " line  Var Isset Error,"; }  // else of  line "if Var is not set"






?>







I have problems with this code:
$damateba = mysql_query ("UPDATE C_lessons set title = '$title', description='$description', text='$text' WHERE id='$id'");

edited.php dont know what is '$id'. But If I write, for example, id=27 everything works. so i wont to make something to tell edited.php what is $id. $id knows only editing.php, does not it?


Thanks a lot :)

#2
Orjan

Orjan

    Writes binary right handed and hex left handed

  • Moderators
  • 3,299 posts
You need to forward your $id with a hidden input so next file also knows that information.
__________________________________________
I study Information Systems at Karlstad University when I'm not on CodeCall

#3
VakhoQ

VakhoQ

    Programmer

  • Members
  • PipPipPipPip
  • 127 posts
Yes, I wont to forward my $id. Could you tell me how to do this? :)

#4
Alexander

Alexander

    It's Science!

  • Moderators
  • 4,124 posts
You would need to place a hidden field within your <form> element on editing.php:
<input type="hidden" name="id" value="<?php echo $id; ?>">
This would pass $_POST['id'] to edited.php.
Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.

#5
VakhoQ

VakhoQ

    Programmer

  • Members
  • PipPipPipPip
  • 127 posts

Nullw0rm said:

You would need to place a hidden field within your <form> element on editing.php:
<input type="hidden" name="id" value="<?php echo $id; ?>">
This would pass $_POST['id'] to edited.php.

what do i pass to edited.php? $_POST['id'] or $_GET['id']? And why? Why $_POST['id'] and not $_GET['id']? could someone explain me?


#6
DEViANT

DEViANT

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 358 posts

VakhoQ said:


what do i pass to edited.php? $_POST['id'] or $_GET['id']? And why? Why $_POST['id'] and not $_GET['id']? could someone explain me?

You would use $_POST['id']

heres why. your form tag looks like this :
<form method="post" action="edited.php" >

and as you can see there, it uses post as its method and not get.

You can read up on $_GET here : PHP: $_GET - Manual
You can read up on $_POST here : PHP: $_POST - Manual

:D You should rep+ me so that I can win :D

My Blog | Ask me!
Error : Satan did it

#7
VakhoQ

VakhoQ

    Programmer

  • Members
  • PipPipPipPip
  • 127 posts
Everything is clear.
Firstly, I pass $id from edit.php to editing.php by $_GET. Then I pass The $id from editing.php to edited.php by $_POST. don't I?

#8
DEViANT

DEViANT

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 358 posts
Indeed it does seem so :)

:D You should rep+ me so that I can win :D

My Blog | Ask me!
Error : Satan did it