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 3 of 3
  1. #1
    New Coder
    Join Date
    Dec 2009
    Posts
    40
    Thanks
    4
    Thanked 0 Times in 0 Posts

    PHP + MySQL INSERT Problem

    I have a Bookmark Service that using a SQL table. Every time you try to add a second bookmark it deletes (literally) the row. Here's the script for adding:

    PHP Code:
    <?php
    $name 
    $_POST['name'];
    $url $_POST['url'];
    $desc $_POST['desc'];
    $uid $_POST['uid'];
    $con mysql_connect('localhost','pippin','**********');
    if (!
    $con)
      {
      die(
    'Could not connect: ' mysql_error());
      }
    $db mysql_select_db('pippin_bookmarks');
        if(!
    $db) {
            die(
    "Unable to select database");
        }
    $qry mysql_query(
        
    "INSERT 
        INTO 
        bookmarks(`uid`, `address`, `title`, `description`) VALUES('$uid','$url','$name','$desc')"
    )or die(mysql_error());
        
    //Check whether the query was successful or not
        
    if($qry == true
        {
            
    header("location: ub-index.php");
            exit();
        } 
        else 
            die(
    "Query failed");
    mysql_close($con);
    ?>
    If you need any other info/data I'll be glad to post it.

  • #2
    Senior Coder
    Join Date
    May 2005
    Posts
    2,137
    Thanks
    96
    Thanked 72 Times in 72 Posts
    My guess would be your id isn't an auto increment, meaning it can't insert a new value.
    Rowsdower! has accused me of having mental problems, and the administrator allowed it. What a great forum huh?

  • #3
    New Coder
    Join Date
    Dec 2009
    Posts
    40
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Well I have an ID (Which is. Actually all of them are ID (Auto increment), UID (to identify the user), Title, Address, Description) but it's not in there.

    It uses this to view them:
    PHP Code:
    <?php
    $id 
    $_SESSION['SESS_MEMBER_ID'];

    $con mysql_connect('localhost','pippin','********');
    if (!
    $con)
      {
      die(
    'Could not connect: ' mysql_error());
      }
    $db mysql_select_db('pippin_bookmarks');
        if(!
    $db) {
            die(
    "Unable to select database");
        }

            
    $qry "SELECT * FROM bookmarks WHERE uid='$id'";
            
    $result mysql_query($qry);
            if(
    $result) {
                if(
    mysql_num_rows($result) == 0) {
    echo 
    "<b>No bookmarks. Please add some.</b>";
                } else {
                while (
    $row mysql_fetch_object($result))
      {
      echo 
    "<b>" $row->title "</b><br />";
      echo 
    $row->description "<br />";
      echo 
    "<a href='" $row->address "'>" $row->address "</a><br />";
      echo 
    "<form method='post' action='delete.php'><input name='idd' type='hidden' value='" $row->id "'><a href='#' onclick='parentNode.submit()'>Delete</a><br><br>";
      }
                }
                }
    ?>
    Last edited by pippin418; 01-23-2010 at 05:08 AM.


  •  

    Posting Permissions

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