View Single Post
Old 02-27-2013, 03:10 PM   PM User | #19
Foster
Regular Coder

 
Join Date: Nov 2011
Posts: 155
Thanks: 7
Thanked 1 Time in 1 Post
Foster has a little shameless behaviour in the past
How do I get it to work as an update form now?

This is the form.
PHP Code:
<?php
$con
=mysqli_connect("host","user","password","database");
// Check connection
if (mysqli_connect_errno())
  {
  echo 
"Failed to connect to MySQL: " mysqli_connect_error();
  }

$result mysqli_query($con,"SELECT * FROM IGarmy WHERE Comname = '".$_SESSION['Comname']."'");    

echo 
"<form method='post' action='update.php'>";
echo 
"<table border='0'>
<tr>
<th>Commanders Information</th>
</tr>"
;

while(
$row mysqli_fetch_array($result))
  {
  echo 
"<tr>";
  echo 
"</tr>";
  echo 
"</tr>";
    echo 
"</table>";
    echo 
"<table>";
    echo 
"<tr>";
  echo 
"<th>Commanders Name:</th> <td><input type='text' name='Comname' value='$row[Comname]' size='50'>";
      echo 
"<tr>";
  echo 
"<th>Password:</th> <td><input type='password' name='password' value='$row[password]'>";
  echo 
"</tr>";
    echo 
"</table>";
    echo 
"<table>";
    echo 
"<tr>";
  echo 
"<tr>";
  echo 
"</tr>";
  echo 
"</tr>";
   echo 
"<th></th> <td></td>";
    echo 
"</tr>";
  echo 
"<tr>
<th>Imperial Guard Regiment Information</th>
</tr>"
;
  echo 
"<th>Regiment Name:</th> <td><input type='text' name='name' value='$row[name]' size='35'>";
      echo 
"<tr>";
  echo 
"<th>Homeworld:</th> <td><input type='text' name='homeworld' value='$row[homeworld]' size='35'>";
  echo 
"</tr>";
    echo 
"<th>Estimated Regiment Size:</th> <td><input type='text' name='regsize' value='$row[regsize]' size='35'>";
  echo 
"</tr>";
  echo 
"<th>Unit Type:</th> <td><input type='text' name='unittype' value='$row[unittype]'>";
      echo 
"<tr>";
  echo 
"<th>Gender:</th> <td><input type='text' name='gender' value='$row[gender]'>";
  echo 
"</tr>";
  echo 
"<th>Allegiance:</th> <td><input type='text' name='allegiance' value='$row[allegiance]'>";
      echo 
"<tr>";
  echo 
"<th>Prefered Special Weapon:</th> <td><input type='text' name='specialweapon' value='$row[specialweapon]'>";
  echo 
"</tr>";
  echo 
"<th>Prefered Heavy Weapon:</th> <td><input type='text' name='heavyweapon' option     value='$row[heavyweapon]' >";
      echo 
"<tr>";
      echo 
"</tr>";
  echo 
"</tr>";
   echo 
"<th></th> <td></td>";
    echo 
"</tr>";
    echo 
"</table>";
    echo 
"<table>";
    echo 
"<tr>";
    echo 
"<th>Background:</th> <tr></tr> <td>";
      echo 
"<textarea cols=\"75\" rows=\"15\"> $row[Background] </textarea><br>";
      echo 
"</tr>";
  echo 
"<th>Historical Figures:</th> <tr> <td>";
  echo 
"<textarea cols=\"75\" rows=\"15\">$row[HistoricalFigures]</textarea><br>";
  echo 
"</tr>";
    echo 
"<th>Notable Campaigns:</th> <tr> <td>";
  echo 
"<textarea cols=\"75\" rows=\"15\">$row[campaigns]</textarea><br>";
  echo 
"</tr>";
  }
echo 
"</table>";
echo 
"<input type=\"submit\" name=\"submit\" value=\"Update Information\">";
echo 
"</form>";

mysqli_close($con);
?>
This is the update page
PHP Code:
<?php
include("config.php");

// connect to the mysql server
$link mysql_connect($server$db_user$db_pass)
or die (
"Could not connect to mysql because ".mysql_error());

// select the database
mysql_select_db($database)
or die (
"Could not select database because ".mysql_error());

mysql_query("UPDATE IGarmy SET Comname = '".$_POST['Comname']."', password = '".$_POST['password']."', name = '".$_POST['name']."', homeworld = '".$_POST['homeworld']."', regsize = '".$_POST['regsize']."', unittype '".$_POST['unittype']."', gender = '".$_POST['gender']."', allegiance = '".$_POST['allegiance']."', specialweapon = '".$_POST['specialweapon']."', heavyweapon = '".$_POST['heavyweapon']."', Background = '".$_POST['Background']."', HistoricalFigures = '".$_POST['HistoricalFigures']."', campaigns = '".$_POST['campaigns']."')
WHERE Comname = '"
.$_POST['Comname']."' AND password = '".$_POST['password']."'");

$resmysql_query($update);

?>

Last edited by Foster; 02-27-2013 at 03:16 PM..
Foster is offline   Reply With Quote