mrt003003 Posted April 21, 2011 Share Posted April 21, 2011 Hi there, Im fairly new at php and mysql but nevertheless im trying to build a web based campaign game for starwars minatures boardgame. Its fairly straightforward and going well.. However ive been thinking about how it will work and have stumbled across a possible problem (because of my limited craft at programming). I want to have a single form that updates all records in the tables, this would simulate an "end of turn" button. Im sure i can do this if doing stuff in the game (e.g. move, create , modify, delete, fleets/ships and auto increment ships hulls simulating repair) if it was done on the same page. However i wanted to to initiate some of these adjustments in their respective pages (fleet.php, planets.php, ships.php etc) and then once the user is happy to click the end turn button somewhere which would update all of these things at the same time.. Is this possible at all??? If anybody could help that would be brilliant. Thank you p.s. if anybody wants a copy of the finished product when its complete, your most welcome. Quote Link to comment https://forums.phpfreaks.com/topic/234336-update-multiple-records-in-one-form/ Share on other sites More sharing options...
JKG Posted April 21, 2011 Share Posted April 21, 2011 i advise just stacking the mysql_query's, eg: $sql = mysql_query(""); $sql2 = mysql_query(""); or just mysql_query(""); mysql_query(""); Quote Link to comment https://forums.phpfreaks.com/topic/234336-update-multiple-records-in-one-form/#findComment-1204435 Share on other sites More sharing options...
mrt003003 Posted April 21, 2011 Author Share Posted April 21, 2011 thanks for the reply. Im not quite sure i understand the concept. Would each page have its own form where the data is parsed to an update page? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/234336-update-multiple-records-in-one-form/#findComment-1204439 Share on other sites More sharing options...
JKG Posted April 21, 2011 Share Posted April 21, 2011 <?php if (!isset($_POST['submit'])) { ?> form <?php } else { echo "<p>Updating your records...</p>"; mysql_query("UPDATE feedback SET comment = '".mysql_real_escape_string($_POST['comment'])."', contact = '".mysql_real_escape_string($_POST['contact'])."', name = '".mysql_real_escape_string($_POST['name'])."', ip = '".mysql_real_escape_string($_POST['ip'])."' WHERE id = '".mysql_real_escape_string($_POST['id'])."'") or die("SQL Error: " . mysql_error()); echo '<h2>Your comment has been added</h2>'; mysql_query("UPDATE anotherTable SET column = '".mysql_real_escape_string($_POST['columndata'])."', ip = '".mysql_real_escape_string($_POST['ip'])."' WHERE id = '".mysql_real_escape_string($_POST['id'])."'") or die("SQL Error: " . mysql_error()); } echo '<h2>more data has been added.</h2>'; ?> let me know if i have missed the question. Quote Link to comment https://forums.phpfreaks.com/topic/234336-update-multiple-records-in-one-form/#findComment-1204444 Share on other sites More sharing options...
mrt003003 Posted April 21, 2011 Author Share Posted April 21, 2011 Hi JKG is see what you mean here. I was hoping it would work so that when a user edited anything to do fleets they would do it in the fleet page, ships in the ship page and so on. I can only visualise that being done indivually with a form and update on each page. So how would the data be parsed from each of the fleet, ships etc pages to the updateform that updates them all at the same time. Sorry I probably sound really stupid :| Thanks Quote Link to comment https://forums.phpfreaks.com/topic/234336-update-multiple-records-in-one-form/#findComment-1204448 Share on other sites More sharing options...
JKG Posted April 21, 2011 Share Posted April 21, 2011 hmm, i wouldnt advise that. you would have to store the data in cookies probably, which has its own complications. i think each page having its own form is the cleanest way of dealing with it, i cant see any advantage to saving all the data up for one script. what if they change loads, then forget to save? or the browser crashes... hope you get it sorted. Joe. Quote Link to comment https://forums.phpfreaks.com/topic/234336-update-multiple-records-in-one-form/#findComment-1204452 Share on other sites More sharing options...
mrt003003 Posted April 21, 2011 Author Share Posted April 21, 2011 Yeah i see your point Joe, ill update on a single page afterall... Can i ask you some thinkg quickly on a different matter please?? Im using dream weaver and i search a tables playername to match a session variable MM_Username (which is set to a playername) mysql_select_db($database_swb, $swb); $query_Detect = sprintf("SELECT * FROM fleet WHERE PlayerName = %s", GetSQLValueString($colname_Detect, "text")); $Detect = mysql_query($query_Detect, $swb) or die(mysql_error()); $row_Detect = mysql_fetch_assoc($Detect); $totalRows_Detect = mysql_num_rows($Detect); All i want to do i select all records that are NOT equal to the session variable and i add the ! $query_Detect = sprintf("SELECT * FROM fleet WHERE PlayerName != %s", GetSQLValueString($colname_Detect, "text")); The trouble is it doesnt work.. Any ideas? Thank you Quote Link to comment https://forums.phpfreaks.com/topic/234336-update-multiple-records-in-one-form/#findComment-1204456 Share on other sites More sharing options...
JKG Posted April 21, 2011 Share Posted April 21, 2011 try $query_Detect = sprintf("SELECT * FROM fleet WHERE PlayerName <> %s", GetSQLValueString($colname_Detect, "text")); if not i bet its something to do with dreamweaver's %s way of managing data. i recommend, as soon as your ready, going with a nice code editor like coda. http://www.adobe.com/devnet/dreamweaver/articles/sql_primer.html/feed/ Quote Link to comment https://forums.phpfreaks.com/topic/234336-update-multiple-records-in-one-form/#findComment-1204457 Share on other sites More sharing options...
mrt003003 Posted April 21, 2011 Author Share Posted April 21, 2011 Thanks Joe ill check coda out.. Ive been using dream weaver for far too long now. I tried the modified bit and its still not working undefined variable $row_Detect heres the dream weaver created code for the session: if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } } Thanks Quote Link to comment https://forums.phpfreaks.com/topic/234336-update-multiple-records-in-one-form/#findComment-1204460 Share on other sites More sharing options...
mrt003003 Posted April 21, 2011 Author Share Posted April 21, 2011 thats cool it is working! Its some else that isnt. Thanks Joe Quote Link to comment https://forums.phpfreaks.com/topic/234336-update-multiple-records-in-one-form/#findComment-1204461 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.