SitePoint Sponsor

User Tag List

Page 2 of 2 FirstFirst 12
Results 26 to 48 of 48
  1. #26
    And your point is.... redgoals's Avatar
    Join Date
    Feb 2002
    Location
    Birmingham, UK
    Posts
    496
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok i was trying to edit a record:

    and got this:

    UPDATE tones SET name='Walk on By U2', tone='4*, 2#, 1#, 4, 2#, 1#, 5#, (4), 28#, 19#, 18**#, 0, 1#, 0, 1#, 0, 599*#, 4, 28#, (1)9#, 18#, 2#, 49, 18#, 29#, 48, 19#, 28#, 4, 2#, 1#, 2#, 4, 1#, 59# edit damnit!!', tempo='225', cat='new' WHERE id=You have an error in your SQL syntax near '' at line 1

    obviously the "edit damnit!!" was entered into the form to see if it is added.

    the record is not updated
    http://redgoals.com ... my site ... nuff said

  2. #27
    SitePoint Wizard
    Join Date
    Jul 1999
    Location
    Chicago
    Posts
    2,629
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Everything looks OK until the end, "id=." $id is undefined. It must not be being passed through the URL or something. It's definitely what's causing your syntax error, though.

  3. #28
    And your point is.... redgoals's Avatar
    Join Date
    Feb 2002
    Location
    Birmingham, UK
    Posts
    496
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    the id is being passed through the url string (gh.php?id=54). ive lost count how many times ive checked the code, cant find an error.

    heres the table structure if it helps in any way.


    PHP Code:

    +-------+--------------+------+-----+---------+----------------+
    Field Type         Null Key | Default | Extra          |
    +-------+--------------+------+-----+---------+----------------+
    cat   varchar(20)  |      |     |         |                |
    id    int(20)      |      | PRI NULL    auto_increment |
    name  varchar(100) |      |     |         |                |
    tempo int(3)       |      |     | 0       |                |
    tone  varchar(150) |      |     |         |                |
    +-------+--------------+------+-----+---------+----------------+ 

    "id=." $id

    has changed to

    id=$id"
    Last edited by redgoals; Mar 5, 2002 at 16:31.
    http://redgoals.com ... my site ... nuff said

  4. #29
    SitePoint Wizard
    Join Date
    Jul 1999
    Location
    Chicago
    Posts
    2,629
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try $HTTP_GET_VARS['id'] instead of $id.

  5. #30
    And your point is.... redgoals's Avatar
    Join Date
    Feb 2002
    Location
    Birmingham, UK
    Posts
    496
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING' in /home/sites/site143/web/file.php on line 19

    is this what you meant:

    PHP Code:
    mysql_query"UPDATE tones SET name='$name', tone='$tone', tempo='$tempo', cat='$cat
    WHERE id=
    $HTTP_GET_VARS['id']" ) or die( mysql_error() ); 
    http://redgoals.com ... my site ... nuff said

  6. #31
    SitePoint Wizard
    Join Date
    Jul 1999
    Location
    Chicago
    Posts
    2,629
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    To tell the truth, I haven't written PHP in a while, but I'm fairly sure that you have to access $HTTP_GET_VARS['id'] like this:


    mysql_query( "UPDATE tones SET name='$name', tone='$tone', tempo='$tempo', cat='$cat'
    WHERE id=". $HTTP_GET_VARS['id'] ) or die( mysql_error() );

  7. #32
    And your point is.... redgoals's Avatar
    Join Date
    Feb 2002
    Location
    Birmingham, UK
    Posts
    496
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok i put some carriage returns before the "WHERE" clause in the UPDATE query and the error line changes to the line the "WHERE" clause is on.
    Last edited by redgoals; Mar 5, 2002 at 17:03.
    http://redgoals.com ... my site ... nuff said

  8. #33
    SitePoint Wizard
    Join Date
    Jul 1999
    Location
    Chicago
    Posts
    2,629
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Was this before or after you got my previous post? So confusing, these message boards!

    Can you just post your entire code?

  9. #34
    And your point is.... redgoals's Avatar
    Join Date
    Feb 2002
    Location
    Birmingham, UK
    Posts
    496
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:

    <?
    mysql_pconnect
    ("localhost","user","pass");
    mysql_select_db("xxx");
    ?>
    <HTML>
    <HEAD>
    <TITLE>Untitled Document</TITLE>
    <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
    </HEAD>

    <BODY BGCOLOR="#FFFFFF" TEXT="#000000">
    <? 
        
    if( $HTTP_POST_VARS["submit"] ) {
        
    $name trim$HTTP_POST_VARS["name"] );
        
    $tone trim$HTTP_POST_VARS["tone"] );
        
    $tempo trim$HTTP_POST_VARS["tempo"] );
        
    $cat trim$HTTP_POST_VARS["cat"] );
        
    $tone addslashes($tone);
        
    mysql_query"UPDATE tones SET name='$name', tone='$tone', tempo='$tempo', cat='$cat



    //carriage returns
    //error in where clause

        WHERE id="
    $HTTP_GET_VARS['id'] ) or die( mysql_error() );
        } 
    ?> 

    <? 
        $result 
    mysql_query"SELECT * FROM tones WHERE id=$id) or die( mysql_error() );
        
    $myrow mysql_fetch_array$result ) or die( mysql_error() );
        
    $name $myrow["name"];
        
    $tone $myrow["tone"]; 
        
    $tempo $myrow["tempo"]; 
        
    $cat $myrow["cat"]; 
    ?>

    <form method="post" action="<? {echo "$PHP_SELF";} ?>">

    <TABLE WIDTH="100%" BORDER="0" CELLSPACING="0" CELLPADDING="0">

    <TR> 
    <TD WIDTH="6%">cat</TD>

    <TD WIDTH="94%"> 

    <SELECT NAME='cat'>
    <OPTION VALUE="<? print( $cat ); ?>" SELECTED> 
    <? print( $cat ); ?>
    </OPTION>
    <OPTION VALUE='new'>new 
    </SELECT>

    </TD>

    </TR>

    <TR> 
    <TD WIDTH="6%">tempo</TD>
    <TD WIDTH="94%"> 
    <SELECT NAME='tempo'>
    <OPTION VALUE="<? print( $tempo ); ?>" SELECTED> 
    <? print( $tempo ); ?>
    </OPTION>
    <OPTION VALUE='140'>140 
    </SELECT>

    </TD>

    </TR>

    <TR> 

    <TD WIDTH="6%"> title:</TD>

    <TD WIDTH="94%">

    <INPUT TYPE="Text" NAME="name" VALUE="<? print( $name ); ?>">

    </TD>

    </TR>
    <TR>

    <TD WIDTH="6%">article:</TD>
    <TD WIDTH="94%">

    <TEXTAREA NAME='tone' ROWS="20" COLS="50"><? print( $tone ); ?></TEXTAREA>

    </TD>
    </TR>
    </TABLE>

    <input type="Submit" name="submit" value="Enter information">

    </form> 

    </BODY>
    </HTML>
    http://redgoals.com ... my site ... nuff said

  10. #35
    SitePoint Wizard
    Join Date
    Jul 1999
    Location
    Chicago
    Posts
    2,629
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    OK, hmm. Now try echoing the query.

    If anyone else sees what's wrong, feel free to jump in!

  11. #36
    And your point is.... redgoals's Avatar
    Join Date
    Feb 2002
    Location
    Birmingham, UK
    Posts
    496
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    UPDATE tones SET name='Beautiful Day by U2', tone='58** 5 48 59 (4) 58 4 2# (4)99 6#8** 5#8* 59 5 4 499 5888** 49 (4)9 6#88** 6# 5#9 * 558 5 (5)9 48 49 58 49 (4)9 6#88** 6# 5 #9* 58 2# 5 2# (5) (4) come on please update!!', tempo='70', cat='abc' WHERE id=You have an error in your SQL syntax near '' at line 1

    record not updated.
    http://redgoals.com ... my site ... nuff said

  12. #37
    SitePoint Enthusiast
    Join Date
    Mar 2002
    Location
    Windsor, Ontario, Canada
    Posts
    32
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    could it be that you forgot to close the query statement with "


    WHERE id=". $HTTP_GET_VARS['id'] ) or die( mysql_error() );

    shouldn't it be

    WHERE id=". $HTTP_GET_VARS['id']") or die( mysql_error() );

    notice the '"' after [id]"

    Just a thought
    But I'm learning as fast as I can!!!

  13. #38
    SitePoint Wizard
    Join Date
    Jul 1999
    Location
    Chicago
    Posts
    2,629
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No, because we got out of the quotes after id= so we can use the . concatenating operator.

    redgoals - try setting $HTTP_GET_VARS['id'] to some random number. It's definitely the "id=" ending that's causing the error. No doubt about it. Now we just need to figure out why the ID isn't getting there. It should, as long as you are accessing the page like file.php?id=1.
    Last edited by qslack; Mar 5, 2002 at 18:03.

  14. #39
    And your point is.... redgoals's Avatar
    Join Date
    Feb 2002
    Location
    Birmingham, UK
    Posts
    496
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok now where getting somewhere, i entered the same random number in both queries and it updates !!!.

    now why doesnt it accept url string.

    heres what i get after the record is updated



    UPDATE tones SET name='Fallin by Alicia Keys', tone='18, 1, 2, 3, 59, 3, 78, 6, (7)9, 08, 28, (3)9, 08, 38, (5)9, 28, 39, 48#, 59, 3, 78, 6, 79, 5, 08, 28, (3)9, 08, 38, (5)9 update god damnit!!', tempo='90', cat='new' WHERE id=43
    http://redgoals.com ... my site ... nuff said

  15. #40
    SitePoint Enthusiast
    Join Date
    Mar 2002
    Location
    Windsor, Ontario, Canada
    Posts
    32
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    oops

    ooops I see your point oh wise one.
    But I'm learning as fast as I can!!!

  16. #41
    SitePoint Wizard
    Join Date
    Jul 1999
    Location
    Chicago
    Posts
    2,629
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    pcpresents - thanks, but I'm hardly a wise one. If you want to see real live wise ones, just hang around these forums a bit and they'll come.

    redgoals - can you give me an example of how you are accessing this script? Can I have a URL? Also, try $_GET['id'] instead of $HTTP_GET_VARS['id'] if you are using PHP >= v4.1.

  17. #42
    And your point is.... redgoals's Avatar
    Join Date
    Feb 2002
    Location
    Birmingham, UK
    Posts
    496
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok here is a record you can edit

    link
    Last edited by redgoals; Mar 5, 2002 at 18:25.
    http://redgoals.com ... my site ... nuff said

  18. #43
    And your point is.... redgoals's Avatar
    Join Date
    Feb 2002
    Location
    Birmingham, UK
    Posts
    496
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok fixed it, just echoed out the id in the select query, and addd a hidden form field at the bottom.

    PHP Code:
    <?
    mysql_pconnect
    ("localhost","user","pass");
    mysql_select_db("xxx");
    ?>
    <HTML>
    <HEAD>
    <TITLE>Untitled Document</TITLE>
    <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
    </HEAD>

    <BODY BGCOLOR="#FFFFFF" TEXT="#000000">
    <? 
            
    if($submit)  {
            
    $name trim$HTTP_POST_VARS["name"] );
            
    $tone trim$HTTP_POST_VARS["tone"] );
            
    $tempo trim$HTTP_POST_VARS["tempo"] );
            
    $cat trim$HTTP_POST_VARS["cat"] );
            
    $tone addslashes($tone);
    $query "UPDATE tones SET name='$name', tone='$tone', tempo='$tempo', cat='$cat' WHERE id='$ids'";

    echo 
    $query;
    mysql_query$query ) or die( mysql_error() );
        } 
        
    else {
    ?> 

    <? 
        $result 
    mysql_query"SELECT * FROM tones WHERE id=$id) or die( mysql_error() );
        
    $myrow mysql_fetch_array$result ) or die( mysql_error() );
        
    $name $myrow["name"];
        
    $tone $myrow["tone"]; 
        
    $tempo $myrow["tempo"]; 
        
    $cat $myrow["cat"];
        
    $ids $myrow["id"]; 
    ?>


    <form method="post" action="<? {echo "$PHP_SELF";} ?>">

    <TABLE WIDTH="100%" BORDER="0" CELLSPACING="0" CELLPADDING="0">

    <TR> 
    <TD WIDTH="6%">cat</TD>

    <TD WIDTH="94%"> 

    <SELECT NAME='cat'>
    <OPTION VALUE="<? print( $cat ); ?>" SELECTED> 
    <? print( $cat ); ?>
    </OPTION>
    <OPTION VALUE='new'>new 
    </SELECT>

    </TD>

    </TR>

    <TR> 
    <TD WIDTH="6%">tempo</TD>
    <TD WIDTH="94%"> 
    <SELECT NAME='tempo'>
    <OPTION VALUE="<? print( $tempo ); ?>" SELECTED> 
    <? print( $tempo ); ?>
    </OPTION>
    <OPTION VALUE='140'>140 
    </SELECT>

    </TD>

    </TR>

    <TR> 

    <TD WIDTH="6%"> title:</TD>

    <TD WIDTH="94%">

    <INPUT TYPE="Text" NAME="name" VALUE="<? print( $name ); ?>">

    </TD>

    </TR>
    <TR>

    <TD WIDTH="6%">article:</TD>
    <TD WIDTH="94%">

    <TEXTAREA NAME='tone' ROWS="20" COLS="50"><? print( $tone ); ?></TEXTAREA>

    </TD>
    </TR>
    </TABLE>

    <input type="Submit" name="submit" value="Enter information">

    <INPUT TYPE="hidden" NAME="ids" VALUE="<? print( $ids ); ?>">

    </form> 

    </BODY>
    </HTML>

    id like to thankyou qslack, coludnt have done without ya. cheers mate.
    Last edited by redgoals; Mar 5, 2002 at 18:24.
    http://redgoals.com ... my site ... nuff said

  19. #44
    SitePoint Enthusiast
    Join Date
    Mar 2002
    Location
    Windsor, Ontario, Canada
    Posts
    32
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Just a question

    Not trying to be a bother but I was curious.

    When I do an update statement I get to the where clause I always end it like this.

    Where username='$username'");

    The way your doing in your first code is that a shortcut?
    But I'm learning as fast as I can!!!

  20. #45
    And your point is.... redgoals's Avatar
    Join Date
    Feb 2002
    Location
    Birmingham, UK
    Posts
    496
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i was having a problem getting the id when updating a record so i had to take the long way round, but i use your way normally.
    http://redgoals.com ... my site ... nuff said

  21. #46
    SitePoint Enthusiast
    Join Date
    Mar 2002
    Location
    Windsor, Ontario, Canada
    Posts
    32
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    thankyou

    I actually thought about the hidden field also cause that is how I pass all information in the query string when you use PHP_SELF or the variable will show up empty.

    Been there done that!

    Nice to know i am finally learning something!

    Congrats on getting it to work and thanks for letting me prod around.
    But I'm learning as fast as I can!!!

  22. #47
    SitePoint Wizard
    Join Date
    Jul 1999
    Location
    Chicago
    Posts
    2,629
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey, glad you got it to work. No problem, sorry it took so long!

    Sometimes the challenge of finding bugs is fun, but I wish they'd just stop being lazy and write informative error messages, like "you need to add a hidden form field."

  23. #48
    SitePoint Enthusiast jsegura's Avatar
    Join Date
    Feb 2002
    Location
    Barcelona (Catalonia-Spain)
    Posts
    36
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    hope this helps

    you said $id comes with the url. Maybe you forget to declare it as global $id so it's lost?.

    regards,
    Juan.


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
  •