Jump to content

can't update the item inside database..


MrGarcia

Recommended Posts

hi..

i have here the "edit_news.php"

to edit my news in my site.. it is connected to database..

the first time i try editing.. its working.. but now.. if i edit the news, the text didn't change..

 

here's my code inside edit_news.phpp

 

<?php

include("config.php");

     if(isset($_POST['submit']))

  {



      // Set global variables to easier names

     // and prevent sql injection and apostrophe to break the db.

      $title = mysql_escape_string($_POST['title']);

      $text1 = mysql_escape_string($_POST['text1']);

      $text2 = mysql_escape_string($_POST['text2']);







         $result = mysql_query("UPDATE news SET title='$title', text1='$text1', text2='$text2' WHERE newsid='$newsid' ",$connect);



          echo "<b>Thank you! News UPDATED Successfully!";

          echo "<meta http-equiv=Refresh content=2;url=admin.php>";

}

elseif(isset($_GET['newsid']))

{



        $result = mysql_query("SELECT * FROM news WHERE newsid='$_GET[newsid]' ",$connect);

        while($myrow = mysql_fetch_assoc($result))

             {

                $title = $myrow["title"];

                $text1 = $myrow["text1"];

                $text2= $myrow["text2"];

?>

<br>


<form method="post" action="<?php echo $PHP_SELF ?>">

<input type="hidden" name="newsid" value="<? echo $myrow['newsid']?>">
  <table width="100%" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td width="17%">Title : </td>
            <td width="83%"><input name="title" type="text" size="30" value="<? echo $title; ?>"></td>
          </tr>

          <tr>
            <td>Message : </td>
            <td><textarea name="text1" cols="35" rows="10"><? echo $text1; ?></textarea></td>
          </tr>
          <tr>
            <td>Message2 : </td>
            <td><textarea name="text2" cols="35" rows="10"><? echo $text2; ?></textarea></td>
          </tr>
          <tr>
            <td> </td>
            <td><input type="submit" name="submit" value="Update News"></td>
          </tr>
                  </table>


</form>

<?

              }//end of while loop



  }//end else

?>

Link to comment
Share on other sites

too little information for me to do anything about your problem.  you gotta think out your questions before posting, and give as much information as possible regarding your issue.

 

i do notice some old code in your script that you should update to get into compliance with new versions of PHP.  use full tags instead of short tags:

 

change <? to <?php in all cases.

 

and use $_SERVER variable in this, and all instances like it:  $PHP_SELF to $_SERVER['PHP_SELF']

 

honestly, you're better to remove that from your form action altogether, and just leave it blank, ie. action=""

 

also, stay consistent with your variables; you are using single and double quote, and in some cases, no quotes at all which will make PHP assume that variable is a constant, discover that it is not, and try and convert it to a string.  use single quotes over double quotes.

Link to comment
Share on other sites

i did every you said..

but why is it.. the first time i try the editing..

its updating my database.. and display the new and edited news in my news.php

but now.. i dunno why i got this problem...

 

btw.. here's my example screenshot..

 

here's my latest news..

http://www.mrgarcia.co.cc/filphotos/pictures/f0c32d18043f2b782c76b61da16c07c0.png

 

i would like to edit it..

http://www.mrgarcia.co.cc/filphotos/pictures/060448aef6d46eb5fe60dfa7f1997305.png

 

after editing it.. i submit it..

http://www.mrgarcia.co.cc/filphotos/pictures/129ff82c9939bcee3366c33978bc5855.png

 

and the results still the same..

http://www.mrgarcia.co.cc/filphotos/pictures/f0c32d18043f2b782c76b61da16c07c0.png

 

[attachment deleted by admin]

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.