473,382 Members | 1,445 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

PHP Update statement

AaronL
99
Hello, I ran into a problem with my PHP code, my code works for adding a new record to the database, but for editing a record it doesn't work, and the MySql statement looks fine to me but the UPDATE doesn't seem to work on the record for some reason.

Expand|Select|Wrap|Line Numbers
  1. if($itemno == 0)
  2. {
  3.   $buildsql = "INSERT INTO products (title, catid, list, price, taxable, shipping, intshipping, calculator, description) ";
  4.   $buildsql = $buildsql . "VALUES ('" . $title . "', '" . $catid . "', '" . $list . "', '" . $price . "', '" . $taxable . "', '" . $shipping . "', '" . $intshipping . "', '" . $calculator . "', '" . $description . "')";
  5.   mysql_query($buildsql);
  6.   $itemno = mysql_insert_id($con);
  7.   echo "<table border='1' width='400' align='center'><tr><td bgcolor='#C0C0C0' align='center'><b>Item Added</b></td></tr>
  8. <tr><td><b>Added item number: </b>" . $itemno . "<br><br><form action='imgupload.php' method='get'><b>
  9. <input type='hidden' value=" . $itemno . " name='itemno' /><p align='right'><input type='submit' value='Upload Images'>
  10. </p></td></tr>";
  11. }
  12. else
  13. //Edit item
  14. {
  15. $buildsql = "UPDATE products SET title='" . $title . 
  16. "' catid='" . $catid . "' list='" . $list . 
  17. "' price='" . $price . "' taxable='" . $taxable . 
  18. "' shipping='" . $shipping . "' intshipping='" . $intshipping . 
  19. "' calculator='" . $calculator . "' description='" . $description . 
  20. "' WHERE itemno='" . $itemno . "'";
  21.   echo "<b>" . $buildsql . "</b>";
  22.   mysql_query($buildsql);
  23. }
  24.  
What am I doing wrong? Thanks again for your help!
May 17 '09 #1
3 3168
prabirchoudhury
162 100+
ok.. you have a wrong Udate query expression .. should be "," after every field want to update..

Expand|Select|Wrap|Line Numbers
  1.  
  2. this code should wrk to you 
  3.  
  4. $sql  = "UPDATE products SET title = '".$title."', catid = '".$catid."', list = '".$list."', ";
  5.  $sql .=   "price = '".$price."', taxable = '".$taxable."', ";
  6.  $sql .=   "shipping = '".$shipping."', ";
  7.  $sql .=   "intshipping = '".$intshipping."', calculator = '".$calculator."', description = '".$description."'  ";            
  8.  $sql .= "WHERE itemno = '".$itemno."' ";
  9.  
  10.   mysql_query($sql)or die("cant execute: $sql");
  11.  
  12.  
May 17 '09 #2
AaronL
99
You're a life saver, thanks!
May 17 '09 #3
prabirchoudhury
162 100+
you are more then welcome ...
May 18 '09 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Mark A Framness | last post by:
Greetings, I am working on a project and we need to write a conversion script to initialize a new field on a table. The number of records on this table is on the order of millions so routine...
7
by: Dave | last post by:
I have 2 tables, one with names, and another with addresses, joined by their CIVICID number (unique to the ADDRESSINFO table) in Oracle. I need to update a field in the NAMEINFO table for a...
8
by: Lauren Quantrell | last post by:
In VBA, I constructed the following to update all records in tblmyTable with each records in tblmyTableTEMP having the same UniqueID: UPDATE tblMyTable RIGHT JOIN tblMyTableTEMP ON...
8
by: pb648174 | last post by:
I have a single update statement that updates the same column multiple times in the same update statement. Basically i have a column that looks like .1.2.3.4. which are id references that need to...
2
by: Mike Leahy | last post by:
Hello all, This question is related to updating tables - is there any way to calculate or update the values in a column in a table to the values in a field produced by a query result? An...
1
by: amitbadgi | last post by:
HI i am getting the foll error while conv an asp application to asp.net Exception Details: System.Runtime.InteropServices.COMException: Syntax error in UPDATE statement. Source Error: Line...
1
by: Grant McLean | last post by:
Hi First a simple question ... I have a table "access_log" that has foreign keys "app_id" and "app_user_id" that reference the "application_type" and "app_user" tables. When I insert into...
6
by: FayeC | last post by:
I really need help figuring this out. i have a db with mostly text fields but 2. The user_id field is an autonumber (key) and the user_newsletter is a number (1 and 0) field meaning 1 yes the ...
19
by: Steve | last post by:
ASP error number 13 - Type mismatch with SELECT...FOR UPDATE statement I got ASP error number 13 when I use the SELECT...FOR UPDATE statement as below. However, if I use SELECT statement without...
3
by: Michel Esber | last post by:
Hi all, DB2 V8 LUW FP 15 There is a table T (ID varchar (24), ABC timestamp). ID is PK. Our application needs to frequently update T with a new value for ABC. update T set ABC=? where ID...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.