Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Senior Coder
    Join Date
    Aug 2005
    Posts
    1,119
    Thanks
    2
    Thanked 1 Time in 1 Post

    how to make a form submit to self and work.

    this is my code:

    PHP Code:
    <?php 
    if( !isset($_SESSION['login_username'])){
    header("Location: index.php?act=admin");
    } else {
    mysql_connect ($dbhost$dbusername$dbuserpass);
    mysql_select_db($dbname) or die(mysql_error());
    $query "SELECT * FROM $tuttable WHERE onoff='0' ORDER BY id DESC";
    $result mysql_query($query) or die(mysql_error());
    while (
    $row mysql_fetch_array($result)) {
     echo 
    "<table style=\"clear: both;\">
        <form action=\"index.php?act=adminlog&do=edit\" method=\"post\">
            <tr>
                <td rowspan=\"2\">
                    <img width=\"40\" height=\"40\" alt=\"preview\" src=\""
    .$row['image']."\" />
                </td>
                <td align=\"center\">
                    Title: <input type=\"text\" name=\"name\" value=\""
    .$row['title']."\" />
                </td>
                <td align=\"center\">
                    Author: <input type=\"text\" name=\"authorname\" value=\""
    .$row['author']."\" />
                </td>
                <td align=\"center\">
                    Tut-URL: <input type=\"text\" name=\"loca\" value=\"viewtut.php?id="
    .$row['id']."\" />
                </td>
                <td align=\"center\" rowspan=\"2\" colspan=\"2\">
                    <select name=\"approve\" id=\"approve\">
                    <option value=\"3\" selected=\"selected\">Edit</option>
                    <option value=\"1\">Approve</option>
                    <option value=\"0\">Leave as is</option>
                    <option value=\"2\">Delete</option>
                    </select>
                    <br />
                    <input type=\"hidden\" name=\"idnum\" value=\""
    .$row['id']."\" />
                    <input type=\"submit\" class=\"submit\" value=\"Go\" />
                    <br />
                    <input type=\"reset\" class=\"submit\" value=\"Reset\" />
                </td>
            </tr>
            <tr>
                <td colspan=\"1\">
                    <textarea name=\"descrip\">"
    .$row['descr']."</textarea>
                </td>
                <td align=\"center\">
                    <input type=\"radio\" name=\"cat\" value=\"Photoshop\" checked/> Photoshop<br />
                    <input type=\"radio\" name=\"cat\" value=\"PHP\" /> PHP<br />
                    <input type=\"radio\" name=\"cat\" value=\"PSP\" /> PSP<br />
                    <input type=\"radio\" name=\"cat\" value=\"PSE\" /> PSE<br />
                </td>
            </tr>
            <tr>
                <td colspan=\"7\">
                    Preview Location: 
                    <input type=\"text\" value=\""
    .$row['image']."\" name=\"preview\" size=\"55\" />
                </td>
            </tr>
        </form>
    </table>"
    ;
    }
    if (
    $_POST['approve'] == 1) {
         
    // SQL to update row to be active
    } else if ($_POST['approve'] == 2) {
         
    // SQL to delete row
    }  else if ($_POST['approve'] == 3) {
         
    // SQL to update row
            
    $update "UPDATE $tuttable SET image = '".$_POST['image']."', title = '".$_POST['title']."', tuturl = '".$_POST['tuturl']."', category = '".$_POST['category']."', author = '".$_POST['author']."', descr = '".$_POST['descr']."' WHERE id = '".$_POST['id']."'";
        
    mysql_query($update)or die(mysql_error());
    }   
    }  
    ?>
    but i think my php at the bottom is in the wrong spot to work. So can someone please tell me how to fix this?
    Last edited by thesavior; 01-06-2006 at 04:20 PM.

  • #2
    Registered User
    Join Date
    Sep 2005
    Posts
    315
    Thanks
    0
    Thanked 0 Times in 0 Posts
    If you want a form to post on the forms page and if you want it to do some tags on post try doing it this way :
    PHP Code:
    echo "<form action='".$_SERVER['PHP_SELF']."?action=checkthisformsinput' method='POST'> 
    THEN PUT THIS IN:
    PHP Code:
    if(isset($_GET['action']) AND $_GET['action'] == "checkthisformsinput"){
    all the things you want to do ...} 
    I used it in this order :
    I first put in if isset $get_action....
    After that i put '} else {' and then the form (so 'echo "<form action='".$_SERVER['PHP_SELF']."?action=checkthisformsinput' method='POST'>'
    }
    I hope this helps bye !

  • #3
    Senior Coder
    Join Date
    Aug 2005
    Posts
    1,119
    Thanks
    2
    Thanked 1 Time in 1 Post
    ok, i had to edit your code a little to make it work, but it still doesn't. It isn't updating the row, it just appears to be refreshing the page with the old values.

    CODE:
    PHP Code:
    <?php 
    if( !isset($_SESSION['login_username'])){
    header("Location: index.php?act=admin");
    } else {

    if(isset(
    $_GET['action']) AND $_GET['action'] == "edittutsnow"){
    if (
    $_POST['approve'] == 1) {
         
    // SQL to update row to be active
    } else if ($_POST['approve'] == 2) {
         
    // SQL to delete row
    }  else if ($_POST['approve'] == 3) {
         
    // SQL to update row
            
    $update "UPDATE $tuttable SET image = '".$_POST['image']."', title = '".$_POST['title']."', tuturl = '".$_POST['tuturl']."', category = '".$_POST['category']."', author = '".$_POST['author']."', descr = '".$_POST['descr']."' WHERE id = '".$_POST['id']."'";
        
    mysql_query($update)or die(mysql_error());
    }   }  

    mysql_connect ($dbhost$dbusername$dbuserpass)or die(mysql_error());
    mysql_select_db($dbname) or die(mysql_error());
    $query "SELECT * FROM $tuttable WHERE onoff='0' ORDER BY id DESC";
    $result mysql_query($query) or die(mysql_error());
    while (
    $row mysql_fetch_array($result)) {
     echo 
    "<table style=\"clear: both;\">
        <form action=\"index.php?act=adminlog&do=edit&action=edittutsnow\" method=\"POST\">
            <tr>
                <td rowspan=\"2\">
                    <img width=\"40\" height=\"40\" alt=\"preview\" src=\""
    .$row['image']."\" />
                </td>
                <td align=\"center\">
                    Title: <input type=\"text\" name=\"name\" value=\""
    .$row['title']."\" />
                </td>
                <td align=\"center\">
                    Author: <input type=\"text\" name=\"authorname\" value=\""
    .$row['author']."\" />
                </td>
                <td align=\"center\">
                    Tut-URL: <input type=\"text\" name=\"loca\" value=\""
    .$row['tuturl']."\" />
                </td>
                <td align=\"center\" rowspan=\"2\" colspan=\"2\">
                    <select name=\"approve\" id=\"approve\">
                    <option value=\"3\" selected=\"selected\">Edit</option>
                    <option value=\"1\">Approve</option>
                    <option value=\"0\">Leave as is</option>
                    <option value=\"2\">Delete</option>
                    </select>
                    <br />
                    <input type=\"hidden\" name=\"idnum\" value=\""
    .$row['id']."\" />
                    <input type=\"submit\" class=\"submit\" value=\"Go\" />
                    <br />
                    <input type=\"reset\" class=\"submit\" value=\"Reset\" />
                </td>
            </tr>
            <tr>
                <td colspan=\"1\">
                    <textarea name=\"descrip\">"
    .$row['descr']."</textarea>
                </td>
                <td align=\"center\">
                    <input type=\"radio\" name=\"cat\" value=\"Photoshop\" checked/> Photoshop<br />
                    <input type=\"radio\" name=\"cat\" value=\"PHP\" /> PHP<br />
                    <input type=\"radio\" name=\"cat\" value=\"PSP\" /> PSP<br />
                    <input type=\"radio\" name=\"cat\" value=\"PSE\" /> PSE<br />
                </td>
            </tr>
            <tr>
                <td colspan=\"7\">
                    Preview Location: 
                    <input type=\"text\" value=\""
    .$row['image']."\" name=\"preview\" size=\"55\" />
                </td>
            </tr>
        </form>
    </table>"
    ;
    }
    }  
    ?>

  • #4
    Senior Coder
    Join Date
    Aug 2005
    Posts
    1,119
    Thanks
    2
    Thanked 1 Time in 1 Post
    *bump*


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •