Jump to content

netpumber

Members
  • Posts

    107
  • Joined

  • Last visited

Posts posted by netpumber

  1. Here is the source code of the form :

     

    <br>
    <table align="center"><td>
    <form method="post" name="edit_misc" action="editm.php" >
    <font face="Lucida Console, Courier New, Fixed" size=2 color="#FFF380" >$title :</font>
    <br>
    <input style="background:#B0D2D7" type="text" name="title" size="38" value="test">
    <br><br>
    <font face="Lucida Console, Courier New, Fixed" size=2 color="#FFF380">$text:</font>
    <br>
    <textarea style="background:#B0D2D7" rows="10" name="entry" cols="48" >testaaa</textarea>
    <br>
    
    <p align="left"><INPUT type="submit" name="edit_misc" value="Save"></p>
    <input type="hidden" name="id" value="13">
    </form>
    </td>
    </table>
    

     

    Question 1 :

     

    how i will put htmlentities() in textarea ?

     

    Question 2 :

     

    clearing your cache maybe
    What exactly you mean ?

     

     

    [x]

     

    <?php
    session_start();
    if ($_SESSION['authorized'] != true)
    {
        header("Location: login_form.php");
        exit;
    }
    die(); <---I add this line in editm.php
    ?>

     

    And here is the access log :P

     

    [30/Oct/2009:15:21:30 -0400] "GET /login/edmp.php?action1=edit&id=13 HTTP/1.1" 200 1359 "http://lol.homelinux.net/login/

    edmp.php?title=test&entry=testaaa.sghdfh&edit_misc=Save&id=13" "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.4) Gecko/2008102920 Firefox/3.0.4"

     

    I have a feeling it is a really simple problem somewhere

     

    I hope so ...:P I can't imagine what the hell is happening...:S

     

    Thanks anyway...my friend..:)

     

  2. Lets make them clearly...

     

    File edmp.php [means edit main page] It has two forms :

     

    1st Form for editing a table called site_entries

     

    here is the code :

     

    <?php
    
    if(isset($_GET['action']) && $_GET['action']=="edit"){
            $q = mysql_query("SELECT title,entry FROM site_entries WHERE id='".mysql_real_escape_string($_GET['id'])."'");
            $row = mysql_fetch_array($q);
    
    
    print "
    <br>
    <table align=\"center\"><td>
    <form method=\"post\" name=\"edit_projects\" action=\"editp.php\" >
    <font face=\"Lucida Console, Courier New, Fixed\" size=2 color=\"#FFF380\" >\$title :</font>
    <br>
    <input style=\"background:#B0D2D7\" type=\"text\" name=\"title\" size=\"38\" value=\"".htmlentities($row['title'])."\">
    <br><br>
    <font face=\"Lucida Console, Courier New, Fixed\" size=2 color=\"#FFF380\">\$text:</font>
    <br>
    <textarea style=\"background:#B0D2D7\" rows=\"10\" name=\"entry\" cols=\"48\" >{$row['entry']}</textarea>
    <br>
    <p align=\"left\"><INPUT type=\"submit\" name=\"edit_projects\" value=\"Save\"></p>
    <input type=\"hidden\" name=\"id\" value=\"".$_GET['id']."\">
    </form>
    </td>
    </table>
    ";
    }
    ?>
    

     

    As you can see action=\"editp.php\"

     

    Here is the code for editp.php:

     

    <?php
    session_start();
    if ($_SESSION['authorized'] != true)
    {
        header("Location: login_form.php");
        exit;
    }
    ?>
    
    
    <?php
    
    // [start] Save changes for projects
    ini_set ('display_errors',1);
    error_reporting (E_ALL);
    
    if (isset ($_POST['edit_projects'])){
            if ($dbc = @mysql_connect('localhost','user','p@ss'))
                    {
                            if (!@mysql_select_db ('web_site'))
                            {
                                    die('<p> Could not select the database brcause:<b>'. mysql_error() .'</b></p>');
                            }
                    }else{
                            die('<p>Could not connect to MYSQL because:<b>' . mysql_error() . '</b></p>');
                            }
    
    
    $query = "UPDATE site_entries SET title='{$_POST['title']}',entry='{$_POST['entry']}' WHERE id={$_POST['id']}";
    
    
    if (@mysql_query ($query)){
                            echo "<meta http-equiv='refresh' content='0;URL=edmp.php'>";
                            }else{
                            print"<p>Could not add the entry because:<b>" .mysql_error() . "</b>. The query was $query.</p>";
                    }
    
    mysql_close();
    }
    
    
    
    ?>
    

     

    ^ This one works FINE !!!

     

    Ok now... the other one form of the edmp.php is for editing a table called misc_entries and here is the code:

     

    <?php
    
    
    if(isset($_GET['actionm']) && $_GET['actionm']=="edit"){
            $qm = mysql_query("SELECT title,entry FROM misc_entries WHERE id='".mysql_real_escape_string($_GET['id'])."'");
            $row = mysql_fetch_array($qm);
    print "
    <table align=\"center\"><td>
    <form method=\"post\"  action=\"editm.php\" >
    <font face=\"Lucida Console, Courier New, Fixed\" size=2 color=\"#FFF380\" >\$title :</font>
    <br>
    <input style=\"background:#B0D2D7\" type=\"text\" name=\"title\" size=\"38\" value=\"".htmlentities($row['title'])."\">
    <br><br>
    <font face=\"Lucida Console, Courier New, Fixed\" size=2 color=\"#FFF380\">\$text:</font>
    <br>
    <textarea style=\"background:#B0D2D7\" rows=\"10\" name=\"entry\" cols=\"48\" >{$row['entry']}</textarea>
    <br>
    <p align=\"left\"><INPUT type=\"submit\" name=\"edit_misc\" value=\"Save\"></p>
    <input type=\"hidden\" name=\"id\" value=\"".$_GET['id']."\">
    </form>
    </td>
    </table>
    ";
    }
    ?>
    

     

    As you can see action=\"editm.php\" > . The editm.php code is here :

     

    <?php
    session_start();
    if ($_SESSION['authorized'] != true)
    {
        header("Location: login_form.php");
        exit;
    }
    ?>
    
    
    <?php
    
    // [start] Save changes for projects
    ini_set ('display_errors',1);
    error_reporting (E_ALL);
    
    if (isset ($_POST['edit_misc'])){
            if ($dbc = @mysql_connect('localhost','user','p@ss'))
                    {
                            if (!@mysql_select_db ('web_site'))
                            {
                                    die('<p> Could not select the database brcause:<b>'. mysql_error() .'</b></p>');
                            }
                    }else{
                            die('<p>Could not connect to MYSQL because:<b>' . mysql_error() . '</b></p>');
                            }
    
    
    $query = "UPDATE misc_entries SET title='".mysql_real_escape_string($_POST['title'])."',entry='".mysql_real_escape_string($_POST['entry'])."' WHERE id={$_POST['id']}";
    echo $query;
    
    if (@mysql_query ($query)){
                            echo "<meta http-equiv='refresh' content='0;URL=edmp.php'>";
                            }else{
                            print"<p>Could not add the entry because:<b>" .mysql_error() . "</b>. The query was $query.</p>";
                    }
    
    mysql_close();
    }
    
    
    
    ?>

     

     

    ^ This one doesn't work... I understood that when i press tha Save button the editm.php doesn't executed and the link became

     

    edmp.php?title=test&entry=test+test2&edit_misc=Save&id=13

     

    When i press the button Save from the first form all works GREAT . The editp.php script executed.

     

     

    Thats all my friend...:)

  3. So look. In the page edmp.php i have two forms that you can edit two different tables.

    1st edit_projects form and 2nd misc_projects form. For the first form this code works perfectly. I mean that you can edit the table.

     

    The problem is in the second form that doesn't execute the script in the action= and i don't know why... I can't imagine anything. I thought that occurs because there are two form in the same page but i don't know any more... i try to change these two forms and nothing happens... Have you ever had a problem like this ?

  4. So look at this.

     

    i have this code for editing the registers :

     

    <?php
    
    
    if(isset($_GET['action1']) && $_GET['action1']=="edit"){
            $q = mysql_query("SELECT title,entry FROM misc_entries WHERE id='".mysql_real_escape_string($_GET['id'])."'");
            $row = mysql_fetch_array($q);
    
    
    print "
    <br>
    <table align=\"center\"><td>
    <form method=\"post\" name=\"edit_misc\" action=\"editm.php\" >
    <font face=\"Lucida Console, Courier New, Fixed\" size=2 color=\"#FFF380\" >\$title :</font>
    <br>
    <input style=\"background:#B0D2D7\" type=\"text\" name=\"title\" size=\"38\" value=\"".htmlentities($row['title'])."\">
    <br><br>
    <font face=\"Lucida Console, Courier New, Fixed\" size=2 color=\"#FFF380\">\$text:</font>
    <br>
    <textarea style=\"background:#B0D2D7\" rows=\"10\" name=\"entry\" cols=\"48\" >{$row['entry']}</textarea>
    <br>
    <p align=\"left\"><INPUT type=\"submit\" name=\"edit_misc\" value=\"Save\"></p>
    <input type=\"hidden\" name=\"id\" value=\"".$_GET['id']."\">
    </form>
    </td>
    </table>
    ";
    }
    ?>
    

     

    The code in editm.php script is :

     

    <?php
    // [start] Save changes for misc
    ini_set ('display_errors',1);
    error_reporting (E_ALL);
    
    if (isset ($_POST['edit_misc'])){
            if ($dbc = @mysql_connect('localhost','user','p@ss'))
                    {
                            if (!@mysql_select_db ('web_site'))
                            {
                                    die('<p> Could not select the database brcause:<b>'. mysql_error() .'</b></p>');
                            }
                    }else{
                            die('<p>Could not connect to MYSQL because:<b>' . mysql_error() . '</b></p>');
                            }
    
    
    $queryb = "UPDATE misc_entries SET title='{$_POST['title']}',entry='{$_POST['entry']}' WHERE id={$_POST['id']}";
    
    
    if (@mysql_query ($queryb)){
                            echo "<meta http-equiv='refresh' content='0;URL=edmp.php'>";
                            }else{
                            print"<p>Could not add the entry because:<b>" .mysql_error() . "</b>. The query was $query.</p>";
                    }
    
    mysql_close();
    }
    
    ?>
    

     

    Tha problem is that when i press the save button it doesn't update the db.

     

    Also i have to add  here that i do the exactly the same thing with another table and there it works fine ...

     

    Can you see any mistake here?

     

    Thanks...

  5. Ok i have this :

     

    <?php
    
    
    if(isset($_GET['action']) && $_GET['action']=="edit"){
            $q = mysql_query("SELECT title,entry FROM site_entries WHERE id='".mysql_real_escape_string($_GET['id'])."'");
            $row = mysql_fetch_array($q);
    
    print "
    <br>
    <table align=\"center\"><td>
    <form method=\"post\" name=\"misc\" action=\"edmp.php\" >
    <font face=\"Lucida Console, Courier New, Fixed\" size=2 color=\"#FFF380\" >\$title :</font>
    <br>
    <input style=\"background:#B0D2D7\" type=\"text\" name=\"title\" size=\"38\" value=\"{$row['title']}\">
    <br><br>
    <font face=\"Lucida Console, Courier New, Fixed\" size=2 color=\"#FFF380\">\$text:</font>
    <br>
    <textarea style=\"background:#B0D2D7\" rows=\"10\" name=\"entry\" cols=\"48\" ></textarea>
    <br>
    <p align=\"center\"><INPUT type=\"submit\" name=\"submit1\" value=\"Submit\"></p>
    </form>
    </td>
    </table>
    ";
    }
    ?>
    

     

    But when it prints the form the Title is out of the text box :P lol and its near it..

     

    Something is not good in this line.. I change it a little bit but... i didnt found anything..

    <input style=\"background:#B0D2D7\" type=\"text\" name=\"title\" size=\"38\" value=\"{$row['title']}\">

  6. Hmmm I need your help once again...

     

    i add this for the edit link

     

    <?php
    
    
    if(isset($_GET['action']) && $_GET['action']=="edit"){
    
            print "<br><table align=\"center\"><td>
    <form method=\"post\" name=\"misc\" action=\"edmp.php\" >
    <font face=\"Lucida Console, Courier New, Fixed\" size=2 color=\"#FFF380\" >\$title :</font>
    <br>
    <input style=\"background:#B0D2D7\" type=\"text\" name=\"title\" size=\"38\" value={$row['title']}>
    <br><br>
    <font face=\"Lucida Console, Courier New, Fixed\" size=2 color=\"#FFF380\">\$text:</font>
    <br>
    <textarea style=\"background:#B0D2D7\" rows=\"10\" name=\"entry\" cols=\"48\" ></textarea>
    <br>
    <p align=\"center\"><INPUT type=\"submit\" name=\"submit1\" value=\"Submit\"></p>
    </form>
    </td></table>";
    }
    ?>
    

     

    I want to ask you how in the text and in the textarea i will load the title and the entry text from the database with the specific id number...

     

    Any ideas...:)

     

    Thanks...

  7. Still doesnt work...

     

    <table align="center" border="2" bordercolor="green" cellspacing="0"><?php
    
    $query = 'SELECT title,id FROM site_entries ORDER BY date_entered DESC';
    
    if ($r = mysql_query($query)){
    
            while ($row = mysql_fetch_array($r)){
                      print "
                             <tr>
                             <td><font face=\"Lucida Console, Courier New, Fixed\" size=2 color=\"#8BB381\">{$row['title']}</td>
                             <td><a href=\"{$_SERVER['PHP_SELF']}?action=delete&id={$row['id']}\">Delete();</a></td>
                             <td><a href=\"{$_SERVER['PHP_SELF']}?action=edit&id={$row['id']}\">Edit();</a></td>
                             </tr> ";
    
                                                 }
    }else{
            die('<p>Could not retrive the data brcause:<b>' . mysql_error .'</b> The query was $query.</p>');
    
    }
    
    
    if(isset($_GET['action']) && $_GET['action']=="delete"){
            $query = "DELETE FROM site_entries WHERE id={$row['id']} LIMIT 1";
            $r = mysql_query($query);
    }
    
    mysql_close();
    
    ?></table>
    

  8. Thank you a lot seanlim :) for your answers...

     

    So after 6 tries with $_POST  i decide to make it with the last way you say...:) Here is my code now:

     

    <?php
    
    $query = 'SELECT title,id FROM site_entries ORDER BY date_entered DESC';
    
    if ($r = mysql_query($query)){
    
            while ($row = mysql_fetch_array($r)){
                      print "
                             <tr>
                             <td><font face=\"Lucida Console, Courier New, Fixed\" size=2 color=\"#8BB381\">{$row['title']}</td>
                             <td><a href=\"{$_SERVER['PHP_SELF']}?action=delete&id={$row['id']}\">Delete();</a></td>
                             <td><a href=\"{$_SERVER['PHP_SELF']}?action=edit&id={$row['id']}\">Edit();</a></td>
                             </tr> ";
    
                                                 }
    }else{
            die('<p>Could not retrive the data brcause:<b>' . mysql_error .'</b> The query was $query.</p>');
    
    }
    
    
    if ($_GET['action'] == "delete"){
            $query = "DELETE FROM site_entries WHERE id={$row['id']} LIMIT 1";
            $r = mysql_query($query);
    }
    
    mysql_close();
    
    ?>
    

     

    It returns me this error

     

    Notice: Undefined index: action in /var/www/login/edmp.php on line 259

     

    and i thing that i have an error in the checking $_GET['action'] part...in the if clause..What do you think ?

     

    Also i have another question...Ok.. with delete link its just execute a DELETE query...what happens with the edit ? Maybe this one needs a POST method i think..cuz it needs a form with the new title and text ...Thats my opinion..Except if we can make it to redirects you to a new edit page...

     

    Thanks for all!! I really mean it.. :) You help me to learn lot of things .

  9. First i want to test it with post method.. Anyway.. i change as you say the php script to another file . delete.php

     

    and there i add print_r($_POST); line...

     

    I get this:

    Array ( [23] => Delete(); )

     

    It takes the id=23 as we can see...and the button's value = Delete();

     

    How i can make it work with DELETE query ? I ll try it later with $_GET but im curious now on how it works with POST. Here is the code once again with some changes:

     

    delete.php

     

    <?php
    //[start] of DeleteOrEdit section
    
    ini_set('display_errors',1);
    error_reporting(E_ALL);
    
            if ($dbc = @mysql_connect('localhost','we','p@ss'))
                    {
                            if (!@mysql_select_db ('web_site'))
                            {
                                    die('<p> Could not select the database brcause:<b>'. mysql_error() .'</b></p>');
                            }
                    }else{
                            die('<p>Could not connect to MYSQL because:<b>' . mysql_error() . '</b></p>');
                            }
    
    
    
    //Deleting a register
    
    if (isset($_POST['submit'])){
    
            $query = "DELETE FROM site_entries WHERE id={$row['id']} LIMIT 1";
            $r = mysql_query($query);
    }
    print_r($_POST);
    mysql_close();
    ?>
    

     

    edmp.php

     

    <form method="post" action="delete.php">
    <table align="center" border="2" bordercolor="green" cellspacing="0">
                             <tr>
                             <td><font color="#F87217">Title:</td>
                             <td><font color="#F87217">Delete();</font></td>
                             <td><font color="#F87217">Edit();</font></td>
                             </tr>
    
    
    <?php
    
    $query = 'SELECT title,id FROM site_entries ORDER BY date_entered DESC';
    
    if ($r = mysql_query($query)){
    
            while ($row = mysql_fetch_array($r)){
                      print "
                             <tr>
                             <td><font color=\"#8BB381\">{$row['title']}</td>
                             <td><input  type=\"submit\" name=\"{$row['id']}\" value=\"Delete();\"></td>
                             <td><input type=\"submit\" name=\"{$row['id']}\" value=\"Edit();\"></td>
                             </tr> ";
    
                                                 }
    }else{
            die('<p>Could not retrive the data brcause:<b>' . mysql_error .'</b> The query was $query.</p>');
    
    }
    
    mysql_close();
    
    ?>
    
    </table>
    </form>

  10. hmm...Seanlim... i do what you said an here is the new code:

     

    <form method="post" action="edmp.php">
    <table align="center" border="2" bordercolor="green" cellspacing="0">
                             <tr>
                             <td><font color="#F87217">Title:</td>
                             <td><font color="#F87217">Delete();</font></td>
                             <td><font color="#F87217">Edit();</font></td>
                             </tr>
    
    
    <?php
    
    $query = 'SELECT title,id FROM site_entries ORDER BY date_entered DESC';
    
    if ($r = mysql_query($query)){
    
            while ($row = mysql_fetch_array($r)){
                      print "
                             <tr>
                             <td><font color=\"#8BB381\">{$row['title']}</td>
                             <td><input  type=\"submit\" name=\"{$row['id']}\" value=\"Delete();\"></td>
                             <td><input type=\"submit\" name=\"{$row['id']}\" value=\"Edit();\"></td>
                             </tr> ";
    
                                                 }
    }else{
            die('<p>Could not retrive the data brcause:<b>' . mysql_error .'</b> The query was $query.</p>');
    
    }
    
    
    ?>
    
    </table>
    </form>
    
    
    <?php
    //Deleting a register
    
    if (isset($_POST['submit'])){
    
            $query = "DELETE FROM site_entries WHERE id={$row['id']} LIMIT 1";
            $r = mysql_query($query);
    }
    mysql_close();
    ?>
    

     

    the prob is that when i press the delete button nothing happens...

     

    Maybe something is going wrong with the {$row['id']} but i dont know...What you say?

  11. Hallo !!

     

    So look at this image :

     

    http://img194.imageshack.us/img194/8272/snapshot5f.png

    This table prints the titles of entries from a table in a database.. The code that i use for this table is this :

    <!--Table For Deleting and Updating -->
    
    <br>
    <br>
    <p align="center"><font color="#1569C7">DeleteOrEdit(</font><font color="red">Security Projects & Thoughts Section</font><font color="#1569C7">);</font></p>
    
    <table align="center" border="2" bordercolor="green" cellspacing="0">
    
    <!--First row with title delete and edit-->
    <tr>
    <td><font color="#F87217">Title:</td>
    <td><font color="#F87217">Delete();</font></td>
    <td><font color="#F87217">Edit();</font></td>
    </tr>
    
    <?php
    
    $query = 'SELECT title FROM site_entries ORDER BY date_entered DESC';
    
    if ($r = mysql_query($query)){
    
            while ($row = mysql_fetch_array($r)){
                      print "<tr>
                             <td><font color=\"#8BB381\">{$row['title']}</td>
                             <td><form method=\"post\"  name=\"sub_del\"><input  type=\"submit\" value=\"Delete();\"></form></td>
                             <td><form method=\"post\" name=\"sub_edt\"><input type=\"submit\" value=\"Edit();\"></form></td>
                             </tr> ";
    
                                                 }
    }else{
            die('<p>Could not retrive the data brcause:<b>' . mysql_error .'</b> The query was $query.</p>');
    
    }
    
    
    mysql_close();
    
    
    ?>
    
    </table>

     

    Its simple...till here...

     

    Now i stack on how to make the script that will delete the registers of the database...I can think something with id column but i can't make it true...:s I want you to help me giving me ideas on how to make this or any other idea on how to create an delete/edit page...If you think that i start it with a wrong way please tell me :)

     

    The table name is site_entries and its columns are id , title , entry , date_entered

     

    Thanks in advance..!!

     

     

  12. D'uh, sorry my bad, I just got up :)

     

    Let's try that one again. The error messages being different indicates that you are getting a row from the database because both session_start and header are failing. With the wrong password only session_start fails because you pass into the else statement. Therefore looking at your code again (at least whats posted), you don't have session_start at the top of admin.php meaning you will get sent straight back to where you came from since without starting the session $_SESSION['authorised'] will be false.

     

     

    Oh YEAH thanks A LOT cags... I add a session_start(); in admin.php and worked .. Thanks a lot all of you guyz!!

    This board roolez!! Keep up the good work...

     

    PROBLEM SOLVED!!

  13. Hmmm i see something curious...

     

    If i type the correct password the error under the echo $query;  is :

     

    select * from users where user_name = "admin" and password = "78fcb88c0a7fba8cead390bb78983705"

    Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /var/www/login/login.php:23) in /var/www/login/login.php on line 27

     

    Warning: Cannot modify header information - headers already sent by (output started at /var/www/login/login.php:23) in /var/www/login/login.php on line 31

     

    and if i type a wrong password the error become :

     

    select * from users where user_name = "admin" and password = "9cdfb439c7876e703e307864c9167a15"

    Warning: Cannot modify header information - headers already sent by (output started at /var/www/login/login.php:23) in /var/www/login/login.php on line 36

     

    What you say ..?

  14. Snapshot 3 tells you what your problem is. Basically speaking you cannot modify headers after you have started output to the screen. Since session_start and header() both require modifying headers so you cannot have output before them. Looking at your code I cannot see any output but I'm assuming that...

     

    <?php
    
    ini_set ('display_errors',1);
    error_reporting (E_ALL & ~E_NOTICE);
    
    if (isset ($_POST['submit'])){
            if ($dbc = @mysql_connect('localhost','web','@qwerty@'))
                    {
                            if (!@mysql_select_db ('web_site'))
                            {
                                    die('<p> Could not select the database brcause:<b>'. mysql_error() .'</b></p>');
                            }
                    }else{
                            die('<p>Could not connect to MYSQL because:<b>' . mysql_error() . '</b></p>');
                            }
    
    
                    $query =  'select * from users where user_name = "'.$_POST['username'].'" and password = "'.md5($_POST['password']). '"';
                    $select_user = mysql_query($query);
    
    
    
    
    if (mysql_num_rows($select_user) != 0)
    {
        session_start();
        session_register('authorized');

     

    ... is the very top of the page. If you have anything before <?php even if it's a space or a newline character then your code will not work. To help work out what it is, click 'View Source' in your browser and check what characters you have before the error messages.

     

    lol ..no .. The error :

     

    Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /var/www/login/login.php:23) in /var/www/login/login.php on line 27
    
    Warning: Cannot modify header information - headers already sent by (output started at /var/www/login/login.php:23) in /var/www/login/login.php on line 31

     

    occurs because i have type in the code

     

    echo $query;

     

    to see if the query do the right things...:)

×
×
  • 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.