Getting Started with Server-Side Validation

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • pbmods
    Recognized Expert Expert
    • Apr 2007
    • 5821

    #16
    Heya, speckledapple.

    That error means that you opened a curly brace somewhere and didn't close it.

    Comment

    • speckledapple
      New Member
      • Aug 2007
      • 17

      #17
      Thanks, its funny that it caused that. Anyway, i now have another error that I cant figure out because i know the syntax is right. But its providing an error as if its invalid.

      Warning: mysql_fetch_arr ay(): supplied argument is not a valid MySQL result resource

      I have this on two statements in my code...
      [PHP]$check = mysql_query("SE LECT ethoId FROM member WHERE ethoId = '$ethoid'");
      $returned = mysql_fetch_arr ay($check);

      if(!empty($retu rned))
      {
      echo " This user already exists!";
      mysql_close($me mber);
      Die();
      }
      else
      {
      $check = mysql_query("SE LECT email FROM member WHERE emailId='$email '");
      $returned = mysql_fetch_arr ay($check);
      if(!empty($retu rned))
      {
      echo " This email already is with another account!";
      mysql_close($me mber);
      Die();
      }[/PHP]

      Comment

      • pbmods
        Recognized Expert Expert
        • Apr 2007
        • 5821

        #18
        Heya, speckledapple.

        Try adding this after every mysql_query:
        [code=php]
        echo mysql_error();
        [/code]

        You might also want to save your sql into a variable so you can output that, too. E.g.:
        [code=php]
        $sql = "SELECT ethoId FROM member WHERE ethoId = '$ethoid'";
        $check = mysql_query($sq l);
        echo $sql, '<br />', mysql_error();
        [/code]

        Comment

        • speckledapple
          New Member
          • Aug 2007
          • 17

          #19
          Ok back again and i seem to be rolling until i hit a bit of a snag. I am getting this error message....

          Column count doesn't match value count at row 1

          I used the mysql_error to figure that part out. Not understanding why im getting it though. This is the code i think its talking about...

          [PHP]$pass1=md5($pas s1);
          $confirm_code = md5(uniqid(rand ()));
          $request = "INSERT INTO member values(NULL,'$f irst','$last',' $gender','$coun try','$city','$ state','$bmonth ','$bday','$bye ar', '$ethoid','$pas s1','$email','$ confirm_code')" ;
          $results = mysql_query($re quest);
          echo mysql_error();[/PHP]

          Comment

          • speckledapple
            New Member
            • Aug 2007
            • 17

            #20
            Disregard that last post, i got that working. Now im stuck though. This problem is a bit harder. I set up an email confirmation script that should update a column in my database when they click the link in their email. However, i am having trouble finding the right record. I think i got the selecting of the column down but the update statement doesnt compute because the ID column is not a variable in the script. So the "where" part in the update statement doesnt work. This is the script, im just trying to update one column out of 15.

            [PHP]$yes = "yes";
            // Retrieve data from table where row that match this passkey
            $sql1 = "SELECT confirm_code FROM member WHERE confirm_code ='$passkey'";
            $result1 = mysql_query($sq l1);

            if($result1){

            // Count how many row has this passkey
            $count=mysql_nu m_rows($result1 );
            if($count==1){

            $sql2 = "UPDATE member SET confirmed = '$yes' WHERE id = 'id'";
            $result2 = mysql_query($sq l2);
            echo $sql2, mysql_error();[/PHP]

            Comment

            • pbmods
              Recognized Expert Expert
              • Apr 2007
              • 5821

              #21
              Heya, speckledapple.

              Try this as your first query:
              [code=php]
              $sql1 = "
              SELECT
              `id`
              FROM
              `member`
              WHERE
              `confirm_code` = '{$passkey}'
              LIMIT 1";
              [/code]

              Then adjust the rest of your code where appropriate.

              Comment

              • speckledapple
                New Member
                • Aug 2007
                • 17

                #22
                I tried that and i see the problem just dont know how to tackle it. The issue seems that I have no variable to classify in the UPDATE line for id. I have an id column. But it doesnt update the confirmed column to a "yes" when the link is clicked. So i selected id from the table but how do i get into a variable that can be used in the update line so it knows which record im talking about? Because in its current form, if there was more than one record it would be a problem but its not even updating one record.

                [PHP]$sql3 = "SELECT id FROM member WHERE confirm_code ='$passkey' limit 1";
                $result1 = mysql_query($sq l3);
                if($result1){

                // Count how many row has this passkey
                $count=mysql_nu m_rows($result1 );
                if($count==1){
                echo $sql3, '<br/>', mysql_error();
                $sql4 = "UPDATE member SET confirmed = '$yes' WHERE id = '$sql3'";
                $result2 = mysql_query($sq l4);
                }[/PHP]

                Comment

                • pbmods
                  Recognized Expert Expert
                  • Apr 2007
                  • 5821

                  #23
                  Heya, speckledapple.

                  Hint:
                  [code=php]
                  $userdata = mysql_fetch_ass oc($result1);
                  print_r($userda ta);
                  [/code]

                  Comment

                  • speckledapple
                    New Member
                    • Aug 2007
                    • 17

                    #24
                    Ok, i have broken down the code step by step using the print_r and echo functions to have some kind of result print on the screen. While in the course of doing this i figured out that in the first part of the statement where it selects the records from the database, the resource id ends up always being 31. Obviously there is not 31 records in my database, its only one currently. so i think my problem is the actual selecting of the right ID and then to actually update a specific column in that row. So far ive just hit a nice large wall.

                    [PHP]$passkey=$_GET['passkey'];
                    $yes = "yes";
                    // Retrieve data from table where row that match this passkey
                    $sql3 = "SELECT id FROM member WHERE confirm_code ='$passkey'";
                    $result1 = mysql_query($sq l3);
                    $userdata = $result1;


                    if($result1){

                    $sql4 = "UPDATE member SET confirmed = '$yes' WHERE id = '$userdata'";
                    $result2 = mysql_query($sq l4);
                    print_r($sql4);
                    }
                    // if not found passkey, display message "Wrong Confirmation code"
                    else {
                    echo '<div class="error"> Wrong Confirmation Code!! </div>';
                    }

                    if($result2){

                    echo '<div class="error"> Your account has been confirmed.<br/>Welcome to <br/><strong>Etho s</strong>!!</div>';
                    mysql_close($me mber);
                    Die();
                    }[/PHP]

                    Comment

                    • pbmods
                      Recognized Expert Expert
                      • Apr 2007
                      • 5821

                      #25
                      Heya, SpeckledApple.

                      Change this line:
                      [code=php]
                      $userdata = $result1;
                      [/code]

                      To this:
                      [code=php]
                      $row = mysql_fetch_ass oc($result1);
                      $userdata = $row['id'];
                      [/code]

                      Comment

                      • speckledapple
                        New Member
                        • Aug 2007
                        • 17

                        #26
                        Ok since i last posted i have done very well in my php coding but now im kinda stuck again. But this time more in phpMyAdmin. Does anyone know how to link tables in that program because is surely cant find an option for it?

                        Comment

                        • ak1dnar
                          Recognized Expert Top Contributor
                          • Jan 2007
                          • 1584

                          #27
                          Originally posted by speckledapple
                          Ok since i last posted i have done very well in my php coding but now im kinda stuck again. But this time more in phpMyAdmin. Does anyone know how to link tables in that program because is surely cant find an option for it?
                          Link Table in PhpMyAdmin? Could you please be more specific?

                          Comment

                          • pbmods
                            Recognized Expert Expert
                            • Apr 2007
                            • 5821

                            #28
                            Heya, Speckled.

                            Changed thread title to better describe the problem; I don't know how we missed it for so long....

                            Are you trying to set up foreign key constraints?

                            Comment

                            • speckledapple
                              New Member
                              • Aug 2007
                              • 17

                              #29
                              Well yea i am trying to link tables in a database in phpMyAdmin using foreign keys. But theres no specific option in that program to do it.

                              Comment

                              • pbmods
                                Recognized Expert Expert
                                • Apr 2007
                                • 5821

                                #30
                                Heya, Speckled.

                                Are these InnoDB tables or MyISAM (check the operations page for an individual table)?

                                Comment

                                Working...