Jump to content

WendyLady

Members
  • Posts

    38
  • Joined

  • Last visited

    Never

Posts posted by WendyLady

  1. fizzzgigg --

    Your code is very long & to debug it I would have to compile it myself & work on it (unfortunately I don't have this kind of time). BUT -- my jerry-rigged version of debugging is a multi-step process I'll share.

    1) Step away from the computer, take a little walk, have a soda or a beer & clear your head for a few minutes. All the little $&"; characters run together after a while. Seriously, this is my most valuable step in figuring out errors. On my most recent project where I have had to really push the envelope on my coding skills, I have worked on a little problem for HOURS, then taken a break & sat back down to realize it was a typo the whole time.

    2) Come back to the computer and read through your code step-by-step, making sure there isn't an illogical step somewhere.

    3) Add echo statements at each step throughout the code to see where the code is stopping/breaking. I have found this to help me a lot. Example: always put echo statement before your WHILE statements in your code to figure out if it isn't finding anything & there is something wrong with the query. Echo back your queries, echo back sent variables (another problem I have often -- I have sent a variable incorrectly) at every step in your functions & other code.

    4) Consider whether there is a more efficient/logical way to arrange your code. If not, try steps 1-2 again.

    Wendy
  2. rstrik --

    While I'm sure there are reasons why you will get "headers already sent" as opposed to "cannot modify headers" -- in my experience so far these errors have been nearly interchangeable in that they have been caused by the same thing. I sent you the link since it goes into more detail. Did you even try the solutions from my earlier post or the other link?

    Wendy
  3. bxmachines,

    I have been as much a noobie as you, so I will make this simple.

    1) All of the variable declarations -- $variable = $_POST['variable']; -- you can either leave all of these in (which is very verbose), or you can delete all of them & insert joquius's snippet of code instead. It really doesn't matter. To first get it working, you might leave this part as-is, then try his more efficient code later.

    2) After you declare all your variables, your INSERT statement is incorrect. It is going to be a very, very LONG statement. Following Violet's suggestion:

    [code]$query = "INSERT INTO servicerecord (textbox1name, textbox2name, check1male, check1female ...) VALUES ('$textbox1name', '$textbox2name', '$check1male', '$check1female', ...)";[/code]

    EVERY table cell you want to insert data into must be listed in the first set of parentheses(), THEN its matching $variable must be listed in the second set of parentheses(), IN THE SAME ORDER. Also, be sure to follow my (or Violet's) lead as to which things have single & double quotes. Obviously, do not leave the "..." in -- this is just to demonstrate that there will be more entries after it.

    3) It is not a good idea to simply spit out "This worked" at the end without checking it somehow. At least until you have debugged your script, add a simple IF statement to check it:

    [code]if (mysql_affected_rows == 1) {
       echo "Succeeded";
       }else{
       echo "Failed: ".mysql_affected_rows()." affected rows with Query: ".$query."<br />Error:".mysql_error();
       }[/code]

    The above will help you figure out what is going on by giving you the returned error messages (if any). It is also a good idea to leave these statements in, but change them to something like "An Error occurred: please contact the webmaster" so that the poor non-profit people aren't thinking things always worked if they DIDN'T.

    Wendy

    Can I make a suggestion?

    Instead of having checkboxes for Male & Female, instead make these radio buttons. Give them the same name but values of M or F, so that no one can check BOTH of them!

    <input type="radio" name="gender" value="M"> Male
    <input type="radio" name="gender" value="F"> Female

    Then you can simplify to ONE table in your database called "Gender" and assign in the value of $_POST['gender'].

    Just an idea --

    Wendy

    --Always assume the user will screw it up somehow.
  4. I have a stupid question.

    Under what circumstances would you be storing identical rows with NO way to differentiate them? What purpose would it serve? I can understand duplicate entries, but only if they have an ID that links to another table or something so that you can tell them apart.

    The only possible thing I can think of is something like a poll, but if you're going to be modifying or deleting them, it still stands to reason that they need some sort of unique identifier, such as an auto-increment ID field.

    Wendy
  5. When you get the message "headers already sent" -- the VERY first thing you do is check every included & required file & make sure there aren't any spaces before the first "<?php" or after the last "?>". Also make sure that nowhere in any of those files have you sent anything to be printed or echoed.

    Then try surrounding your session code with OB_start(); and OB_flush();. But try the first things first.

    Wendy

    Edited: HEY! I'm not the first person to figure this out: Go have a look-see: [a href=\"http://www.phpfreaks.com/forums/index.php?showtopic=37442\" target=\"_blank\"]http://www.phpfreaks.com/forums/index.php?showtopic=37442[/a]
  6. The "not a valid resource" error has been driving me up the wall recently.

    From what I can tell with my own code so far is that this really means, "I didn't manage to select/update/delete the thing you requested, and it's because you made an error in my code, silly". In other words, it didn't like your query somewhere.

    For me it usually means that SQL wanted parentheses somewhere, or a single quote around something, etc. Sometimes what works in one place doesn't work somewhere else (I would say there are gremlins somewhere in my database, but I am sure it has more to do with my relatively NOOBIE status as a PHP programmer).

    Wendy
  7. Hi everyone --

    I have an interesting thing happening that is just annoying, but interesting. I can work around it, but I would really like to know why it is happening.

    I have an option on a form that either UPDATEs or DELETEs a row in the MySQL database. After each one, I have the following code to confirm the UPDATE or DELETE:

    [code]if (mysql_affected_rows != 1) {
                    echo 'Problem!';
                    echo '<br />' . mysql_affected_rows() . $query;
                }else{
                    header ("Location: index.php");
                }[/code]

    The screwy thing is, for the UPDATE query it returns "Problem! 1 (affected row)" and then the query. And when I check the database, it [b]has updated properly[/b].

    For the DELETE query, it returns "Problem! 0 (affected rows)" and then the query. And when I check the database, it [b]has deleted properly[/b].

    Why would it be going into the "if !=1" when it IS equal to 1, and why would it be returning 0 affected rows when there IS an affected row? I have stated the above in a variety of ways, such as reversing it to "if ==1", "if ==0 || if == -1", etc., to no avail!

    Have you seen this before? Am I making a stupid mistake that is causing it?

    Darn curious (and Thank you!),

    Wendy
  8. [code]$ts = date("m/d/Y", strtotime($myrow[12]));[/code]


    I have been searching everywhere for the past 2 weeks to simply reformat a MySQL date for the project I'm working on -- I just want it to look recognizable! -- and finally this!

    Thanks!

    Wendy
  9. Hi, all -- I have a question that is purely for formatting, but I'm not sure how to even search for this, or how to call things.

    I'm dealing with a database where users' contact information will be returned. I have two fields for address: address1 and address2. An example is that if the person has entered two address lines, I want it to print:

    address1, address2
    city, state, zip

    But if they have only entered the first line & the second line is empty, I don't want it to print:

    address1,
    city, state, zip

    So I think I need to write a little function for each formatting issue that would say, for example,
    if NOT NULL . . then echo ", address2""
    else do nothing

    Such a silly thing -- but I'm not sure how to start. There are several of these that pose a problem. Can anyone point me in the right direction, even just to tell me how to search for help?

    Thank you!

    Wendy
  10. IT IS WORKING!!! Woo-hooo!!!! I settled down long enough from doing a little jig to post results for posterity. Here are my responses to all of you who answered my plea for help, as well as the working code, since I have not seen this anywhere else on the web (populating a form & the submitting it).

    jeremy & 448191: it occurred to me that if someone checked ALL the boxes, they would print out the entire database. NOT good for the purposes here. I changed it to a radio instead, which simplified having to implode or any of that. However, on the admin side, I am going to need to use that implode function for a userface to help insert categories using checkboxes, so I will be using it & appreciate you mentioning it (I haven't used it before).

    shoz: I do actually need a full-text search, because (this is complicated) -- I have one table with my possible categories, and another table with customers, who can fall into more than one category. On the customer table, the description field contains the categories they belong to. This might not be the most efficient way to do it, but it seemed simplest for my meager programming skills. BUT-- the vardump/print_r functions were also new to me, and they are coming in handy! I used a variation on this for my search results, so that it prints out "Results for X" intead of just "Search Results". I also changed the 'desc' field & that helped.

    Thanks so much, everyone! I am just so excited, because with these first two major problems figured out, doing the rest of the site will be a breeze. I was getting worried that it was way beyond me.

    What worked in the code:
    [code]
        function searchForm2()
    {
        $searchwords = (isset($_GET['category']) ? htmlspecialchars(stripslashes($_REQUEST['category'])) : '');

        echo '<p><form method="GET" action="'.$_SERVER['PHP_SELF'].'">';
        echo '<input type="hidden" name="cmd" value="search2" />';

    include ("includes/functions/mysql_connect.php");

                $category = $_GET['category'];
                $query = "SELECT category FROM mvci_category";
                $result = mysql_query($query);
                while (list($category) = mysql_fetch_row($result))
                {
                    echo "<input type=\"radio\" name=\"category\" value=\"$category\" />$category
                          <br />";
                }
        echo '<input type="submit" value="Search Services" />';
        echo '</form></p>';

    ........

        echo '<h2>Search Services: Results for <i>'.($_GET['category']).'</i></h2><br />';
        searchForm2();

    //   $searchstring = mysql_escape_string($_GET['$category']);

        $sql = "SELECT first, last,
               MATCH(description)
               AGAINST ('$category' IN BOOLEAN MODE) AS score FROM mvci_customer
               WHERE MATCH(description)
               AGAINST ('$category' IN BOOLEAN MODE) ORDER BY score DESC";

      $result = mysql_query($sql) or die (mysql_error());

        while($row = mysql_fetch_object($result))
        {
          echo '<strong>First: '.stripslashes(htmlspecialchars($row->first)).'</strong><br />';
          echo 'Score:'. number_format($row->score, 1);
          echo '<hr size="1" />';
        }
    [/code]
    What acutally made it work was ignoring the variable $searchstring & using straight $category in my query (second part). The first form was returning the categories, but it wasn't making it through the variable. If this opens me up to a security risk, please let me know. Thanks again so much!
    Wendy
  11. Hi, everyone -- I hope that as I get more proficient with PHP I can be more of a help & not just asking --

    I have a 2-part problem, and I have solved the 1st part:

    In order to fully automate a site for a client, I have a set of customer categories that are changeable in an interface by the company owner. Today I *finally* [img src=\"style_emoticons/[#EMO_DIR#]/laugh.gif\" style=\"vertical-align:middle\" emoid=\":laugh:\" border=\"0\" alt=\"laugh.gif\" /] figured out how to populate a form (group of checkboxes) by calling those categories out of the database. Whew!

    Now, I am setting up a search where a user would be able to search the database for entries matching those categories. I have set up a boolean search using MATCH . . . AGAINST, but I keep getting the same error:

    [!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]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 'desc) AGAINST ('Array' IN BOOLEAN MODE) AS score FROM table_customer ' at line 2[/quote]

    Below is my full code, starting with calling the categories to populate the form, and followed by the 2nd query.

    I really appreciate any help you can offer! I've been pulling my hair out for two days. I'm not sure if I'm making a silly mistake somewhere that I can't catch because I'm so cross-eyed, or whether it doesn't like gathering the array to submit for the MATCH . . . AGAINST code.

    Wendy

    The searchForm function, because I'm using it several times throughout the site (the fact that it is a function is pulled from a tutorial on here because the switch statments were making me crazy) -- it returns the checkbox form like a charm:
    [code]
        function searchForm2()
    {
        $searchwords = (isset($_GET['cat']) ? htmlspecialchars(stripslashes($_REQUEST['cat'])) : '');

        echo '<form method="get" action="'.$_SERVER['PHP_SELF'].'">';
        echo '<input type="hidden" name="cmd" value="search1" />';

        include "includes/functions/mysql_connect.php";
                $category = $_GET['category'];
                $query = "SELECT category FROM table_customer";
                $result = mysql_query($query);
                while (list($category) = mysql_fetch_row($result))
                {
                    echo "<input type=\"checkbox\" name=\"cat[]\" value=\"$category\" />$category
                          ";
                }
        echo '<input type="submit" name="submit1" value="Search Services" />';
        echo '</form>';
    }
    [/code]

    The actual query where the error is appearing, minus the switch:
    [code]
    echo '<h2>Search Services: Results</h2><br />';
        searchForm2();
        $searchstring = mysql_escape_string($_GET['cat']);

        $sql = "SELECT first, last,
               MATCH(desc)
               AGAINST ('$searchstring' IN BOOLEAN MODE) AS score FROM table_customer
               WHERE MATCH(desc)
               AGAINST ('$searchstring' IN BOOLEAN MODE) ORDER BY score DESC";

      $result = mysql_query($sql) or die (mysql_error());

        while($row = mysql_fetch_object($result))
        {
          echo '<strong>First: '.stripslashes(htmlspecialchars($row->first)).'</strong><br />';
          echo 'Score:'. number_format($row->score, 1);
          echo '<hr size="1" />';
        }
    [/code]

    Thanks again!
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.