SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Member
    Join Date
    Aug 2000
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi all,
    I'm trying to do a simple update for a 3 cell table. Updating two cells by selecting the 3rd. Could you take a look at the code below and see if you can see why it is not updating?
    I'm getting no errors other than "Couldn't update record!".

    Thanks, Ray

    <?php
    include("required.php");

    // Connect to the database server
    $dbcnx = @mysql_connect("localhost",
    "$user", "$password");
    if (!$dbcnx) {
    echo( "<P>Unable to connect to the " .
    "database server at this time.</P>" );
    exit();
    }

    // Select the hrcomm database
    if (! @mysql_select_db("hrcomm") ) {
    echo( "<P>Unable to locate the hrcomm" .
    "database at this time.</P>" );
    exit();
    }


    $sql = "UPDATE $tablename
    SET introletter = \"$introletter\", disclaimer = \"$disclaimer\"
    WHERE company = \"$company\"
    ";
    if (!$sql_result) {
    echo "<P>Couldn't update record!";
    } else {
    //continue
    }
    ?>


  2. #2
    SitePoint Wizard
    Join Date
    Apr 2000
    Posts
    1,483
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try changing this line:
    echo "<P>Couldn't update record!";

    to this:
    echo mysql_error();

    That should echo out the exact problem.

  3. #3
    ********* Callithumpian silver trophy freakysid's Avatar
    Join Date
    Jun 2000
    Location
    Sydney, Australia
    Posts
    3,798
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by raymundo
    [B
    $sql = &quot;UPDATE $tablename
    SET introletter = \&quot;$introletter\&quot;, disclaimer = \&quot;$disclaimer\&quot;
    WHERE company = \&quot;$company\&quot;
    &quot;;
    [/B]
    Hi, I don't know PHP but in general, when emmbedding SQL into code things get pretty messy because of the speciall ways you usually have to format the string such as the use of escape charater as above. Therefor, it is always a good idea to print out your sql statement for debugging purposes ie; echo($sql). Chances are you've got a syntax error in your SQL string that is not obvious from reading the code but appears obvious once you've printed out the string!

    For example, I suspect you are missing whitespace between$disclaimer and "WHERE" .

  4. #4
    SitePoint Author Kevin Yank's Avatar
    Join Date
    Apr 2000
    Location
    Melbourne, Australia
    Posts
    2,571
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Actually, the main problem is that you never called mysql_query(). How do you expect to get results from the MySQL server if you never send the query?

    Code:
    $sql = "UPDATE $tablename 
    SET introletter = \"$introletter\", disclaimer = \"$disclaimer\" 
    WHERE company = \"$company\" 
    "; 
    $sql_result = mysql_query($sql);
    if (!$sql_result) { 
    echo "<P>Couldn't update record!"; 
    } else { 
    //continue 
    }
    Kevin Yank
    CTO, sitepoint.com
    I wrote: Simply JavaScript | BYO PHP/MySQL | Tech Times | Editize
    Babys got backa hard back, that is: The Ultimate CSS Reference

  5. #5
    SitePoint Member
    Join Date
    Aug 2000
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you! Thank you! As you can tell I'm new. Thank goodness their are people out there willing to help the newbie!

    Again thanks,
    Ray


Bookmarks

Posting Permissions

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