Web Analytics Made Easy -
StatCounter Graphic Designer with a PHP problem - CodingForum

Announcement

Collapse
No announcement yet.

Graphic Designer with a PHP problem

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Graphic Designer with a PHP problem

    Hi, i'm really not a programmer, but i have installed a script and set up some data-bases. I'm getting around most of the errors, but here's one that i don't even know how to approach.

    This is the message that i'm getting:


    "Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /web/sites/grinder/allxclubclassroom.com/tour/includes/tour_inc.php on line 129"

    Here are the two lines from "tour_inc.php" file:

    128: $sql_temp = mysql_query("SELECT $pagename FROM template WHERE templateid='$language'");
    129: $temp_check = mysql_fetch_array($sql_temp);


    What do I do about this?

  • #2
    It looks like you might have created a MySQL database,
    but you didn't create the table called "template",
    or did they have a setup script that did that for you?

    Just to make sure your two variables are OK, echo them
    and see what they contain ...

    echo $pagename;
    echo "<br />";
    echo $language;
    exit;

    $sql_temp = mysql_query("SELECT $pagename FROM template WHERE templateid='$language'");
    $temp_check = mysql_fetch_array($sql_temp);

    It will show you those two variables and stop.

    Comment


    • #3
      The message is saying "Hey buddy, on line 129 you are trying to use a MySQL query resultset to fetch a row out of the resultset, but the resultset 'aint valid!"

      So what you have to figure out is why did the query bomb? The best way to do that is to check the return values of the mysql_query() function. Here's a good way to do that:

      PHP Code:
      $query "SELECT $pagename FROM template WHERE templateid='$language'";
      $sql_temp mysql_query($query);
      if (!
      $sql_temp) {
          die(
      "TRAGEDY STRIKES!  Query failed!  Query text is: $query<br />Error is: ".mysql_error());
      }
      $temp_check mysql_fetch_array($sql_temp); 
      Notice I assign the query to a variable so I can echo it later on to troubleshoot the problem.

      (edit:

      Comment


      • #4
        Thanks for such quick responses....

        i'm still attempting both suggestions, but i dont think i'm doing it right because there are several php files and they're calling each other and i'm really not sure where to plug in this part of the code, sometimes i get nothing displayed and sometimes a different error is picked up before the program even comes to this part of the code... anyways this is what i'm getting as a result of Fumigator's suggestion:



        TRAGEDY STRIKES! Query failed! Query text is: SELECT FROM template WHERE templateid=''
        Error is: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FROM template WHERE templateid=''' at line 1



        it looks like a syntax error that's not even letting me display the results that i expected and "at line 1" part is not making any sense since all i have at line 1 is the php opening tag....

        Comment


        • #5
          Take a look at the query that was returned:
          Code:
          SELECT FROM template WHERE templateid=''
          Your variables $pagename & $language are empty when passed to the query.
          John

          Comment


          • #6
            I'm getting another error message now:
            TRAGEDY STRIKES! Due to the reccession, small companies will not be able to afford good quality programmers and will drop the remaining projects onto their web and graphic designers.

            Ok, back to the original problem. Here is the whole file:

            [php]
            <?

            # force SSL

            if($_SERVER["HTTPS"] != "on" && $use_ssl) {
            $newurl = "https://" . $_SERVER["SERVER_NAME"] . $_SERVER["REQUEST_URI"];
            header("Location: $newurl");
            exit();
            }

            # include config file
            include '../db.php';

            $username = $_GET['id'];
            $mid = $_GET['mid'];
            $mcidnumber = $_GET['mcid'];

            # Get the info from the config table
            $sql2 = mysql_query("SELECT dname,defaultphoto FROM config WHERE configid='1'");
            $row2 = mysql_fetch_array($sql2);
            $dname = $row2['dname'];
            $defaultphoto = $row2['defaultphoto'];


            #check status of member for active
            $sql_active = mysql_query("SELECT status FROM member WHERE username='$username'");
            $checkuser = mysql_num_rows($sql_active);

            $active_check = mysql_fetch_array($sql_active);
            $active = $active_check['status'];

            if ($checkuser == '0') {
            header ("Location: http://$dname/index.php?show=2");
            exit();
            } else if ($active == '0') {
            header ("Location: http://$dname/index.php?show=1");
            exit();
            } else {

            # search to verify the mid is a valid tour taker
            $sql = mysql_query("SELECT memberid FROM member WHERE memberid='$mid' AND type='1'");
            $num_mid = mysql_num_rows($sql);

            if ($num_mid > '0') {

            # insert into the pagetrack table to record this visit if mid is not empty
            $sql = mysql_query("INSERT INTO pagetrack (memberid, pageid, visitdate) VALUES ('$mid', '$pid', now())") or die (mysql_error());

            if(!$sql){
            echo "There has been an error updating the tracking. Please contact support.";
            } else {
            $pagetrackid = mysql_insert_id();

            # Start the Member Session
            session_start();

            # check for session info
            $trackinfin = $_SESSION['trackinfin'];

            # Check to see that the member is logged in
            if ( empty( $trackinfin ) ) {

            # Register a session variable
            session_register('trackinfin');
            $_SESSION['trackinfin'] = "intrackin";

            # Update a visitation number into the visits column of the member table
            $sql = mysql_query("SELECT visits,fname,lname,emailaddress,phone,state,country,tourdate FROM member WHERE memberid='$mid'");
            $row = mysql_fetch_array($sql);
            $visits = $row['visits'];
            $totalvisits = $visits + 1;

            $sql_update = mysql_query("UPDATE member SET visits='$totalvisits' WHERE memberid='$mid'");
            mysql_query($sql_update);

            }; // end if empty

            }; // end if sql

            # get tour taker info
            $sql = mysql_query("SELECT visits,fname,lname,emailaddress,phone,state,country,tourdate FROM member WHERE memberid='$mid'");
            $row = mysql_fetch_array($sql);

            $tfname = $row['fname'];
            $tlname = $row['lname'];
            $temailaddress = $row['emailaddress'];
            $tphone = $row['phone'];
            $tstate = $row['state'];
            $tcountry = $row['country'];
            $tourdate = $row['tourdate'];

            }; // end if num_mid


            $sql_info = mysql_query("SELECT * FROM member WHERE username='$username' AND status='1'");
            $result = mysql_fetch_array($sql_info);
            $efname = $result['fname'];
            $elname = $result['lname'];
            $eemailaddress = $result['emailaddress'];
            $ephone = $result['phone'];
            $ememberid = $result['memberid'];
            $aphoto1 = $result['aphoto1'];
            $cusername = $result['cusername'];
            $estate = $result['state'];
            $ecountry = $result['country'];
            $language = $result['language'];
            $cidnumber = $result['cidnumber'];

            if ($aphoto1 == '1') {
            $photourl = "/member/memphoto/azab_" . $ememberid . ".jpg";
            } else {
            $photourl = $defaultphoto;
            }; // end if empty aphoto1



            # get the tour takers ip
            $ipaddress = $_SERVER['REMOTE_ADDR'];

            # check for the comefrom field
            $comefrom = $_GET['t'];

            if (!$comefrom) {
            $comefrom = "";
            }; // end comefrom

            # get the members information from the database
            $sql_temp = mysql_query("SELECT $pagename FROM template WHERE templateid='$language'");
            $temp_check = mysql_fetch_array($sql_temp);
            $html = $temp_check[$pagename];

            $html=str_replace("[emailaddress]", $eemailaddress, $html);
            $html=str_replace("[firstname]", $efname, $html);
            $html=str_replace("[lastname]", $elname, $html);
            $html=str_replace("[phone]", $ephone, $html);
            $html=str_replace("[state]", $estate, $html);
            $html=str_replace("[country]", $ecountry, $html);
            $html=str_replace("[memberid]", $ememberid, $html);
            $html=str_replace("[username]", $username, $html);
            $html=str_replace("[ipaddress]", $ipaddress, $html);
            $html=str_replace("[mid]", $mid, $html);
            $html=str_replace("[cusername]", $cusername, $html);
            $html=str_replace("[photo]", $photourl, $html);
            $html=str_replace("[tourdate]", $tourdate, $html);
            $html=str_replace("[tourfirstname]", $tfname, $html);
            $html=str_replace("[tourlastname]", $tlname, $html);
            $html=str_replace("[touremailaddress]", $temailaddress, $html);
            $html=str_replace("[tourphone]", $tphone, $html);
            $html=str_replace("[tourstate]", $tstate, $html);
            $html=str_replace("[tourcountry]", $tcountry, $html);
            $html=str_replace("[cid]", $cidnumber, $html);


            #Tour URL Prefix

            $toururl = "http://$dname/$username";

            }; // end if checkuser

            ?>
            [php]


            now there IS a script that creates members in the database, I did have some errors in there, but nothing serious, i don't think i messed up any code while fixing those.

            Does this code tell you guys anything?

            Comment


            • #7
              TRAGEDY STRIKES! Due to the reccession, small companies will not be able to afford good quality programmers and will drop the remaining projects onto their web and graphic designers.


              You have not assigned anything to your $pagename variable. I don't know what else to say about it... it has to have a value for that query to work.

              Comment

              Working...
              X