SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Zealot
    Join Date
    Apr 2003
    Location
    Texas, USA
    Posts
    139
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Can you spot an error?

    This is a form which members fill inside the members area:

    PHP Code:
    <?
    session_start
    ();
    if (!isset(
    $_SESSION['username'])) {
                                        die(
    'An error has ocurred. You have not logged in, or your session has expired.');
                                        exit();
    }

    $dbcnx = @mysql_connect("localhost""user""pass");
       if (!
    $dbcnx) { 
         echo( 
    "<p>Unable to connect to the " 
               
    "database server at this time.</p>" ); 
         exit(); 
       }

    // Select the database
       
    if (! @mysql_select_db("needforcash_com") ) {
         echo( 
    "<p>Unable to locate the " .
               
    "database at this time.</p >" ); 
         exit(); 
       }
       
    $itis "yes";
    $itisnot "no";
       
    $sql mysql_query("SELECT * FROM users WHERE username='$username'");

    $lookup mysql_fetch_assoc($sql);


    $tacticsnow $lookup['tacticsusername'];
    $tacticsupdated $lookup['tacticsupdated'];

    $allmylistnow $lookup['allmylistusername'];
    $allmylistupdated $lookup['allmylistupdated'];

    $bwlnow $lookup['bwlusername'];
    $bwlupdated $lookup['bwlupdated'];

    $hercunow $lookup['hercuusername'];
    $hercuupdated $lookup['hercuupdated'];

    $promoneynow $lookup['promoneyusername'];
    $promoneyupdated $lookup['promoneyupdated'];

    $safelisternow $lookup['safelisterusername'];
    $safelisterupdated $lookup['safelisterupdated'];

    $hisreferer $lookup['referer'];


    $sqltwo mysql_query("SELECT * FROM users WHERE username='$hisreferer'");

    $reflookup mysql_fetch_assoc($sqltwo);


    $tacticslink $reflookup['tacticsusername'];
    $allmylistlink $reflookup['allmylistusername'];
    $bwllink $reflookup['bwlusername'];
    $herculink $reflookup['hercuusername'];
    $promoneylink $reflookup['promoneyusername'];
    $safelisterlink $reflookup['safelisterusername'];

    ?>

    <html>
    .....
    <form name="updatesafelists" method="post" action="updatesafelists.php">
                <table width="100%" border="0" cellpadding="1" cellspacing="3">
                
                <tr><td><b>Ad Tactics</b></td></tr>
                <tr><td><a href="http://www.adtactics.com/index.php?ac=<?=$tacticslink?>">Click here to join</a></td></tr>
                <tr><td>Enter your AdTactics username below<br>
               <? if ($tacticsupdated == $itisnot) { ?>
                 http://www.adtactics.com/index.php?ac=<input name="tacticsnewlink" type="text"></td></tr>
               <? } elseif ($tacticsupdated == $itis) { ?>
                 http://www.adtactics.com/index.php?ac=<input name="tacticsnewlink" type="text" value="<?=$tacticsnow?>"></td></tr>
               <? ?>

                <tr><td>&nbsp;</td></tr>
                <tr><td>&nbsp;</td></tr>

                <tr><td><b>AllMyList</b></td></tr>
                <tr><td><a href="http://www.allmylist.net/?refid=<?=$allmylistlink?>">Click here to join</a></td></tr>
                <tr><td>Enter your AllMyList ID NUMBER below<br>
               <? if ($allmylistupdated == $itisnot) { ?>
                 http://www.allmylist.net/?refid=<input name="allmylistnewlink" type="text"></td></tr>
               <? } elseif ($allmylistupdated == $itis) { ?>
                 http://www.allmylist.net/?refid=<input name="allmylistnewlink" type="text" value="<?=$allmylistnow?>"></td></tr>
               <? ?>

                <tr><td>&nbsp;</td></tr>
                <tr><td>&nbsp;</td></tr>

                <tr><td><b>Business World List</b></td></tr>
                <tr><td><a href="http://businessworldlist.com/members/index.cgi?<?=$bwllink?>">Click here to join</a></td></tr>
                <tr><td>Enter your Business World List username below<br>
               <? if ($bwlupdated == $itisnot) { ?>
                 http://www.businessworldlist.com/members/index.cgi?<input name="bwlnewlink" type="text"></td></tr>
               <? } elseif ($bwlupdated == $itis) { ?>
                 http://www.businessworldlist.com/members/index.cgi?<input name="bwlnewlink" type="text" value="<?=$bwlnow?>"></td></tr>
               <? ?>

                <tr><td>&nbsp;</td></tr>
                <tr><td>&nbsp;</td></tr>
                
                <tr><td><b>HercuList</b></td></tr>
                <tr><td><a href="http://herculist.com/members/index.cgi?<?=$herculink?>">Click here to join</a></td></tr>
                <tr><td>Enter your HercuList username below<br>
               <? if ($hercuupdated == $itisnot) { ?>
                 http://www.herculist.com/members/index.cgi?<input name="hercunewlink" type="text"></td></tr>
               <? } elseif ($hercuupdated == $itis) { ?>
                 http://www.herculist.com/members/index.cgi?<input name="hercunewlink" type="text" value="<?=$hercunow?>"></td></tr>
               <? ?>

                <tr><td>&nbsp;</td></tr>
                <tr><td>&nbsp;</td></tr>

                <tr><td><b>ProMoneyMail</b></td></tr>
                <tr><td><a href="http://www.promoneymail.com/member<?=$promoneylink?>">Click here to join</a></td></tr>
                <tr><td>Enter your ProMoneyMail ID NUMBER below<br>
               <? if ($promoneyupdated == $itisnot) { ?>
                 http://www.promoneymail.com/member<input name="promoneynewlink" type="text"></td></tr>
               <? } elseif ($promoneyupdated == $itis) { ?>
                 http://www.promoneymail.com/member<input name="promoneynewlink" type="text" value="<?=$promoneynow?>"></td></tr>
               <? ?>

                <tr><td>&nbsp;</td></tr>
                <tr><td>&nbsp;</td></tr>
                
                <tr><td><b>Safe Lister</b></td></tr>
                <tr><td><a href="http://www.safelister.com/index.cgi?id=<?=$safelisterlink?>">Click here to join</a></td></tr>
                <tr><td>Enter your Safe Lister username below<br>
               <? if ($safelisterupdated == $itisnot) { ?>
                 http://www.safelister.com/index.cgi?id=<input name="safelisternewlink" type="text"></td></tr>
               <? } elseif ($safelisterupdated == $itis) { ?>
                 http://www.safelister.com/index.cgi?id=<input name="safelisternewlink" type="text" value="<?=$safelisternow?>"></td></tr>
               <? ?>

                <tr><td>&nbsp;</td></tr>
                <tr><td>&nbsp;</td></tr>

                <tr><td align="center"><input type="submit" name="Submit" value="Save"></td></tr>
                </table>
                </form>
    The above form submits to the following script which is where the problem is:

    PHP Code:
    <?
    session_start
    ();
    if (!isset(
    $_SESSION['username'])) {
                                        die(
    'An error has ocurred. You have not logged in, or your session has expired.');
                                        exit();
    }


    // Connect to the database server
       
    $dbcnx = @mysql_connect("localhost""user""pass");
       if (!
    $dbcnx) { 
         echo( 
    "<p>Unable to connect to the " 
               
    "database server at this time.</p>" );
         exit(); 
       } 
       
    // Select the database
       
    if (! @mysql_select_db("needforcash_com") ) {
         echo( 
    "<p>Unable to locate the MarketingH2O " .
               
    "database at this time.</p >" ); 
         exit(); 
       }

    $sql mysql_query("SELECT * FROM users WHERE username='$username'");

    $lookup mysql_fetch_assoc($sql);

    $tacticsoldlink $lookup['tacticsusername'];
    $allmylistoldlink $lookup['allmylistusername'];
    $bwloldlink $lookup['bwlusername'];
    $hercuoldlink $lookup['hercuusername'];
    $promoneyoldlink $lookup['promoneyusername'];
    $safelisteroldlink $lookup['safelisterusername'];

    // Define post fields into simple variables


    if(empty($_POST['tacticsnewlink'])) {
                                     
    $tacticsnewlink $tacticsoldlink;
                                     
    $tacticsupdated "no";
    } else {
            
    $tacticsnewlink $_POST['tacticsnewlink'];
            
    $tacticsupdated "yes";
    }


    if(empty(
    $_POST['allmylistnewlink'])) {
                                     
    $allmylistnewlink $allmylistoldlink;
                                     
    $allmylistupdated "no";
    } else {
            
    $allmylistnewlink $_POST['allmylistnewlink'];
            
    $allmylistupdated "yes";
    }


    if(empty(
    $_POST['bwlnewlink'])) {
                                     
    $bwlnewlink $bwloldlink;
                                     
    $bwlupdated "no";
    } else {
            
    $bwlnewlink $_POST['bwlnewlink'];
            
    $bwlupdated "yes";
    }


    if(empty(
    $_POST['hercunewlink'])) {
                                     
    $hercunewlink $hercuoldlink;
                                     
    $hercuupdated "no";
    } else {
            
    $hercunewlink $_POST['hercunewlink'];
            
    $hercuupdated "yes";
    }


    if(empty(
    $_POST['promoneynewlink'])) {
                                     
    $promoneynewlink $promoneyoldlink;
                                     
    $promoneyupdated "no";
    } else {
            
    $promoneynewlink $_POST['promoneynewlink'];
            
    $promoneyupdated "yes";
    }


    if(empty(
    $_POST['safelisternewlink'])) {
                                     
    $safelisternewlink $safelisteroldlink;
                                     
    $safelisterupdated "no";
    } else {
            
    $safelisternewlink $_POST['safelisternewlink'];
            
    $safelisterupdated "yes";
    }


    $query mysql_query("UPDATE users SET tacticsusername='$tacticsnewlink', tacticsupdated='$tacticsupdated', allmylistusername='$allmylistnewlink', allmylistupdated='$allmylistupdated', bwlusername='$bwlnewlink', bwlupdated='$bwlupdated', hercuusername='$hercunewlink', hercuupdated='$hercuupdated', promoneyusername='$promoneynewlink', promoneyupdated='$promoneyupdated', safelisterusername='$safelisternewlink', $safelisterupdated='$safelisterupdated' WHERE username='$username'");

    if (!
    $query) {
                  echo 
    'Your info were NOT updated.';
    } else {
               echo 
    'your info were updated successfully.';
    }

    ?>
    After I submit the form, I receive "Your info were NOT updated". Meaning, that the error is in that $query line where I post to the database.

    I've gone over the two scripts all day. I can't see why it's not updating the info in the database!

    Strangely, the above all worked before I added the:
    PHP Code:
     $tacticsupdated$allmylistupdated$bwlupdated$hercuupdated$promoneyupdated$safelisterupdated 
    variables!!

    Can someone spot the problem?

    Thanks. I appriciate any help.

  2. #2
    if($awake){code();} PHP John's Avatar
    Join Date
    Jul 2002
    Location
    Along the Wasatch Fault line.
    Posts
    1,771
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Some basic questions come to mind. I imagine you have the fields defined in the database, but are they compatible data types with the data you are trying to set?

    Have you echoed the query?
    PHP Code:
    $sql "UPDATE users
              SET
               tacticsusername    = '
    $tacticsnewlink',
               tacticsupdated     = '
    $tacticsupdated',
               allmylistusername  = '
    $allmylistnewlink',
               allmylistupdated   = '
    $allmylistupdated',
               bwlusername        = '
    $bwlnewlink',
               bwlupdated         = '
    $bwlupdated',
               hercuusername      = '
    $hercunewlink',
               hercuupdated       = '
    $hercuupdated',
               promoneyusername   = '
    $promoneynewlink',
               promoneyupdated    = '
    $promoneyupdated',
               safelisterusername = '
    $safelisternewlink',
               
    $safelisterupdated = '$safelisterupdated'
              WHERE
               username ='
    $username'"
    echo $sql;
    $query mysql_query$sql ); 
    John

  3. #3
    ********* Genius Mike's Avatar
    Join Date
    Apr 2001
    Location
    Canada
    Posts
    5,458
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    $safelisterupdated = '$safelisterupdated'

    should be

    safelisterupdated = '$safelisterupdated'

    I assume
    Mike
    It's not who I am underneath, but what I do that defines me.

  4. #4
    SitePoint Zealot
    Join Date
    Apr 2003
    Location
    Texas, USA
    Posts
    139
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes. It was the last part $safelisterupdated should be safelisterupdated.

    *sigh* I've been trying to spot this error all day. I guess I need glasses. I wonder if PHP programmers ten years from now will have to go through what we go through today. One charecter messes up *everything*

    Anyway... Thanks for the help John and Mike. You've been very helpful.

    Jimmy.

  5. #5
    ********* Genius Mike's Avatar
    Join Date
    Apr 2001
    Location
    Canada
    Posts
    5,458
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    You're welcome.

    I only noticed it after John formatted your code though For the future, it's easier to spot errors when formatting queries like that.
    Mike
    It's not who I am underneath, but what I do that defines me.

  6. #6
    if($awake){code();} PHP John's Avatar
    Join Date
    Jul 2002
    Location
    Along the Wasatch Fault line.
    Posts
    1,771
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I was pretty tired when I did it, so it passed right by me!

    Good catch, Naramation!
    John


Bookmarks

Posting Permissions

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