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.
Page 1 of 2 12 LastLast
Results 1 to 15 of 22
  1. #1
    Regular Coder
    Join Date
    Apr 2006
    Posts
    231
    Thanks
    9
    Thanked 1 Time in 1 Post

    Undefined Constant?

    Hey all,

    I have profile_form.php which is basically a form/updater. The form submits info to the same file via a button called update.

    Now, at the top of the form, I have a simple update script for mysql but it won't excecute. it gives me a few errors like:
    Notice: Use of undefined constant update - assumed 'update' in /home/profile_form.php on line 17

    The Form:
    PHP Code:
    <form method="post">
    <
    input blah blah .... />
    <
    input blah blah .... />
    <
    input blah blah .... />
    <
    input type="submit" name="update" value="Update"/>
    </
    form
    Then the action:
    PHP Code:
    if (isset($_POST[update])  && $_POST[update]!=""){
    DO 
    STUFF    


  • #2
    Senior Coder NancyJ's Avatar
    Join Date
    Feb 2005
    Location
    Bradford, UK
    Posts
    3,174
    Thanks
    19
    Thanked 66 Times in 65 Posts
    The message is telling you exactly what the problem is - you don't have a constant defined called update but you have tried to use it. It then assumes you meant the string 'update' and uses that instead.

    PHP Code:
    //this is a constant, it differs from a variable because it is not prefixed with a $
    my_var

    //this is a string, it differs from a constant because it is enclosed in quotation marks
    'my_var' 
    Array keys are strings, which may be contained in constants, variables or given directly as string.

    To get rid of the warning change your code to:

    PHP Code:
    if(isset($_POST['update']) && $_POST['update']!=""

  • #3
    Senior Coder kbluhm's Avatar
    Join Date
    Apr 2007
    Location
    Philadelphia, PA, USA
    Posts
    1,509
    Thanks
    3
    Thanked 258 Times in 254 Posts
    Array keys are integers or strings, and nothing else:
    PHP Code:
    if (isset($_POST['update'])  && $_POST['update']!=""){ 

  • #4
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,072
    Thanks
    2
    Thanked 320 Times in 312 Posts
    The notice errors are because the syntax - $_POST[update] means that PHP must first look for a defined constant named update, then when it does not find one, it generates and logs the error, then looks for an array index named update. The proper syntax is - $_POST['update']

    However, php makes a correct assumption that you meant $_POST['update'] and continues execution. If your code is not working, it is not directly related to the missing quotes, and is likely due to some other logic problem.

    You would need to post your code to get any specific help with why it is not working.
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.

  • #5
    Regular Coder
    Join Date
    Apr 2006
    Posts
    231
    Thanks
    9
    Thanked 1 Time in 1 Post
    I still get error, so here, blow my brains out:

    PHP Code:
    <?php
    $check
    =$_POST['update'];
    if (isset(
    $check)  && $check!='' && $check=='update'){
         
    $userid=$_POST['memid'];
         
    $name=$_POST['firstname'];
         
    $gender=$_POST['gjinia'];
         
    $age=$_POST['mosha'];
         
    $location=$_POST['banimi'];
         
    $msn=$_POST['msn'];
         
    $aim=$_POST['aim'];
         
    $website=$_POST['website'];
         
    $interest=$_POST['interesat'];
         
    $update mysql_query("Update gallarific_users set firstname='$name', gjinia='$gender', mosha='$age', banimi='$location', msn='$msn', aim='$aim', website='$website', interesat='$interest' userid = '$userid'"); 
    }
    ?>
    <form method="post" action="self">
        <input type="hidden" name="memid" id="memid" value="<?php echo $user[userid]; ?>" size="30"/>
        <table width="90%" border="0">
            <tr>
                <td width="150" align="right" class="padlr"><strong>Pseudonimi:</strong></td>
                <td><?php echo $user["username"]; ?></td>
            </tr>
            <tr>
                <td width="150" align="right" class="padlr"><strong>Fjalekalimi:</strong></td>
                <td><?php echo $user["password"]; ?></td>
            </tr>
            <tr>
                <td width="150" align="right" class="padlr"><strong>Adresa E-Mail:</strong></td>
                <td><?php echo $user["email"]; ?></td>
            </tr>
            <tr>
                <td width="150" align="right" class="padlr"><strong>Emri Juaj: </strong></td>
                <td><input type="text" name="firstname" id="firstname" size="30" value="<?php echo $user["firstname"]; ?>" /></td>
            </tr>
            <tr>
                <td width="150" align="right" class="padlr">Gjinia: </td>
                <td>
                    <select name="gjinia" id="gjinia">
                        <option value="$user[gjinia]"><?php echo $user["gjinia"]; ?></option>
                        <option value="Mashkull">Mashkull</option>
                        <option value="Femer">Femer</option>
                        <option value="N/A">Sta Them</option>
                    </select>
                </td>
            </tr>
            <tr>
                <td width="150" align="right" class="padlr">Mosha: </td>
                <td>
                    <select name="mosha" id="mosha">
                        <option value="$user[mosha]"><?php echo $user["mosha"]; ?></option>
                        <option value="10-15">10-15</option>
                        <option value="16-20">16-20</option>
                        <option value="21-25">21-25</option>
                        <option value="26-30">26-30</option>
                        <option value="31-35">31-35</option>
                        <option value="35-40">35-40</option>
                        <option value="40+">40+</option>
                    </select>
                </td>
            </tr>
            <tr>
                <td width="150" align="right" class="padlr">Vendbanimi: </td>
                <td><input type="text" name="banimi" id="banimi" size="30" value="<?php echo $user["banimi"]; ?>" /></td>
            </tr>
            <tr>
                <td width="150" align="right" class="padlr">MSN Messenger: </td>
                <td><input type="text" name="msn" id="msn" size="30" value="<?php echo $user["msn"]; ?>" /></td>
            </tr>
            <tr>
                <td width="150" align="right" class="padlr">AIM Messenger: </td>
                <td><input type="text" name="aim" id="aim" size="30" value="<?php echo $user["aim"]; ?>" /></td>
            </tr>
            <tr>
                <td width="150" align="right" class="padlr">Hi5 / MySpace: </td>
                <td><input type="text" name="website" id="website" size="30" value="<?php echo $user["website"]; ?>" /></td>
            </tr>
            <tr>
                <td width="150" align="right" class="padlr">Ineteresat: </td>
                <td><textarea name="interesat" id="interesat" rows="3" cols="30"/><?php echo $user["ineteresat"]; ?></textarea></td>
            </tr>
            <tr>
                <td width="150" align="right" class="padlr"> </td>
                <td><input type="submit" id="update" name="update" value="update"/></td>
            </tr>
        </table>
    </form>

  • #6
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    You missed this one
    PHP Code:
    <input type="hidden" name="memid" id="memid" value="<?php echo $user[userid]; ?>" size="30"/>

  • #7
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,647
    Thanks
    2
    Thanked 406 Times in 398 Posts
    Change
    PHP Code:
    <form method="post" action="self">
        <input type="hidden" name="memid" id="memid" value="<?php echo $user[userid]; ?>" size="30"/>
    To
    PHP Code:
    <form method="post" action="self">
        <input type="hidden" name="memid" id="memid" value="<?php echo $user['userid']; ?>" size="30"/>

  • #8
    Regular Coder
    Join Date
    Apr 2006
    Posts
    231
    Thanks
    9
    Thanked 1 Time in 1 Post
    still nothing....

    I changed the action="self" to action="profile.php" which is basically self.
    I also changed what you guys said, but it didn't work.

  • #9
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,647
    Thanks
    2
    Thanked 406 Times in 398 Posts
    Post the error?

  • #10
    Regular Coder
    Join Date
    Apr 2006
    Posts
    231
    Thanks
    9
    Thanked 1 Time in 1 Post
    Notice: Undefined index: update in /home/.nigan/steganos/fotokoment.com/themes/black/profile_form.php on line 17

    Line 17 is right under the first if statement.

  • #11
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,072
    Thanks
    2
    Thanked 320 Times in 312 Posts
    action="self" has no meaning. This either must be an empty value - action='' or action="" or it must be a relative or absolute URL.
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.

  • #12
    Regular Coder
    Join Date
    Apr 2006
    Posts
    231
    Thanks
    9
    Thanked 1 Time in 1 Post
    which is why I changed it. Now I get this error, and it doesnt update the info in mysql.

    Notice: Undefined index: update in /home/.nigan/steganos/fotokoment.com/themes/black/profile_form.php on line 17

  • #13
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    interesat='$interest', userid = '$userid'"

    Missing a comma here. Doubt it's what's causing your problem though

  • #14
    Regular Coder
    Join Date
    Apr 2006
    Posts
    231
    Thanks
    9
    Thanked 1 Time in 1 Post
    It wasn't the problem. I put a little check in the update, and it doesnt update:

    if($update){echo updated;}
    else{echo error;}


    and everytime I submit the form, it gives me the error...

  • #15
    Regular Coder
    Join Date
    Mar 2007
    Location
    Quebec
    Posts
    261
    Thanks
    6
    Thanked 7 Times in 7 Posts
    Could this be it?
    PHP Code:
    $check=$_POST['update'];
    if (isset(
    $check)  && $check!='' && $check=='update'
    With that statement you're checking if $check is equal to 'update'. And since you said $check is $_POST['update'], its checking if $_POST['update'] contains the text "update". And since the button does NOT contain "update", the SQL query doesn't run.

    I just ran a test using the following code and nothing happened:
    PHP Code:
    <?php
    $check
    =$_POST['update'];
    if(isset(
    $check) && $check!="" && $check=="update"){
        echo 
    "Everything is returning true";
    }else{
        echo 
    "<form action='check.php' method='post'>
             <input type='submit' name='update' value='update'>
             </form>"
    ;
    }
    ?>
    I changed it to:
    PHP Code:
    <?php
    $check
    =$_POST['update'];
    if(isset(
    $check) && $check!=""){
        echo 
    "Everything is returning true";
    }else{
        echo 
    "<form action='check.php' method='post'>
             <input type='submit' name='update' value='Update'>
             </form>"
    ;
    }
    ?>
    and it worked fine. Try that I think it will work.

    Hope this helped
    -fl00d


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

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