Jump to content

Update multiple records in one form


mrt003003

Recommended Posts

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. :)

Link to comment
Share on other sites

<?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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 :)

 

Link to comment
Share on other sites

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 :)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.