Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6

Thread: modify database

  1. #1
    New to the CF scene
    Join Date
    Apr 2013
    Posts
    9
    Thanks
    1
    Thanked 0 Times in 0 Posts

    modify database

    Hi, all. I have trouble on debug the code.

    there is no error messages show when i run the code.

    i was able insert and delete records, but update and sorting data weren't working.

    Code:
    <?php
    $username="username";
    $password="password";
    $database="DB";
    $connect=mysql_connect("localhost", $username, $password);
    
    if(!$connect){
    echo mysql_error();
    }
    
    $select=mysql_select_db($database);
    $query=mysql_query("SELECT field FROM table ORDER BY field");
    if(!$query){echo mysql_error();}
    mysql_close();
    ?>

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,861
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    Where's your code to update the table?
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #3
    New to the CF scene
    Join Date
    Apr 2013
    Posts
    9
    Thanks
    1
    Thanked 0 Times in 0 Posts
    thanks for the reply.

    I have no idea what happened. it worked when i change the update code like this:

    $query=mysql_query("UPDATE table SET age=20 WHERE name='John'");

    but when i used variable for the age and name values. the error message says the variable value is on the field list.

    $query=mysql_query("UPDATE table SET age=$age WHERE name=$name");

  • #4
    Regular Coder
    Join Date
    Jun 2009
    Posts
    144
    Thanks
    3
    Thanked 20 Times in 20 Posts
    Quote Originally Posted by AlwaysNew View Post
    thanks for the reply.

    I have no idea what happened. it worked when i change the update code like this:

    $query=mysql_query("UPDATE table SET age=20 WHERE name='John'");

    but when i used variable for the age and name values. the error message says the variable value is on the field list.

    $query=mysql_query("UPDATE table SET age=$age WHERE name=$name");
    Try
    PHP Code:
    $query=mysql_query("UPDATE table SET age='$age' WHERE name='$name'"

  • #5
    New to the CF scene
    Join Date
    Apr 2013
    Posts
    9
    Thanks
    1
    Thanked 0 Times in 0 Posts
    thank you it worked.. but im sure i tried that.. i just feel alot of times things dont work at first then work after a while. or my mind was messed..

  • #6
    Regular Coder
    Join Date
    Jun 2009
    Posts
    144
    Thanks
    3
    Thanked 20 Times in 20 Posts
    Quote Originally Posted by AlwaysNew View Post
    thank you it worked.. but im sure i tried that.. i just feel alot of times things dont work at first then work after a while. or my mind was messed..

    Sometimes its best to take a walk around the block and come back to it.. The number of times my coding error becomes glaringly obvious after a walk is remarkable!!


  •  

    Tags for this Thread

    Posting Permissions

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