I did some major tweeking to my forum system today, and added a module for the control panel. I am going to allow basic editing.

I have error handling, and it's not throwing any errors, yet it's not updating the database when I make changes.

PHP Version

<?php
$m = $_GET['m'];

if($_SESSION) {


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

$query = mysql_query("UPDATE members SET password='".$_POST['password']."', email='".$_POST['email']."', icq='".$_POST['icq']."', aim='".$_POST['aim']."', msn='".$_POST['msn']."', yahoo='".$_POST['yahoo']."', home='".$_POST['home']."', password='".$_POST['job']."' WHERE name='$m'");

if (!query) {

die("Mysql Error:<br><br>".mysql_error());

}

}

include("W:/www/modulization/templates/cp_top.php");
include("W:/www/modulization/templates/cp.php");
include("W:/www/modulization/templates/cp_bottom.php");
} else {
include("W:/www/modulization/templates/cp_top.php");
include("W:/www/modulization/templates/cp_no.php");
include("W:/www/modulization/templates/cp_bottom.php");
}

?>

Template

    <tr>
    <form method='post' action="index.php?page=cp">
    <tr>
    <td class='forumcell2' width='100%' colspan='2' align='center'>Here you may update your profile information. Certain information is hidden for security purposes.</td>
    </tr>
    <tr>
    <td class='forumcell2' width='20%'>Password</td>
    <td class='forumcell2' width='80%'><input name="password" MAXLENGTH="16" value="<?=$this['password']?>">&nbsp; Your password is hidden for security.</td>
    </tr>
    <tr>
    <td class='forumcell2' width='20%'>Email</td>
    <td class='forumcell2' width='80%'><input name="email" MAXLENGTH="25" value="<?=$this['email']?>">&nbsp; Update your email address.</td>
    </tr>
    <tr>
     <td class='forumcell' width='100%' colspan='2'><b>Profile Information</b></td>
    </tr>
    <tr>
    <td class='forumcell2' width='20%'>ICQ number</td>
    <td class='forumcell2' width='80%'><input name="icq" MAXLENGTH="9" value="<?=$this['icq']?>">&nbsp; Update your ICQ number (9 chars or less).</td>
    </tr>
    <tr>
    <td class='forumcell2' width='20%'>AIM Nickname</td>
    <td class='forumcell2' width='80%'><input name="aim" value="<?=$this['aim']?>">&nbsp; Update your AIM Nickname.</td>
    </tr>
    <tr>
    <td class='forumcell2' width='20%'>MSN Nickname</td>
    <td class='forumcell2' width='80%'><input name="msn" value="<?=$this['msn']?>">&nbsp; Update your MSN Nickname.</td>
    </tr>
    <tr>
    <td class='forumcell2' width='20%'>Yahoo Nickname</td>
    <td class='forumcell2' width='80%'><input name="yahoo" value="<?=$this['yahoo']?>">&nbsp; Update your Yahoo Nickname.</td>
    </tr>
    <tr>
    <td class='forumcell2' width='20%'>Hometown</td>
    <td class='forumcell2' width='80%'><input name="home" value="<?=$this['home']?>">&nbsp; Update your Hometown.</td>
    </tr>
    <tr>
    <td class='forumcell2' width='20%'>Occupation</td>
    <td class='forumcell2' width='80%'><input name="job" value="<?=$this['job']?>">&nbsp; Update your Occupation.</td>
    </tr>
    <tr>
    <td colspan='2' class='forumcell' width='100%' align='center'><input type='submit' name='submit' value='Update Profile'></td>
    </tr>
    </form>

By the way the variable $this is an generator from a query that I generated from the _SESSION it works perfectly other places so I'm doubting it's the issue this time around.. it basically just gives "previews" of what's set in the database.

    A better way is (for debugging)...

    <?php
    $m = $_GET['m'];
    
    if($_SESSION) {
    
    
    if(isset($_POST['submit'])) {
    
    $query = "UPDATE members SET password='".$_POST['password']."', email='".$_POST['email']."', icq='".$_POST['icq']."', aim='".$_POST['aim']."', msn='".$_POST['msn']."', yahoo='".$_POST['yahoo']."', home='".$_POST['home']."', password='".$_POST['job']."' WHERE name='$m'";
    
    print $query //see if the query looks okay
    
    mysql_query($query)
    or die("Mysql Error:<br><br>".mysql_error());
    
    }
    
    }
    
    include("W:/www/modulization/templates/cp_top.php");
    include("W:/www/modulization/templates/cp.php");
    include("W:/www/modulization/templates/cp_bottom.php");
    } else {
    include("W:/www/modulization/templates/cp_top.php");
    include("W:/www/modulization/templates/cp_no.php");
    include("W:/www/modulization/templates/cp_bottom.php");
    }
    
    ?>
    

    Template

        <tr>
        <form method='post' action="index.php?page=cp">
        <tr>
        <td class='forumcell2' width='100%' colspan='2' align='center'>Here you may update your profile information. Certain information is hidden for security purposes.</td>
        </tr>
        <tr>
        <td class='forumcell2' width='20%'>Password</td>
        <td class='forumcell2' width='80%'><input name="password" MAXLENGTH="16" value="<?=$this['password']?>">&nbsp; Your password is hidden for security.</td>
        </tr>
        <tr>
        <td class='forumcell2' width='20%'>Email</td>
        <td class='forumcell2' width='80%'><input name="email" MAXLENGTH="25" value="<?=$this['email']?>">&nbsp; Update your email address.</td>
        </tr>
        <tr>
         <td class='forumcell' width='100%' colspan='2'><b>Profile Information</b></td>
        </tr>
        <tr>
        <td class='forumcell2' width='20%'>ICQ number</td>
        <td class='forumcell2' width='80%'><input name="icq" MAXLENGTH="9" value="<?=$this['icq']?>">&nbsp; Update your ICQ number (9 chars or less).</td>
        </tr>
        <tr>
        <td class='forumcell2' width='20%'>AIM Nickname</td>
        <td class='forumcell2' width='80%'><input name="aim" value="<?=$this['aim']?>">&nbsp; Update your AIM Nickname.</td>
        </tr>
        <tr>
        <td class='forumcell2' width='20%'>MSN Nickname</td>
        <td class='forumcell2' width='80%'><input name="msn" value="<?=$this['msn']?>">&nbsp; Update your MSN Nickname.</td>
        </tr>
        <tr>
        <td class='forumcell2' width='20%'>Yahoo Nickname</td>
        <td class='forumcell2' width='80%'><input name="yahoo" value="<?=$this['yahoo']?>">&nbsp; Update your Yahoo Nickname.</td>
        </tr>
        <tr>
        <td class='forumcell2' width='20%'>Hometown</td>
        <td class='forumcell2' width='80%'><input name="home" value="<?=$this['home']?>">&nbsp; Update your Hometown.</td>
        </tr>
        <tr>
        <td class='forumcell2' width='20%'>Occupation</td>
        <td class='forumcell2' width='80%'><input name="job" value="<?=$this['job']?>">&nbsp; Update your Occupation.</td>
        </tr>
        <tr>
        <td colspan='2' class='forumcell' width='100%' align='center'><input type='submit' name='submit' value='Update Profile'></td>
        </tr>
        </form>
    

    Copy and paste the SQL (from 'print $query') into mysql command prompt and see what you get.

      Hmm.. thanks! It turns out some code got in there shouldn't be there.. $m = the name of the person due to the url.. BUT I don't even use that? I must seriously stop falling asleep while coding.

        Ok..

        Everything updates but the password. Why would this be?

        <?php
        if($_SESSION) {
        
        
        if(isset($_POST['submit'])) {
        
        $query = "UPDATE members SET password='".$_POST['pass']."', email='".$_POST['email']."', icq='".$_POST['icq']."', aim='".$_POST['aim']."', msn='".$_POST['msn']."', yahoo='".$_POST['yahoo']."', home='".$_POST['home']."', password='".$_POST['job']."' WHERE name='".$this['name']."'";
        mysql_query($query) or die ('Something is wrong');
        
        echo "<META HTTP-EQUIV='refresh' content='0;URL=index.php?page=cp_updated'>";
        
        }
        
        include("W:/www/modulization/templates/cp_top.php");
        include("W:/www/modulization/templates/cp.php");
        include("W:/www/modulization/templates/cp_bottom.php");
        } else {
        include("W:/www/modulization/templates/cp_top.php");
        include("W:/www/modulization/templates/cp_no.php");
        include("W:/www/modulization/templates/cp_bottom.php");
        }
        
        ?>
        
            <tr>
            <form method='post' action="index.php?page=cp">
            <tr>
            <td class='forumcell2' width='100%' colspan='2' align='center'>Here you may update your profile information. Certain information is hidden for security purposes.</td>
            </tr>
            <tr>
            <td class='forumcell2' width='20%'>Password</td>
            <td class='forumcell2' width='80%'><input name="pass" MAXLENGTH="16" value="<?=$this['password']?>">&nbsp; Your password is hidden for security.</td>
            </tr>
            <tr>
            <td class='forumcell2' width='20%'>Email</td>
            <td class='forumcell2' width='80%'><input name="email" MAXLENGTH="25" value="<?=$this['email']?>">&nbsp; Update your email address.</td>
            </tr>
            <tr>
             <td class='forumcell' width='100%' colspan='2'><b>Profile Information</b></td>
            </tr>
            <tr>
            <td class='forumcell2' width='20%'>ICQ number</td>
            <td class='forumcell2' width='80%'><input name="icq" MAXLENGTH="9" value="<?=$this['icq']?>">&nbsp; Update your ICQ number (9 chars or less).</td>
            </tr>
            <tr>
            <td class='forumcell2' width='20%'>AIM Nickname</td>
            <td class='forumcell2' width='80%'><input name="aim" value="<?=$this['aim']?>">&nbsp; Update your AIM Nickname.</td>
            </tr>
            <tr>
            <td class='forumcell2' width='20%'>MSN Nickname</td>
            <td class='forumcell2' width='80%'><input name="msn" value="<?=$this['msn']?>">&nbsp; Update your MSN Nickname.</td>
            </tr>
            <tr>
            <td class='forumcell2' width='20%'>Yahoo Nickname</td>
            <td class='forumcell2' width='80%'><input name="yahoo" value="<?=$this['yahoo']?>">&nbsp; Update your Yahoo Nickname.</td>
            </tr>
            <tr>
            <td class='forumcell2' width='20%'>Hometown</td>
            <td class='forumcell2' width='80%'><input name="home" value="<?=$this['home']?>">&nbsp; Update your Hometown.</td>
            </tr>
            <tr>
            <td class='forumcell2' width='20%'>Occupation</td>
            <td class='forumcell2' width='80%'><input name="job" value="<?=$this['job']?>">&nbsp; Update your Occupation.</td>
            </tr>
            <tr>
            <td colspan='2' class='forumcell' width='100%' align='center'><input type='submit' name='submit' value='Update Profile'></td>
            </tr>
            </form>
        

        BTW, the query is pretty much correct, and I know the database variables are set correctly!..

          I think you still need some more sleep 🙂

          ".....password='".$_POST['job']
          

            :p - Woah my god.. that's embarrasing...I got plenty of sleep last night so let's see how the coding of today is. 🙂

              Write a Reply...