Jump to content

Help creating form code.


thedizmaster

Recommended Posts

Hi, I'm fairly new here and need some serious help.

 

I'm trying to create a page that deletes users from the mysql database via a delete_members.php page and I can't seem to get it right. I have a working edit_members.php page, and was wondering if i supplied that code if you might be able to help me do the opposite.

P.S. its for a game.

 

<?php

include("../lib.php");

define("PAGENAME", "Edit Member");

 

include("panel_lib.php");

 

 

//List of fields that cannot be edited

$noedit[] = "id";

//$noedit[] = "username";

$noedit[] = "password";

//$noedit[] = "email";

 

$query = $db->execute("select * from `players` where `id`=?", array(intval($_GET['id'])));

if ($query->recordcount() == 0)

{

echo "This player does not exist!";

exit;

}

else

{

$edit = $query->fetchrow();

}

 

 

 

if (isset($_POST['level']))

{

$update = $_POST;

 

$query = "update `players` set ";

$i = 1;

foreach($update as $k=>$v)

{

//If cannot be edited, do not add to query

if (!in_array($k, $noedit))

{

$query .= "`" . $k . "`=?";

 

//If not last element, add comma to query

if ($i != count($update))

{

$query .= ", ";

}

}

$values[] = $v;

$i++;

}

$query .= " where `id`=?";

$values[] = $edit['id'];

 

$query = $db->execute($query, $values);

 

$query = $db->execute("select * from `players` where `id`=?", array($edit['id']));

$edit = $query->fetchrow();

 

 

$msg = "You have successfully updated this player!";

}

 

 

 

if ($msg)

{

echo "<font color=\"red\">";

echo $msg;

echo "</font>\n";

echo "<br /><br />\n";

}

 

echo "<b>Editing " . $edit['username'] . "</b><br /><br />\n";

 

echo "<form method=\"post\" action=\"edit_member.php?id=" . $edit['id'] . "\">\n";

echo "<table width=\"70%\">\n";

foreach($edit as $k=>$v)

{

if($k==='level') echo'<tr><td><hr></td></tr>';

 

echo "<tr>\n";

echo "<td width=\"35%\">";

 

//If field cannot be edited, show field name in red

if (in_array($k, $noedit))

{

echo "<font color=\"red\">";

}

 

echo ucwords(strtolower($k));

 

if (in_array($k, $noedit))

{

echo "</font>";

}

 

echo "</td>\n";

echo "<td width=\"65%\">";

 

//Add readonly property to input field if field cannot be edited

if (in_array($k, $noedit))

{

echo "<input type=\"text\" value=\"" . $v . "\" readonly=\"readonly\" />";

}

else

{

echo "<input type=\"text\" name=\"" . $k . "\" value=\"" . $v . "\"/>";

}

 

echo "</td>\n";

echo "</tr>\n";

}

 

//echo"<input type='text' name='gm_rank' value='gm_rank'>";

 

echo "<tr><td></td><td><input type=\"submit\" value=\"Edit\" /></td></tr>\n";

echo "</table>\n";

echo "</form>\n";

 

modInfo(0,1);

//include("./footer.php");

?>

 

Any help is greatly appreciated thanks.

Link to comment
https://forums.phpfreaks.com/topic/155245-help-creating-form-code/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.