|
-
Aug 25th, 2006, 06:17 AM
#1
Thread Starter
Member
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
-
Aug 25th, 2006, 06:22 AM
#2
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|