Results 1 to 4 of 4
  1. #1
    Join Date
    Jul 2004
    Posts
    494

    Unanswered: problem updating database

    I don't understand where I'm going wrong in this:
    PHP Code:
    for($j=1$j<=18$j++){
        
    $sql "UPDATE boti_pages SET chapter = '".$chapTitles[$j][0]."' WHERE page_num >= '".$chapTitles[0][$j]."' AND page_num < '".$chapTitles[0][$j+1]."'";
    echo 
    $sql."<br />";

    PHP Code:
    $chapTitles[1][0] = "Introduction"
    $chapTitles[0][1] =  "1";

    $chapTitles[2][0] = "chapter 1";
    $chapTitles[0][2] =  "5";

    $chapTitles[3][0] = "chapter 2"
    $chapTitles[0][3] =  "17";

    $chapTitles[4][0] = "chapter 3";
    $chapTitles[0][4] =  "18";

    $chapTitles[5][0] = "chapter 4";
    $chapTitles[0][5] =  "27";

    $chapTitles[6][0] = "chapter 5";
    $chapTitles[0][6] =  "48"
    Echo-ing the SQL I get:
    UPDATE boti_pages SET chapter = 'Introduction' WHERE page_num >= '1' AND page_num < '5'
    UPDATE boti_pages SET chapter = 'chapter 1' WHERE page_num >= '5' AND page_num < '17'
    UPDATE boti_pages SET chapter = 'chapter 2' WHERE page_num >= '17' AND page_num < '18'
    UPDATE boti_pages SET chapter = 'chapter 3' WHERE page_num >= '18' AND page_num < '27'
    UPDATE boti_pages SET chapter = 'chapter 4' WHERE page_num >= '27' AND page_num < '48'
    UPDATE boti_pages SET chapter = 'chapter 5' WHERE page_num >= '48' AND page_num < '62'
    But there is no entry into the database in the chapter field.
    Compare bible texts (and other tools):
    TheWheelofGod

  2. #2
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    Quote Originally Posted by gilgalbiblewhee
    I don't understand where I'm going wrong in this:
    PHP Code:
    for($j=1$j<=18$j++){
        
    $sql "UPDATE boti_pages SET chapter = '".$chapTitles[$j][0]."' WHERE page_num >= '".$chapTitles[0][$j]."' AND page_num < '".$chapTitles[0][$j+1]."'";
    echo 
    $sql."<br />";

    But there is no entry into the database in the chapter field.
    that doesn't look too surprising to me

    where is the code that actually updates the db?
    I can see you are building the SQL, but I can't see any code which actually tells the server to do something with that SQL, nop can I see any error trapping or post server code to check validity

    BTW: I have doubts if this is the right site for you at your present level of expertese, this site doesn't attempt to teach coding & db development from scratch. its here to help design, develop and administer databases and db applications

  3. #3
    Join Date
    Jul 2004
    Posts
    494
    I had forgotten:
    PHP Code:
    mysql_query($sql); 
    in
    PHP Code:
    for ($j=1$j<=18$j++){ 
        
    $sql "UPDATE boti_pages SET chapter = '".$chapTitles[$j][0]."' WHERE page_num >= '".$chapTitles[0][$j]."' AND page_num < '".$chapTitles[0][$j+1]."'"
        echo 
    $sql."<br />";
        
    mysql_query($sql);

    Compare bible texts (and other tools):
    TheWheelofGod

  4. #4
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    so now you are issuing the update command to the server.....
    how do you propose to validate the response from the server, bearing in mind it was not evaluating the response form the server that caused you problems in the previous post?

    what happens if the server cannot find the record to update? do you want o bin that record, or do you want to be informed that the application has failed to do something
    if an update fails (presumably because no record exists what action do you take
    instead do you try to insert a record?

    I presume you are taking adequate precautions against SQL injection by escaping all possible dodgy input using htmlsafe(), mysql_escape_string(), sql_escape_string()....

    as ever the PHP manual is your friend

Posting Permissions

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