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

    Unanswered: no update made and no table created

    I don't understand why no updating is taking effect and no table is created:
    PHP Code:
    include("../files/constants.php");
    include(
    "../files/dbconnection.php");
    if (!
    $con)
      {
      die(
    'Could not connect: ' mysql_error());
      }

    mysql_select_db($acronym."_book"$con);
    $sql "SELECT * FROM ".$acronym."_pages WHERE content LIKE '%nbsp%'";
    $result mysql_query($sql) OR exit( 'Error: ' mysql_error() );
        
    //echo $sql;
        //to keep record of what changes are made I decided to create a table
        
    $sql_record "CREATE TABLE ".$acronym."_correction_nbsp
        (
        cor_ID int(6) NOT NULL AUTO_INCREMENT,
        PRIMARY KEY(cor_ID),
        content_before longtext,
        content_after longtext
        )"
    ;
        while(
    $row mysql_fetch_array($result)){
            
    $new preg_replace('#&?nbsp;?#i'' '$row['content']);
            if(
    $row['content'] != ""){
            
    $sql_record2 "INSERT INTO correction_nbsp (content_before, content_after)
            VALUES ("
    .$row['content'].", ".$new.")";
            echo 
    $sql_record2."<br />\n";
            }        
            
    $sql2 "UPDATE ".$acronym."_pages SET content = '".$new."' WHERE content = '".$row['content']."'";
            echo 
    $sql2."<br />\n";
        }
    mysql_close($con); 
    If you want to simply view the statements here are a few examples:
    Code:
    INSERT INTO correction_nbsp (content_before, content_after) VALUES ( CHAPTER 1  ,  CHAPTER 1  )
    UPDATE bwas_pages SET content = ' CHAPTER 1  ' WHERE content = ' CHAPTER 1  '
    INSERT INTO correction_nbsp (content_before, content_after) VALUES ( , )
    UPDATE bwas_pages SET content = ' ' WHERE content = ' '
    INSERT INTO correction_nbsp (content_before, content_after) VALUES ( , )
    UPDATE bwas_pages SET content = ' ' WHERE content = ' '
    INSERT INTO correction_nbsp (content_before, content_after) VALUES (chapter: , chapter: )
    UPDATE bwas_pages SET content = 'chapter: ' WHERE content = 'chapter: '
    INSERT INTO correction_nbsp (content_before, content_after) VALUES (copies  &nbspfrom  &nbspauthoritative  &nbspsources  &nbspshowing  &nbspthe , copies from authoritative sources showing the )
    Compare bible texts (and other tools):
    TheWheelofGod

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    the php means nothing to me, so i viewed the first statement

    i suggest you run it outside of php exactly as you have shown it and watch what happens

    the second statement looks like it wants to change something to the same something

    the third statement has a problem with missing values

    and so on

    so it's definitely your php that's messing things up

    i'll move this thread to the php forum for you

    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  3. #3
    Join Date
    Jul 2004
    Posts
    494
    Quote Originally Posted by r937
    the php means nothing to me, so i viewed the first statement

    i suggest you run it outside of php exactly as you have shown it and watch what happens

    the second statement looks like it wants to change something to the same something

    the third statement has a problem with missing values

    and so on

    so it's definitely your php that's messing things up

    i'll move this thread to the php forum for you

    :)
    Yeah I'd figure you'd say that. How do I run outside of php?
    Compare bible texts (and other tools):
    TheWheelofGod

  4. #4
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    Quote Originally Posted by gilgalbiblewhee
    How do I run outside of php?
    - command line
    - mysql query browser
    - phpmyadmin
    - heidisql (the one i use)
    - navicat
    - sqlyog
    - toad for mysql
    - the list just goes on and on
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  5. #5
    Join Date
    Jul 2004
    Posts
    494
    Oh that's right you're the one that introduced me to HeidiSQL.
    That's what I'm using.
    Where do I go from there?
    Compare bible texts (and other tools):
    TheWheelofGod

  6. #6
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    where do you go from there?

    well, after you see the error message, you track it down to what's causing it, then you change your php to generate the correct syntax

    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  7. #7
    Join Date
    May 2008
    Posts
    10
    I use regular mySQL 4 or mySQL 5.. But... when I use php to update, sometimes it could be pretty strict on my syntax. For example, when I go to update a line of SQL with php, I do it like this:

    PHP Code:
    $sql="SELECT * FROM `Table` WHERE `field` = 'value' LIMIT '1' ";
    $insert="INSERT INTO `Table` WHERE `field` = 'value' LIMIT '1' ";
    $update="ALTER TABLE `Table` WHERE `field` = 'value' LIMIT '1' "
    Notice the ``,' ', and " " I use at diferent times to assure the syntax works. This might not be the problem, many databases are different, I just know my 1and1 SQL DB is pretty strict with that stuff.. Mostly the peculiar `` things

    EDIT: :O :O :O! I just found your problem

    Okay, notice my update code. You need to use " ALTER TABLE " instead of " UPDATE " in your code on line: 27.

    See if that works.

Posting Permissions

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