Nymphetamine Posted August 23, 2008 Share Posted August 23, 2008 Hey hey! My code: mysql_connect("########", "##########", "########") or die(mysql_error()); mysql_select_db("########") or die(mysql_error()); mysql_query("UPDATE table SET var = '$var' WHERE date = '$date'"); However I need to update many at the same time, I tried doing... mysql_query("UPDATE table SET var = '$var', var2 = '$var2', var3 etc.. That seems to work for a couple but the trouble is I have loads and it just wont have it! >.< Anyone know? Quote Link to comment https://forums.phpfreaks.com/topic/121008-solved-updating-multiple-records/ Share on other sites More sharing options...
Fadion Posted August 23, 2008 Share Posted August 23, 2008 That's the right syntax: UPDATE table SET col1='$var1', col2='$var2', col3='$var3' WHERE date='$date' What's the problem if you have loads of variables? Quote Link to comment https://forums.phpfreaks.com/topic/121008-solved-updating-multiple-records/#findComment-623801 Share on other sites More sharing options...
DeanWhitehouse Posted August 23, 2008 Share Posted August 23, 2008 i dont think he wants to enter var1= $var etc. for each one, he could use a loop but that would take longer, and may even exceed maximum execution time. Quote Link to comment https://forums.phpfreaks.com/topic/121008-solved-updating-multiple-records/#findComment-623802 Share on other sites More sharing options...
Fadion Posted August 23, 2008 Share Posted August 23, 2008 Why would he use a loop and run xx number of queries where he can just run one query? Quote Link to comment https://forums.phpfreaks.com/topic/121008-solved-updating-multiple-records/#findComment-623806 Share on other sites More sharing options...
DeanWhitehouse Posted August 23, 2008 Share Posted August 23, 2008 because i think he doesnt want to enter each var that has to be updated, although that is the best way to do it. Quote Link to comment https://forums.phpfreaks.com/topic/121008-solved-updating-multiple-records/#findComment-623814 Share on other sites More sharing options...
Nymphetamine Posted August 24, 2008 Author Share Posted August 24, 2008 Hey, Sorry for the late reply, was 1am here in Oz when I posted that haha. No updating all the records in that row is fine, its just I have so many that when I put it in one line it simply didnt work! Maybe I've just done something wrong... Quote Link to comment https://forums.phpfreaks.com/topic/121008-solved-updating-multiple-records/#findComment-624020 Share on other sites More sharing options...
DeanWhitehouse Posted August 24, 2008 Share Posted August 24, 2008 show your code please Quote Link to comment https://forums.phpfreaks.com/topic/121008-solved-updating-multiple-records/#findComment-624023 Share on other sites More sharing options...
Nymphetamine Posted August 24, 2008 Author Share Posted August 24, 2008 mysql_query("UPDATE chateau SET booked = '$booked', date = '$date', name = '$name', property = '$property', adults = '$adults', children = '$children', babies = '$babies', address = '$address', daytime = '$daytime', evening = '$evening', mobile = '$mobile', email = '$email', find = '$find', cot = '$cot', chair = '$chair', linen = '$linen', cleaning = '$cleaning', catering = '$catering', other = '$other', cotcost = '$cotcost', chaircost = '$chaircost', linencost = '$linencost', cleaningcost = '$cleaningcost', cateringcost = '$cateringcost', othercost = '$othercost', totalholiday = '$totalholiday', depositagreed = '$depositagreed', firstagreed = '$firstagreed', secondagreed = '$secondagreed', thirdagreed = '$thirdagreed', due = '$due', depositreceived = '$depositreceived', firstreceived = '$firstreceived', secondreceived = '$secondreceived', thirdreceived = '$thirdreceived', duereceived = '$duereceived', totalreceived = '$totalreceived' WHERE date = '$date'"); Quote Link to comment https://forums.phpfreaks.com/topic/121008-solved-updating-multiple-records/#findComment-624027 Share on other sites More sharing options...
DeanWhitehouse Posted August 24, 2008 Share Posted August 24, 2008 mysql_query("UPDATE chateau SET booked = '$booked', date = '$date', name = '$name', property = '$property', adults = '$adults', children = '$children', babies = '$babies', address = '$address', daytime = '$daytime', evening = '$evening', mobile = '$mobile', email = '$email', find = '$find', cot = '$cot', chair = '$chair', linen = '$linen', cleaning = '$cleaning', catering = '$catering', other = '$other', cotcost = '$cotcost', chaircost = '$chaircost', linencost = '$linencost', cleaningcost = '$cleaningcost', cateringcost = '$cateringcost', othercost = '$othercost', totalholiday = '$totalholiday', depositagreed = '$depositagreed', firstagreed = '$firstagreed', secondagreed = '$secondagreed', thirdagreed = '$thirdagreed', due = '$due', depositreceived = '$depositreceived', firstreceived = '$firstreceived', secondreceived = '$secondreceived', thirdreceived = '$thirdreceived', duereceived = '$duereceived', totalreceived = '$totalreceived' WHERE date = '$date'") or die(mysql_error()); try that , i added the die statement Quote Link to comment https://forums.phpfreaks.com/topic/121008-solved-updating-multiple-records/#findComment-624030 Share on other sites More sharing options...
Nymphetamine Posted August 24, 2008 Author Share Posted August 24, 2008 Ahhhh brilliant, Cheers buddy, turns out there was a field I forgot to put in the database! Quote Link to comment https://forums.phpfreaks.com/topic/121008-solved-updating-multiple-records/#findComment-624034 Share on other sites More sharing options...
Fadion Posted August 24, 2008 Share Posted August 24, 2008 Wooha, that's a really big table Quote Link to comment https://forums.phpfreaks.com/topic/121008-solved-updating-multiple-records/#findComment-624038 Share on other sites More sharing options...
DeanWhitehouse Posted August 24, 2008 Share Posted August 24, 2008 Alot to update ,lolz Quote Link to comment https://forums.phpfreaks.com/topic/121008-solved-updating-multiple-records/#findComment-624041 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.