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 5 of 5
  1. #1
    Registered User
    Join Date
    Sep 2005
    Posts
    315
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Php noob with question here...

    Hi, i have another problem, the code below was working right, untill i inserted the if (empty....) tags. I also think there's a better way to do it then the way i'm trying to.
    It's like this : if the form 'catnaam' is empty, it shouldt update 'origcatnaam' into 'catnaam'. Also with this code, a part of the form is seen twice !
    If you can't find in the code wich part is seen twice, go to here :
    http://www.superprofile.nl/arne/catwijzigen.php
    there you'll find it ! at least i hope so !
    I'm sorry i'm a total noob in php !!!

    PHP Code:
    <? 
    include 'global.php';
    include(
    "bovenbody.php");

    if(isset(
    $_GET['actie']) AND $_GET['actie'] == "controleren"){
    //
    if (empty($_POST['catnaam'])) {
    $_POST['catnaam']=$_POST['origcatnaam'];
    }
    //
    @mysql_query("UPDATE cats SET locatie='".lekubb($_POST['plaats'])."', naam='".lekubb($_POST['catnaam'])."',  gebruikersnaam='".$lid."', inltekst='".lekubb($_POST['bericht'])."' WHERE gebruikersnaam='".$lid."' AND cat='".lekubb($_POST['origcatnaam'])."'");
    if (empty(
    $_POST['catnaam'])) {
    }else{
    @
    mysql_query("UPDATE links SET cat='".lekubb($_POST['catnaam'])."' WHERE gebruikersnaam='".$lid."' AND cat='".lekubb($_POST['origcatnaam'])."'");
    }
    ?>
    <?
                begintabel
    ("Succesvol aangepast");

                echo 
    "De categorie is aangepast !";

                
    eindetabel();

        } else {

            
    begintabel("Categorie aanpassen");

            echo 
    "<form action='".$_SERVER['PHP_SELF']."?actie=controleren' method='POST'>

            Bij het veranderen van de categorienaam worden automatisch ook de links in die categorie verplaatst naar de nieuwe categorie.<br><br><br>
            
            <table width='100%' border='0' cellpadding='0' cellspacing='0' height='167'>
            <tr>
                <td width='50%' height='24'>Huidige categorienaam</td>
                <td width='50%' height='24'>
                <input type='text' name='origcatnaam' size='20'>"
    ;
    $query "SELECT * FROM cats WHERE gebruikersnaam='$lid'"
    $uitvoer mysql_query($query) or die (mysql_error()); 
    while(
    $lijst mysql_fetch_object($uitvoer)) 
    {
    ?>
                <option value='<?php echo"$lijst->naam"?>'><?php echo"$lijst->naam"?></option>
    </td>
            </tr>
    <tr>
                <td width='50%' height='24'>Nieuwe categorienaam*</td>
                <td width='50%' height='24'>
                <input type='text' name='catnaam' size='20'></td></tr>&nbsp;&nbsp;&nbsp; 
    *Laat dit leeg als u de huidige naam wil behouden !
            <tr>
                <td width='50%' height='24'>Locatie</td>
                <td width='50%' height='24'>
                <select size='1' name='plaats'>
                <option value='1'>Links</option>
                <option value='2'>Midden</option>
                <option value='3'>rechts</option>
                </select></td>
            </tr>
            <tr>    <td width='50%' height='68'>Bericht</td>
                <td width='50%' height='68'>
                <textarea name='bericht' rows='4' cols='35' value='<?php echo"$lijst->bericht"?>'></textarea></td>
            </tr>
            <tr>
                <td width='50%' height='25'>&nbsp;</td>
                <td width='50%' height='25'>&nbsp;</td>
            </tr>
            <tr>
                <td width='50%' height='26'>Bevestigen</td>
                <td width='50%' height='26'><input type='submit' value='Toevoegen'></td>
            </tr>
            </table>

            <?
    eindetabel
    ();
    }
    }
    include(
    "onderbody.php"?>
    Bye and thanx for helping me out !

  • #2
    Registered User
    Join Date
    Sep 2005
    Posts
    315
    Thanks
    0
    Thanked 0 Times in 0 Posts
    To make it more clearly : i have a table (cats) in wich there is information about categories (also the name of the categorie). In another table (links) information about links are inserted (also the categorie to wich the link belong). If members want to change the name of their categorie, the name of the categorie should change it the first table as well as in the second one with the links BUT if they only want to change other things and not the categorie name, it doesn't have to update the 'links' table cause there information doesn't need to be changed. So if 'newcategoriename' is empty, it means the old categorie name should be in work still, so it doesn't have to update, the newcategoriename is a formcomponent (sorry for my english) called 'catnaam'. if 'catnaam' is zero, no links have to be updated,but how to code that?

  • #3
    Registered User
    Join Date
    Sep 2005
    Posts
    315
    Thanks
    0
    Thanked 0 Times in 0 Posts
    bump this

  • #4
    New Coder
    Join Date
    Dec 2005
    Posts
    36
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Have you tried using isset condition instead of 'empty' ?

  • #5
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,979
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    Post text fields will return a null value when empty. Therefore, isset() will always return true, regardless of if there is a value or not.

    Anyway, its your request methods that are causing your problems:
    PHP Code:
    if(isset($_GET['actie']) AND $_GET['actie'] == "controleren"){ 
    // 
    if (empty($_POST['catnaam'])) { 
    $_POST['catnaam']=$_POST['origcatnaam']; 

    Anyway, I didn't really scan through this overly well, so I'm not 100% certain this is your problem. However, your $_POST will not be co-existing with your $_GET, and if it should, $_POST will override $_GET. So, the if (empty($_POST['catnaam'])) is never evaluated from a _POST sent form, as it requires that _GET['actie'] isset and only equal to 'controleren'. No get = no evaluation.
    If you need to use both, change your GET/POST requests to $_REQUEST, which merges your _POST, _GET, and _COOKIE if I'm not mistaken, ordering GET => POST => COOKIE override. This should fix the problem. If not, its something completely different.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 


  •  

    Posting Permissions

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