ballhogjoni Posted December 7, 2007 Share Posted December 7, 2007 Can some one help me figure this out. I have this update query below and it seems to not be working. I have the $id info coming from a XML page. My parser works and my INSERT query works, just not my UPDATE. What I want to do is just run this script when I need to upate certain parts of the rows in the table of my db. <?php $query = mysql_query("SELECT cid FROM cardOffers WHERE cid = ".$id['CID'].""); $doesitexist = mysql_num_rows($query); if ($doesitexist > 0) { mysql_query("UPDATE cardOffers SET creditcard = '".$id['CREDITCARD']."', category = '".$id['CATEGORY']."', issuer = '".$id['ISSUER']."', link = '".$id['LINK']."', picturehtmlcard = '".$id['PICTUREHTMLCARD']."', ba = '".$id['BA']."', bb = '".$id['BB']."', bc = '".$id['BC']."', bd = '".$id['BD']."', be = '".$id['BE']."', bf = '".$id['BF']."', bg = '".$id['BG']."', bh = '".$id['BH']."', cardtype = '".$id['CARDTYPE']."', introductoryrate = '".$id['INTRODUCTORYRATE']."', timeperiod = '".$id['TIMEPERIOD']."', appliedto = '".$id['APPLIEDTO']."', introdetails = '".$id['INTRODETAILS']."', aprpurchnum = '".$id['APRPURCHNUM']."', annual = '".$id['ANNUAL']."', review = '".$id['REVIEW']."', introductoryratealpha = '".$id['INTRODUCTORYRATEALPHA']."' WHERE cid = '".$id['CID']."'"); echo $id['CID'].' was updated<br>'; } else { mysql_query("INSERT INTO cardOffers (cid,creditcard,category,issuer,link,picturehtmlcard,ba,bb,bc,bd,be,bf,bg,bh,cardtype,introductoryrate,timeperiod,appliedto,introdetails,aprpurchnum,annual,review,introductoryratealpha) VALUES ('".$id['CID']."','".$id['CREDITCARD']."','".$id['CATEGORY']."','".$id['ISSUER']."','".$id['LINK']."','".$id['PICTUREHTMLCARD']."','".$id['BA']."','".$id['BB']."','".$id['BC']."','".$id['BD']."','".$id['BE']."','".$id['BF']."','".$id['BG']."','".$id['BH']."','".$id['CARDTYPE']."','".$id['INTRODUCTORYRATE']."','".$id['TIMEPERIOD']."','".$id['APPLIEDTO']."','".$id['INTRODETAILS']."','".$id['APRPURCHNUM']."','".$id['ANNUAL']."','".$id['REVIEW']."','".$id['INTRODUCTORYRATEALPHA']."')"); echo $id['CID'].' <font size="4" color="#FF0000">was new</font><br>'; } ?> Quote Link to comment Share on other sites More sharing options...
Yesideez Posted December 7, 2007 Share Posted December 7, 2007 Try building the query as a string and echo'ing it to the screen to see exactly what your query is - it may be failing for something simple like a mismatched datatype. Something like this: <?php $debug="UPDATE cardOffers SET creditcard = '".$id['CREDITCARD']."', category = '".$id['CATEGORY']."', issuer = '".$id['ISSUER']."', link = '".$id['LINK']."', picturehtmlcard = '".$id['PICTUREHTMLCARD']."', ba = '".$id['BA']."', bb = '".$id['BB']."', bc = '".$id['BC']."', bd = '".$id['BD']."', be = '".$id['BE']."', bf = '".$id['BF']."', bg = '".$id['BG']."', bh = '".$id['BH']."', cardtype = '".$id['CARDTYPE']."', introductoryrate = '".$id['INTRODUCTORYRATE']."', timeperiod = '".$id['TIMEPERIOD']."', appliedto = '".$id['APPLIEDTO']."', introdetails = '".$id['INTRODETAILS']."', aprpurchnum = '".$id['APRPURCHNUM']."', annual = '".$id['ANNUAL']."', review = '".$id['REVIEW']."', introductoryratealpha = '".$id['INTRODUCTORYRATEALPHA']."' WHERE cid = '".$id['CID']."'"; echo $debug; ?> Not sure if that'd work as I just copied and pasted your code but that's the sort of thing. Quote Link to comment Share on other sites More sharing options...
revraz Posted December 7, 2007 Share Posted December 7, 2007 add or die with a mysql error after every query. Quote Link to comment Share on other sites More sharing options...
ballhogjoni Posted December 7, 2007 Author Share Posted December 7, 2007 revraz your right, but I don't know what it was. I jsut added the part that you suggested, Yesideez, to my code underneath the UPDATE query and it seems to be updating everything. Weird! So now the code looks like this, and works every time: <?php if ($doesitexist > 0) { mysql_query("UPDATE cardOffers SET creditcard = '".$id['CREDITCARD']."', category = '".$id['CATEGORY']."', issuer = '".$id['ISSUER']."', link = '".$id['LINK']."', picturehtmlcard = '".$id['PICTUREHTMLCARD']."', ba = '".$id['BA']."', bb = '".$id['BB']."', bc = '".$id['BC']."', bd = '".$id['BD']."', be = '".$id['BE']."', bf = '".$id['BF']."', bg = '".$id['BG']."', bh = '".$id['BH']."', cardtype = '".$id['CARDTYPE']."', introductoryrate = '".$id['INTRODUCTORYRATE']."', timeperiod = '".$id['TIMEPERIOD']."', appliedto = '".$id['APPLIEDTO']."', introdetails = '".$id['INTRODETAILS']."', aprpurchnum = '".$id['APRPURCHNUM']."', annual = '".$id['ANNUAL']."', review = '".$id['REVIEW']."', introductoryratealpha = '".$id['INTRODUCTORYRATEALPHA']."' WHERE cid = '".$id['CID']."'"); echo $id['CID'].' was updated<br>'; $debug="UPDATE cardOffers SET creditcard = '".$id['CREDITCARD']."', category = '".$id['CATEGORY']."', issuer = '".$id['ISSUER']."', link = '".$id['LINK']."', picturehtmlcard = '".$id['PICTUREHTMLCARD']."', ba = '".$id['BA']."', bb = '".$id['BB']."', bc = '".$id['BC']."', bd = '".$id['BD']."', be = '".$id['BE']."', bf = '".$id['BF']."', bg = '".$id['BG']."', bh = '".$id['BH']."', cardtype = '".$id['CARDTYPE']."', introductoryrate = '".$id['INTRODUCTORYRATE']."', timeperiod = '".$id['TIMEPERIOD']."', appliedto = '".$id['APPLIEDTO']."', introdetails = '".$id['INTRODETAILS']."', aprpurchnum = '".$id['APRPURCHNUM']."', annual = '".$id['ANNUAL']."', review = '".$id['REVIEW']."', introductoryratealpha = '".$id['INTRODUCTORYRATEALPHA']."' WHERE cid = '".$id['CID']."'"; echo $debug.'<br>'; } else { mysql_query("INSERT INTO cardOffers (cid,creditcard,category,issuer,link,picturehtmlcard,ba,bb,bc,bd,be,bf,bg,bh,cardtype,introductoryrate,timeperiod,appliedto,introdetails,aprpurchnum,annual,review,introductoryratealpha) VALUES ('".$id['CID']."','".$id['CREDITCARD']."','".$id['CATEGORY']."','".$id['ISSUER']."','".$id['LINK']."','".$id['PICTUREHTMLCARD']."','".$id['BA']."','".$id['BB']."','".$id['BC']."','".$id['BD']."','".$id['BE']."','".$id['BF']."','".$id['BG']."','".$id['BH']."','".$id['CARDTYPE']."','".$id['INTRODUCTORYRATE']."','".$id['TIMEPERIOD']."','".$id['APPLIEDTO']."','".$id['INTRODETAILS']."','".$id['APRPURCHNUM']."','".$id['ANNUAL']."','".$id['REVIEW']."','".$id['INTRODUCTORYRATEALPHA']."')"); echo $id['CID'].' <font size="4" color="#FF0000">was new</font><br>'; } ?> Quote Link to comment Share on other sites More sharing options...
Yesideez Posted December 7, 2007 Share Posted December 7, 2007 Using die() is OK when writing the script but you should really be using the proper error handling routines. Otherwise people will be using your site and when it experiences problems - it stops working - not good. At least using error handling routines you can give the user a message and giving them an option to carry on with the site somewhere else. Plus it gives you an opportunity to send yourself an email containing the data the user entered and a copy of the query that failed. That way you know your script is failing and what could be causing it. Quote Link to comment Share on other sites More sharing options...
ballhogjoni Posted December 8, 2007 Author Share Posted December 8, 2007 Good thing no one sees this page. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.