I've been trying to use an example I got off of this forum.
The PHP file works fine as a separate PHP file.
When it's adding into a wp page the following results occur;
Page will access db and display the list of people.
Columns can be sorted by either the id or name.
Existing names can be modified
However;
Can not add new players or delete players
ANY suggestions are appreciated!
<?php
/**** Dealing with the database ****/
// connect to db
$conn = mysql_connect('xxxxxxxxxx','yyyyyyyyyy','zzzzzzzzzzzzz') or trigger_error("SQL", E_USER_ERROR);
$db = mysql_select_db('ddddddddddddd',$conn) or trigger_error("SQL", E_USER_ERROR);
// INSERT: if we have a name to add...
if($_GET['name']) {
// little bit of cleaning...
$name = mysql_real_escape_string($_GET['name']);
// insert new name into table
$sql = "INSERT INTO info (id, name) VALUES ('','$name')";
$result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR);
} // end if
// UPDATE: if we have name(s) to change...
if($_POST['cname']) {
// for each name to change...
foreach($_POST['cname'] as $cid => $cname) {
// little bit of cleaning...
$id = mysql_real_escape_string($cid);
$name = mysql_real_escape_string($cname);
// update name in the table
$sql = "UPDATE info SET name = '$name' WHERE id = '$id'";
$result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR);
} // end foreach
} // end if
// DELETE: if we have a name to delete...
if($_GET['name']) {
// little bit of cleaning...
$name = mysql_real_escape_string($_GET['name']);
// delete name from table
$sql = "DELETE FROM info WHERE name = '$name'";
$result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR);
} // end if
// ORDERBY: if one of the links was clicked..
if ($_GET['orderby']) {
// make an aray of allowed names
$allowed = array('id','name');
// bit of cleaning...
$order = mysql_real_escape_string($_GET['orderby']);
// is it a valid column name? yes: use it. no: default to 'id'
$order = (in_array($order, $allowed))? $order : "id";
// if no link clicked, default to 'id'
} else {
$order = "id";
} // end else
// SELECT: get the list of names from database
$sql = "SELECT id, name FROM info ORDER BY $order";
$result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR);
/**** end deal with the database ****/
/**** list everything out ****/
// list columns
echo <<<LISTCOLS
<form action = '{$_SERVER['REQUEST_URI']}' method = 'post'>
<table border = '1'>
<tr>
<td><a href = '{$_SERVER['REQUEST_URI']}?orderby=id'>id</td>
<td><a href = '{$_SERVER['REQUEST_URI']}?orderby=name'>name</td>
<td>delete</td>
</tr>
LISTCOLS;
// loop through list of names
while ($list = mysql_fetch_assoc($result)) {
echo <<<LISTINFO
<tr>
<td>{$list['id']}</td>
<td><input type = 'text' name = 'cname[{$list['id']}]' value = '{$list['name']}'>
<td><a href = '{$_SERVER['REQUEST_URI']}?name={$list['name']}'>delete</a></td>
</tr>
LISTINFO;
} // end while
// list input box for adding new entry
echo <<<NEWENTRY
<tr>
<td bgcolor = 'gray'></td>
<td><input type = 'text' name = 'name'></td>
<td bgcolor = 'gray'></td>
</tr><tr>
<td></td>
<td align = 'center'><input type = 'submit' value = 'submit'></td>
<td></td>
</tr>
</table>
</form>
NEWENTRY;
/**** end list everything out ****/
?>