Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

cms was workin - until i looked this morn

Options
  • 03-12-2009 12:24pm
    #1
    Registered Users Posts: 287 ✭✭


    then got this

    Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/squarebar/domains/nixysthesquarebar.com/public_html/cmslogin/update.php on line 37


    <?php

    // Connect to the database
    $cnx = mysql_connect("localhost", "********", "*******")
    OR die("Unable to connect to database!");
    mysql_select_db("***********", $cnx);


    if ($_POST == 1) {
    // Save to the database
    $content = mysql_real_escape_string(trim($_POST));
    $res = mysql_query("UPDATE webcontent SET content = '".$data."' WHERE id = $id");

    if (!$res)
    die("Error saving the record! Mysql said: ".mysql_error());

    // Redirect to self to get rid of the POST
    header("Location: admin.php");
    }

    include_once "fckeditor/fckeditor.php";
    ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
    <html xmlns="http://www.w3.org/1999/xhtml&quot; xml:lang="en" lang="en">
    <head>
    <title>Test FCKeditor</title>
    </head>
    <body>

    <h1>Test FCKeditor</h1>

    <form action="testselect.php" method="post">
    <?php
    // Get data from the database
    $query = mysql_query("SELECT content FROM webcontent WHERE id=$id");

    $content = mysql_fetch_array($query);
    // Configure and output editor
    $oFCKeditor = new FCKeditor('content');
    $oFCKeditor->BasePath = "fckeditor/";
    $oFCKeditor->Value = $content["content"];
    $oFCKeditor->Width = 540;
    $oFCKeditor->Height = 400;
    echo $oFCKeditor->CreateHtml();
    ?>
    <br />
    <input type="hidden" name="submit_form" value="1" />
    <input type="submit" value="Save Form" />
    </form>

    </body>
    </html>


    <?php
    // Close the database connection
    mysql_close($cnx);
    ?>

    any particular reason


Comments

  • Closed Accounts Posts: 18,163 ✭✭✭✭Liam Byrne


    This is about the third time we've pointed out to you that you haven't set the variable $id.

    The error isn't on the highlighted line; the error is that the highlighted line is using a variable $query which hasn't been set properly on the previous line
    $query = mysql_query("SELECT content FROM webcontent WHERE id=[b]$id[/b]"); 
    
    $content = mysql_fetch_array($query);
    

    The same problem exists further up the page, but isn't kicking in because you haven't asked the page to edit any content
    $res = mysql_query("UPDATE webcontent SET content = '".$data."' WHERE id = [b]$id[/b]");
    

    In addition, you haven't put anything into the form to enable the $id to be passed to the form.

    All of the above were pointed out to you before. And without getting narky (there's no problem asking for, or getting, help on this thread) if you don't implement it then what's the point in asking ? Or people spending time replying ?

    The above code - as posted - NEVER worked. Unless you've accidentally rolled back to an old copy of the file, there is no way that your CMS was working.


  • Registered Users Posts: 287 ✭✭Keewee6


    <?php

    // Connect to the database
    $cnx = mysql_connect("localhost", "*********", "*****")
    OR die("Unable to connect to database!");
    mysql_select_db("******", $cnx);

    $id= $row; is this not setting the id

    if ($_POST == 1) {
    // Save to the database
    $content = mysql_real_escape_string(trim($_POST));
    $res = mysql_query("UPDATE webcontent SET content = '".$data."' WHERE id = $id");

    if (!$res)
    die("Error saving the record! Mysql said: ".mysql_error());

    // Redirect to self to get rid of the POST
    header("Location: admin.php");
    }

    include_once "fckeditor/fckeditor.php";
    ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
    <html xmlns="http://www.w3.org/1999/xhtml&quot; xml:lang="en" lang="en">
    <head>
    <title>Test FCKeditor</title>
    </head>
    <body>

    <h1>Test FCKeditor</h1>

    <form action="testselect.php" method="post">
    <?php
    // Get data from the database
    $query = mysql_query("SELECT content FROM webcontent WHERE id=$id");

    $content = mysql_fetch_array($query);
    // Configure and output editor
    $oFCKeditor = new FCKeditor('content');
    $oFCKeditor->BasePath = "fckeditor/";
    $oFCKeditor->Value = $content["content"];
    $oFCKeditor->Width = 540;
    $oFCKeditor->Height = 400;
    echo $oFCKeditor->CreateHtml();
    ?>
    <br />
    <input type="hidden" name="submit_form" value="1" />
    <input type="submit" value="Save Form" />
    </form>

    </body>
    </html>


    <?php
    // Close the database connection
    mysql_close($cnx);
    ?>

    must have being a fluke


  • Closed Accounts Posts: 18,163 ✭✭✭✭Liam Byrne


    Keewee6 wrote: »
    [B]   $id= $row['id'];[/B][B] is this not setting the id[/B]
    

    a) that line wasn't in the original post

    b) even if it were, it isn't setting anything because $row isn't set anywhere before that, so $row means nothing at that point in the code (and incidentally, would mean nothing after that, because $row isn't set anywhere on that page).
    Keewee6 wrote: »
    must have being a fluke

    No, it's just badly coded.

    If you want help, then PLEASE stop adding code to the posts after you've posted the original query. We all have to learn somehow, but trying to second-guess problems and explain the very, very basics is far too frustrating.

    And again, I'm not being cruel.....some of the questions are like "how do you service a car", and when I reply "well, under the bonnet there's...." and getting "hang on, what's a bonnet ?"

    I've said it before; if we knew what level you were really at, we could explain it one way [ even without the code ] but posting "CMS nearly finished / CMS was working, what's wrong" indicates a level of understanding that simply isn't backed up by the code. There's no fault in that, but it does mean that any help that we give you seems to go completely over your head.

    As I said before, try to UNDERSTAND what the code is doing, rather than simply copying and pasting random lines of code, or adding them randomly to existing code that you've already asked about.

    If you were retrieving an existing record from the database, what would you do ? Step by step

    Forget PHP - post it in English.

    If you were updating a record using a form, what would you do ? Again, step by step

    Again, forget PHP - post it in English.


  • Registered Users Posts: 287 ✭✭Keewee6


    i know thanks

    1. i want to retrieve a record
    2. update using fck


  • Closed Accounts Posts: 18,163 ✭✭✭✭Liam Byrne


    Keewee6 wrote: »
    i know thanks

    1. i want to retrieve a record
    2. update using fck

    That's not step-by-step! :eek:

    OK, let me try again.

    If you wanted to "buy a present", what would you do ? The overall "buy a present" is the equivalent of what you've said in the above, but what are the steps ?

    1. Decide on what present
    2. Check what shop it might be in
    3. Drive to town
    4. Park
    5. Go to the shop and check the price
    6. Maybe repeat step 5 with other shops
    7. Go to the ATM
    8. Withdraw the required cash
    9. Go back to the shop
    10. Buy the item
    11. Bring it home
    12. Wrap it

    So THINK about ALL of the steps you need to do - in English; once you've done that, then translating from English to PHP will be relatively straightforward, and you won't be leaving out required steps due to a lack of knowledge of a particular language.


  • Advertisement
  • Registered Users Posts: 287 ✭✭Keewee6


    like
    1. select the record to edit
    2 open the record in the editor
    3 make the neccessary changes
    4 save the changes


  • Closed Accounts Posts: 18,163 ✭✭✭✭Liam Byrne


    Keewee6 wrote: »
    like
    1. select the record to edit
    2 open the record in the editor
    3 make the neccessary changes
    4 save the changes

    OK, now we're getting places.

    Now break down those steps some more; what steps do you need to do within each of those ? e.g. how do you "select the record to edit" ?


  • Registered Users Posts: 287 ✭✭Keewee6


    Liam Byrne wrote: »
    OK, now we're getting places.

    Now break down those steps some more; what steps do you need to do within each of those ? e.g. how do you "select the record to edit" ?

    write a select query


  • Registered Users Posts: 287 ✭✭Keewee6


    mysql_fetch_array(): supplied argument is not a valid MySQL result resource

    regarding this line

    $content = mysql_fetch_array($query);


  • Closed Accounts Posts: 18,163 ✭✭✭✭Liam Byrne


    Keewee6 wrote: »
    write a select query

    Nope! You're jumping the gun!

    A "select query" will retrieve the record(s) that you want from a database, but you haven't yet specified - IN ENGLISH - which record you want, or how you propose getting it.


  • Advertisement
  • Closed Accounts Posts: 18,163 ✭✭✭✭Liam Byrne


    Keewee6 wrote: »
    mysql_fetch_array(): supplied argument is not a valid MySQL result resource

    regarding this line

    $content = mysql_fetch_array($query);

    OK, I'm getting totally frustrated now......did you even read the earlier post that I made ?
    LiamByrne wrote: »
    The error isn't on the highlighted line; the error is that the highlighted line is using a variable $query which hasn't been set properly on the previous line

    If you want help, I'll do my best, but if you're simply going to throw in random posts and not read what was said, I'm going to have to move on and just tell you to take a course or something, because some of your posts are almost random and completely irrelevant (earlier throwing in a completely new line to the original question, claiming that the CMS was working, etc), and TBH I've better things to do than repeatedly hold your hand if you're not going to take heed.

    Break down the earlier steps into single, discrete steps, making sure that you have EVERYTHING specified.....e.g. "open the drawer" doesn't specify "which" drawer...

    Likewise my earlier example included a step "withdraw money from an ATM"; that's not a discrete step......it involves taking your card out, putting it in the machine, typing in your PIN, selecting "withdraw", giving the amount, etc.

    I'd advice you to step away from the computer or PHP or select queries or ANYTHING until you have your head around what steps you need.


  • Registered Users Posts: 1,127 ✭✭✭smcelhinney


    I apologise if this is considered trolling, I have not much to add but to say Liam you are the most patient person I've ever met.

    I should also add for the OP, that you need to learn Pseudocode before you try to do actual code. What Liam is saying is correct, programming is formulaic, its retarded at times, but it is meant to be logical.

    Also, when you do figure out how to set an acceptable value for $id, pay attention to scope. You have several function calls within your page, and while Im no genius at PHP (Im a java developer), I would imagine the same rules for scope apply. Declare the variable globally, and set locally when required.

    Is this an off the shelf CMS, or is it one you have pieced together yourself?

    Actually scratch the first remark, I have a lot to add.


  • Registered Users Posts: 287 ✭✭Keewee6


    thanks for ur help sure u mean well - ill try and find tutorials


  • Closed Accounts Posts: 18,163 ✭✭✭✭Liam Byrne




Advertisement