Hello, I am having difficulties with this, I have been working weeks on getting a site finished and I'm down to the last couple of pages and this has become irritating. If you could help I would be very thankful.
Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /home/chaoskni/public_html/admin/insert.php on line 17
Error:
This is the edit_members.php code. (not the one displaying the error)
<?php
require("auth.php");
$rank_array = array("1" => "Founder",
"Leader",
"Commander",
"Co-Commander",
"General",
"Lieutenant General",
"Major General",
"Brigadier General",
"Colonel",
"Lieutenant Colonel",
"Major",
"Captain",
"First Lieutenant",
"Second Lieutenant",
"Master Warrant Officer CWO5",
"Chief Warrant Officer CWO4",
"Chief Warrant Officer CWO3",
"Chief Warrant Officer CWO2",
"Warrant Officer WO1",
"Sergeant Major",
"First Sergeant",
"Master Sergeant",
"Sergeant First Class",
"Staff Sergeant",
"Sergeant",
"Corporal",
"Private: First Class",
"Private",
"Recruit");
@include '../f/fileid.php';
$connect = mysql_connect($db_host,$db_username,$db_password)or die ("no connect");
mysql_select_db($db_name)or die ("no select");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<title>Chaos Knights :: Knights of the Evil Realm</title>
<script type="text/javascript" src="../js/dropdown.js">
/***********************************************
* Drop Down Tabs Menu- (c) Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/
</script>
<!-- CSS for Drop Down Tabs Menu #1 -->
<link rel="stylesheet" type="text/css" href="../css/ddcolortabs.css" />
<link rel="stylesheet" type="text/css" href="../css/website2.css" />
<style type="text/css">
.style1 {
font-weight: normal;
}
</style>
</head>
<body>
<table style="width: 100%" cellspacing="0" cellpadding="0">
<tr>
<td colspan="3" id="banner">
<img alt="" src="../img/banner-left.png" width="504" height="200" /></td>
</tr>
<tr>
<td colspan="3" id="navigation" style="height: 21px">
<?
@include '../f/include/user/navigation2.php';
?>
</td>
</tr>
<tr>
<td width="20%" valign="top" class="left"><span class="style1"><em><?php include '../f/include/user/left.php'; ?></em></td>
<td valign="top" width="60%" class="middle"><blockquote>
<p>
You can use this page to manage the roster/memberlist.<br/>
To begin, click 'Show' next to the task you wish to perform.
</p>
<p>
You can use this page to manage the roster/memberlist.<br/>
To begin, click 'Show' next to the task you wish to perform.
</p>
Add Member : (<a href='#' onclick='document.getElementById("add").style.display = "block"; return false;'>Show</a> / <a href='#' onclick='document.getElementById("add").style.display = "none"; return false;'>Hide</a>)
<div style='display: none;' id='add'>
<form action="insert.php" method="post">
<table border="0" width="500" cellspacing="0" cellpadding="0" id="table1">
<tr>
<td align='right'>*Forum ID: </td>
<td><input type="text" name="uid" size="5" maxlength='5' /></td>
</tr>
<tr>
<td align='right'>*Rank:</td>
<td> <select size="1" name="rank">
<?php
foreach($rank_array as $key => $value){
echo("<option value='$key'>$key - $value</option>
");
}
?>
</select></td>
</tr>
<tr>
<td align='right'>*Game:</td>
<td>
<select size="1" name="game">
<option>Starcraft</option>
<option>Brood War</option>
<option>Starcraft & Brood War</option>
<option>Warcraft II</option>
<option>Warcraft III</option>
<option>World of Warcraft</option>
<option>Diablo</option>
<option>Diablo II & Expansion</option>
</select></td>
</tr>
<tr>
<td align='right'>AIM:</td><td><input type='text' name='aim' value='none'></td>
</tr>
<tr>
<td align='right'>MSN:</td><td><input type='text' name='msn' value='none'></td>
</tr>
<tr>
<td align='right'>Yahoo:</td><td><input type='text' name='yahoo' value='none'></td>
</tr>
<tr>
<td align='right'>E-Mail:</td><td><input type='text' name='email' value='none'></td>
</tr>
<tr>
<td align='right'>*Date Joined :</td><td>
<select name='date_month'>
<option value='1'>01</option>
<option value='2'>02</option>
<option value='3'>03</option>
<option value='4'>04</option>
<option value='5'>05</option>
<option value='6'>06</option>
<option value='7'>07</option>
<option value='8'>08</option>
<option value='9'>09</option>
<option value='10'>10</option>
<option value='11'>11</option>
<option value='12'>12</option>
</select>
<select name='date_day'>
<option value='1'>01</option>
<option value='2'>02</option>
<option value='3'>03</option>
<option value='4'>04</option>
<option value='5'>05</option>
<option value='6'>06</option>
<option value='7'>07</option>
<option value='8'>08</option>
<option value='9'>09</option>
<option value='10'>10</option>
<option value='11'>11</option>
<option value='12'>12</option>
<option value='13'>13</option>
<option value='14'>14</option>
<option value='15'>15</option>
<option value='16'>16</option>
<option value='17'>17</option>
<option value='18'>18</option>
<option value='19'>19</option>
<option value='20'>20</option>
<option value='21'>21</option>
<option value='22'>22</option>
<option value='23'>23</option>
<option value='24'>24</option>
<option value='25'>25</option>
<option value='26'>26</option>
<option value='27'>27</option>
<option value='28'>28</option>
<option value='29'>29</option>
<option value='30'>30</option>
<option value='31'>31</option>
</select>
<select name='date_year'>
<option value='07'>2007</option>
<option value='08'>2008</option>
<option value='09'>2009</option>
<option value='10'>2010</option>
</select> <i>(mm/dd/yyyy)</i>
</td>
</tr>
<tr>
<td colspan="2">
<p align="center">
<input type="submit" value="Add Member" />
</td>
</tr>
</table>
</form>
</div>
<br/>
Edit Members: (<a href='#' onclick='document.getElementById("edit").style.display = "block"; return false;'>Show</a> / <a href='#' onclick='document.getElementById("edit").style.display = "none"; return false;'>Hide</a>)<br/>
<div style='display: <?php if($_POST['do'] == "edit"){echo("block");}else{echo("none");}?>;' id='edit'>
<?php
if($_POST['do'] == "edit"){
$user_row = mysql_fetch_array(mysql_query("SELECT * FROM members WHERE id = $_POST[uid];"));
$rank_out = $user_row[rank];
$username = mysql_fetch_row(mysql_query("SELECT username FROM forum_users WHERE id = $user_row[uid] LIMIT 1;"));
echo ("<br/>
<table width=\"500\">
<tr><td>
<form action=\"edit.php\" method=\"post\">
<font size='+2'><b>Editing: $username[0]</b></font><br/>
Rank:<select size=\"1\" name=\"rank\">
<option value='$user_row[rank]'>$rank_out - $rank_array[$rank_out]</option>");
foreach($rank_array as $key => $value){
echo("<option value='$key'>$key - $value</option>
");}
echo("</select><br/>
Game: <select size=\"1\" name=\"game\">
<option>$user_row[game]</option>
<option>Starcraft</option>
<option>Brood War</option>
<option>Starcraft & Brood War</option>
<option>Warcraft II</option>
<option>Warcraft III</option>
<option>World of Warcraft</option>
<option>Diablo</option>
<option>Diablo II & Expansion</option>
</select><br/>
AIM: <input type='text' name='aim' value='$user_row[aim]'><br/>
MSN: <input type='text' name='msn' value='$user_row[msn]'><br/>
Yahoo: <input type='text' name='yahoo' value='$user_row[yahoo]'><br/>
E-Mail: <input type='text' name='email' value='$user_row[email]'><br/>
Date Joined: NON-EDITABLE ATM (Sorry)<br/>
<input type='hidden' name='date_joined' value='$user_row[date_joined]'>
<input type='hidden' name='' value='$user_row[show_aim]'>
<input type='hidden' name='' value='$user_row[show_msn]'>
<input type='hidden' name='' value='$user_row[show_yahoo]'>
<input type='hidden' name='' value='$user_row[show_email]'>
<input type='hidden' name='' value='$user_row[show_date_recruited]'>
<input type='hidden' name='uid' value='$_POST[uid]'>
<input type='hidden' name='do' value='edit'>
<input type='submit' value='Edit Member'>
</form>
</td></tr>
</table>
");}
?>
<table width="500">
<tr><td>
Select a member to Edit.<br />
<form action="edit_members.php" method="post">
*Member<br/>
<select name='uid' style=text-align:center;
<option value="0">*Select*</option>
<?php
$results = mysql_query("SELECT * FROM members;");
while($row = mysql_fetch_array($results)){
$username = mysql_fetch_row(mysql_query("SELECT username FROM forum_users WHERE id = $row[uid] LIMIT 1;"));
echo("<option value='$row[id]'>$username[0]</option>
");
}
?>
</select><br/>
<input type='hidden' name='do' value='edit'>
<input type='submit' value='Edit Member'>
</form>
</td></tr>
</table>
</div>
Toggle Display: (<a href='#' onclick='document.getElementById("tog").style.display = "block"; return false;'>Show</a> / <a href='#' onclick='document.getElementById("tog").style.display = "none"; return false;'>Hide</a>)<br/>
<div style='display: none;' id='tog'>
<p>Options for toggling the display option of members currently in the database.<br />
<table width="500">
<tr><td>
<form action="edit.php" method="post">
<div align="center">
<table border="0" width="250" cellspacing="0" cellpadding="0" id="table1">
<tr>
<td colspan='2' align='center'>
Displayed Members<br/>
<select name="uid" style="text-align:center;">
<option value="0">*Select*</option>
<?php
$results = mysql_query("SELECT * FROM members WHERE display = \"1\";");
while($row = mysql_fetch_array($results)){
$username = mysql_fetch_row(mysql_query("SELECT username FROM forum_users WHERE id = $row[uid] LIMIT 1;"));
echo("<option value='$row[id]'>$username[0]</option>
");
}
?>
</select><br/><br/>
<input type='hidden' name='do' value='off' />
<input type="submit" value="Turn Off Display" />
</td>
</tr></table>
</div>
</form>
</td>
<td>
<form action="edit.php" method="post">
<div align="center">
<table border="0" width="250" cellspacing="0" cellpadding="0" id="table1">
<tr>
<td colspan='2' align='center'>
Hidden Members<br/>
<select name="uid" style="text-align:center;">
<option value="0">*Select*</option>
<?php
$results = mysql_query("SELECT * FROM members WHERE display = \"0\";");
while($row = mysql_fetch_array($results)){
$username = mysql_fetch_row(mysql_query("SELECT username FROM forum_users WHERE id = $row[uid] LIMIT 1;"));
echo("<option value='$row[id]'>$username[0]</option>
");
}
?>
</select><br/><br/>
<input type='hidden' name='do' value='on' />
<input type="submit" value="Turn On Display" /></td>
</tr></table></div>
</form>
</td></tr>
</table>
</div>
Delete Members: (<a href='#' onclick='document.getElementById("del").style.display = "block"; return false;'>Show</a> / <a href='#' onclick='document.getElementById("del").style.display = "none"; return false;'>Hide</a>)<br/>
<div style='display: none;' id='del'>
<p>Deleting a member removes their information permanently. If you don't mean to remove all their info use edit, or the display toggle, to peform your task.<br />
<table width="500">
<tr><td colspan='2' align='center'>
<form action="edit.php" method="post">
*Member<br/>
<select name='uid' style="text-align:center;">
<option value="0">*Select*</option>
<?php
$results = mysql_query("SELECT * FROM members;");
while($row = mysql_fetch_array($results)){
$username = mysql_fetch_row(mysql_query("SELECT username FROM forum_users WHERE id = $row[uid] LIMIT 1;"));
echo("<option value='$row[id]'>$username[0]</option>
");
}
?>
</select><br/>
<input type='hidden' name='do' value='del'>
<input type='submit' value='Permanent Deletion'>
</form>
</td></tr>
</table>
</div>
</blockquote></td>
<td valign="top" width="20%" class="right"><?php include '../f/include/user/right.php'; ?></td>
</tr>
<tr>
<td class="left"><?php include '../f/include/user/bot-left.php'; ?></td>
<td class="middle"><?php include '../f/include/user/bottom-mid.php'; ?></td>
<td class="right"><?php include '../f/include/user/bot-right.php'; ?></td>
</tr>
<tr>
<td colspan="3">
<img src="../img/footer.png" border="0" height="30px" width="100%" /></td>
</tr>
</table>
</body>
</html>
This is the code to the insert.php that handles the data sent from that page.
<?php
require("auth.php");
@include '../f/fileid.php'; //config file
$connect = mysql_connect($db_host,$db_username,$db_password);
if (!$connect) {
die('Could not connect: ' . mysql_error());
}
mysql_select_db($db_name)or die ("no select");
$date = mktime(0,0,0,$_POST[date_month],$_POST[date_day],$_POST[date_year]);
$insert="INSERT INTO members (`id` ,`uid` ,`rank` ,`game` ,`show_game` ,`aim` ,`show_aim` ,`msn` ,`show_msn` ,`yahoo` ,`show_yahoo` ,`email` ,`show_email` ,`date_joined` ,`show_date_joined` ,`display`)VALUES (NULL , '$_POST[uid]', '$_POST[rank]', '$_POST[game]', '0', '$_POST[aim]', '0', '$_POST[msn]', '0', '$_POST[yahoo]', '0', '$_POST[email]', '0', '$date', '1', '1');";
if (!mysql_query($insert,$sql)) { die('Error: ' . mysql_error()); }
mysql_close($sql)?>
Any help would be appreciated. I know my code is sloppy :P I looked around at the other people who posted this error. Tried what was discussed, didn't work. So now I'm posting my own. I have made a successful connection to the database so it isn't due that that.