SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Wizard bronze trophy
    Join Date
    Apr 2003
    Posts
    4,095
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Unhappy MySQL delete problems

    Dear everyone,

    I've been trying to write a PHP script that deletes rows from a database, and this is the MySQL query:

    Code:
    $query=("delete from journal where id=\"$id\"");
    When the code is executed, however, I get an error. Does the code look valid? Thanks for your help.

    Compuwhiz7

  2. #2
    SitePoint Wizard
    Join Date
    Mar 2002
    Location
    Bristol, UK
    Posts
    2,240
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You don't need to use brackets with variables. There also might be a problem with the quotes. Try the following:

    PHP Code:
    $query "DELETE FROM journal WHERE id = '$id'"
    Hope this helps

    -Sam
    Sam Hastings

  3. #3
    SitePoint Wizard bronze trophy
    Join Date
    Apr 2003
    Posts
    4,095
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Dear everyone,

    I've tried Devilware.net's suggestions, and nothing works. The MySQL error I've been getting is "no database selected". I am using the "mysql_select_db" function, though.

    Compuwhiz7

  4. #4
    SitePoint Wizard
    Join Date
    Mar 2002
    Location
    Bristol, UK
    Posts
    2,240
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Perhaps you could post your code in here, so we can get a better picture of what you're trying to do?

    Thanks.

    -Sam
    Sam Hastings

  5. #5
    SitePoint Wizard bronze trophy
    Join Date
    Apr 2003
    Posts
    4,095
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Dear everyone,

    The code is as follows.

    Code:
    $id=$_REQUEST["id"];
    $server=mysql_connect("localhost","cybercory_root");
    $db=mysql_select_db("cybercor_journal");
    $query="delete from journal where id=\"$id\"";
    $status=mysql_query($query);
    Thanks for your help.

    Compuwhiz7

  6. #6
    SitePoint Wizard
    Join Date
    Mar 2002
    Location
    Bristol, UK
    Posts
    2,240
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try changing the mysql_select_db line as follows:

    PHP Code:
    $db=mysql_select_db("cybercor_journal"$server); 
    -Sam
    Sam Hastings

  7. #7
    SitePoint Wizard bronze trophy
    Join Date
    Apr 2003
    Posts
    4,095
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Dear everyone,

    I've tried to modify the "select_db" line, and the problem has persisted. Incidentally, their are other sections of the page connecting to the same database without a hitch.

    Compuwhiz7

  8. #8
    SitePoint Enthusiast
    Join Date
    May 2003
    Location
    Serbia
    Posts
    53
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Let's see the code for other sections on a page
    Wondering about best weight loss pill? Take a look at Proactol.

  9. #9
    SitePoint Wizard bronze trophy
    Join Date
    Apr 2003
    Posts
    4,095
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Dear everyone,

    The following block of code connects to another database on the same server.

    Code:
    $username=$_REQUEST["username"];
    $password=$_REQUEST["password"];
    $server=mysql_connect("localhost","cybercor_root");
    $db=mysql_select_db("cybercor_ids");
    $query="select * from ids";
    $ids=mysql_query($query);
    This block of code connects to the same database as my original post.

    Code:
    $server=mysql_connect("localhost","cybercor_root");
    $db=mysql_select_db("cybercor_journal");
    $query="
    insert into journal set
    date_and_time=\"$date_and_time\",
    text=\"$text\"
    ";
    $status=mysql_query($query);
    Thanks for your help.

    Compuwhiz7


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
  •