Results 1 to 2 of 2

Thread: Sql Help

  1. #1

    Thread Starter
    Member
    Join Date
    May 2006
    Posts
    39

    Sql Help

    Hi All,

    if ($updatecode == 3 ){
    mysql_query("UPDATE tblcollection SET status = 3 WHERE barcode = '$barcode'");
    }
    else{
    $rec=mysql_query("select * from tblcollection where barcode='".$barcode."'");
    if($row=mysql_fetch_array($rec)){
    //update
    mysql_query("UPDATE tblcollection SET ( barcode = '$barcode', Title = '$title', Genre = '$genre',Boxsize = '$boxset' ) WHERE '$rec'");
    }
    else{
    //insert
    mysql_query("INSERT INTO tblcollection (barcode,Title,Genre,Boxsize) VALUES ('$barcode','$title','$genre','$boxset')");
    }
    }

    I don't know how take id from $rec in
    mysql_query("UPDATE tblcollection SET ( barcode = '$barcode', Title = '$title', Genre = '$genre',Boxsize = '$boxset' ) WHERE '$rec'");

    Ramesh

  2. #2
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Sql Help

    Please use the [php]code here[/php] tags to post PHP code.

    Use the index operator to access fields returned in a dataset. Use mysql_fetch_assoc() if you want to access them by field name.

    PHP Code:
    $rec mysql_query("select * from tblcollection where barcode='".$barcode."'");
    if (
    $row mysql_fetch_assoc($rec)) {
      
    //update
      
    mysql_query(
        
    "UPDATE tblcollection SET (".
        
    "barcode = '$barcode', Title = '$title', Genre = '$genre', Boxsize = '$boxset' )".
        
    "WHERE id = {$row['id']}"
      
    ); 
    Assuming a field name of id.

Posting Permissions

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



Click Here to Expand Forum to Full Width