Hi Guys, I'm back again with a few more problems.
I've got a php script to update my MySQL database if needs be. For some reason it's not updating the database.
This is how it should work:
editDJ1.php (select the DJ to edit) [works okay]
editDJ2.php (brings the DJ's details from the database for editing) [pulls the info okay.. Once edited i press "Submit" and it passes to editDJ3.php]
editDJ3.php (validates the new entries and submits to database) [not working]
I've included the code from DJ2.php below, then under that, the DJ3.php file.. im not sure where its going wrong 🙁
Sorry for the length of the code, but i didnt want to leave anything out that may be causing the problem.
editDJ2.php
<?php
include ("../config.php");
include ("header.inc");
if (!empty($_GET['pass'])) {
$pass = $_GET['pass'];
} else {
$pass = $_POST['pass'];
}
if ($pass != $adminpass) {
echo "<strong>Incorrect password</strong>";
} else {
//////////////////
$query="SELECT * FROM currentdj WHERE dj = '$edj'";
$result=mysql_query($query);
while($row = mysql_fetch_array($result)) {
$edj = "$row[dj]";
$epass = "$row[password]";
$eactive = "$row[active]";
$ename = "$row[name]";
$eaddress = "$row[address]";
$eaim = "$row[aim]";
$emsn = "$row[msn]";
$eyim = "$row[yim]";
$eicq = "$row[icq]";
$eals1 = "$row[alias1]";
$eals2 = "$row[alias2]";
$eals3 = "$row[alias3]";
}
?>
<SCRIPT LANGUAGE="JavaScript">
function checkrequired(which) {
var pass=true;
if (document.images) {
for (i=0;i<which.length;i++) {
var tempobj=which.elements[i];
if (tempobj.name.substring(0,8)=="required") {
if (((tempobj.type=="text"||tempobj.type=="textarea")&&
tempobj.value=='')||(tempobj.type.toString().charAt(0)=="s"&&
tempobj.selectedIndex==0)) {
pass=false;
break;
}
}
}
}
if (!pass) {
shortFieldName=tempobj.name.substring(8,30).toUpperCase();
alert("Please make sure the "+shortFieldName+" field was properly completed.");
return false;
}
else
return true;
}
</script>
<style type="text/css">
<!--
.style2 {color: #FF0000}
.style4 {color: #000033}
-->
</style>
<p><strong>DJ Management > Edit DJ</strong></p>
<form action="editDJ3.php" method="post" name="editDJ2" onSubmit="return checkrequired(this)">
<span class="style2">*</span> Required<br>
<table width="432" border="2" cellpadding="2" cellspacing="0" bordercolor="#666666">
<tr>
<td width="272"><strong>Display Name<span class="style2">*</span></strong></td>
<td width="144">
<input name="requireddjname" type="text" id="requireddjname" value="<?php echo "$name"; ?>">
</td>
</tr>
<tr>
<td width="272"><strong>Password<span class="style2">*</span></strong></td>
<td width="144">
<input name="requireddjpassword" type="password" id="requireddjpassword" value="<?php echo "$pass"; ?>">
</td>
</tr>
<tr>
<td width="272"><strong>Password Confirm<span class="style2">*</span></strong></td>
<td width="144">
<input name="requireddjpassword2" type="password" id="requireddjpassword2" value="<?php echo "$pass"; ?>">
</td>
</tr>
<tr>
<td><strong>Presenter Picture URL</strong></td>
<td><input name="newaddress" type="text" id="newaddress" value="<?php echo "$address"; ?>"></td>
</tr>
<tr>
<td><strong>Show Times</strong></td>
<td><input name="newaim" type="text" id="newaim" value="<?php echo "$icqdb"; ?>"></td>
</tr>
<tr>
<td><strong>Show Days</strong></td>
<td><input name="newmsn" type="text" id="newmsn" value="<?php echo "$aimdb"; ?>"></td>
</tr>
<tr>
<td><strong>Profile Name (./profiles/"FILE".php)</strong></td>
<td><input name="newyim" type="text" id="newyim" value="<?php echo "$msn"; ?>"></td>
</tr>
<tr>
<td><strong>UNUSED</strong></td>
<td><input name="newicq" type="text" id="newicq" value="<?php echo "$yim"; ?>"></td>
</tr>
<tr>
<td><strong>Alias 1<span class="style2">*</span> </strong></td>
<td><input name="requiredalias1" type="text" id="requiredalias1" value="<?php echo "$aliasa"; ?>"></td>
</tr>
<tr>
<td><strong>Alias 2<span class="style2">*</span></strong></td>
<td><input name="requiredalias2" type="text" id="requiredalias2" value="<?php echo "$aliasb"; ?>"></td>
</tr>
<tr>
<td><strong>Alias 3<span class="style2">*</span> </strong></td>
<td><input name="requiredalias3" type="text" id="requiredalias3" value="<?php echo "$aliasc"; ?>"></td>
</tr>
</table>
<?php
if ("$dj" == "$edj") {
echo "<br><b>Note: This DJ is currently signed on as an active DJ.</b>";
} ?>
<input type="hidden" name="pass" value="<?php echo "$pass"; ?>">
<input type="hidden" name="edj" value="<?php echo "$edj"; ?>"><br>
<input type="submit" name="Submit" value="Submit">
<p><strong><u><span class="style4">Explainations</span></u><br>
<u>SongRequester Address</u> - DJ's specific address to their Song Request page. For use with <a href="http://www.oddsock.org/tools/gen_songrequester/" target="_blank">Oddsock Song Requester Winamp plugin.</a> Static address required.<br>
<u>Aliases</u> - Names to search server title for. Three are required, but there can be duplicates or be all the same if needed. </strong></p>
</form>
<br><br><a href="main.php?pass=<?php echo "$pass"; ?>">Main</a>
<?php
}
include ("footer.inc");
?>
editDJ3.php
<?php
include ("../config.php");
include ("header.inc");
if (!empty($_GET['pass'])) {
$pass = $_GET['pass'];
} else {
$pass = $_POST['pass'];
}
if ($pass != $adminpass) {
echo "<strong>Incorrect password</strong>";
} else {
///////////////
$newname = $_POST['requireddjname'];
$djpass1 = $_POST['requireddjpassword'];
$djpass2 = $_POST['requireddjpassword2'];
$newaddress = $_POST['newaddress'];
$newaim = $_POST['newaim'];
$newmsn = $_POST['newmsn'];
$newyim = $_POST['newyim'];
$newicq = $_POST['newicq'];
$als1 = $_POST['requiredalias1'];
$als2 = $_POST['requiredalias2'];
$als3 = $_POST['requiredalias3'];
if ((isset($_POST['requireddjname']) == FALSE) or ($djpass1 !== $djpass2) or (isset($_POST['requireddjpassword']) == FALSE) or (isset($_POST['requireddjpassword2']) == FALSE) or (isset($_POST['requiredalias1']) == FALSE) or (isset($_POST['requiredalias2']) == FALSE) or (isset($_POST['requiredalias3']) == FALSE)) {
if (isset($_POST['requireddjname']) == FALSE) {
echo "<font color=\"red\"><strong>Please enter a name.</strong></font><br>";
}
if ($_POST['requireddjpassword'] !== $_POST['requireddjpassword2']) {
echo "<font color=\"red\"><strong>Passwords do not match.</strong></font><br>";
}
if (isset($_POST['requireddjpassword']) == FALSE) {
echo "<font color=\"red\"><strong>Please enter a password.</strong></font><br>";
}
if (isset($_POST['requireddjpassword2']) == FALSE) {
echo "<font color=\"red\"><strong>Please input your password in the \"password confirm\" box.</strong></font><br>";
}
if (isset($_POST['requiredalias1']) == FALSE) {
echo "<font color=\"red\"><strong>Please enter Alias 1.</strong></font><br>";
}
if (isset($_POST['requiredalias2']) == FALSE) {
echo "<font color=\"red\"><strong>Please enter Alias 2.</strong></font><br>";
}
if (isset($_POST['requiredalias3']) == FALSE) {
echo "<font color=\"red\"><strong>Please enter Alias 3.</strong></font>";
}
} else {
if(!$db = @mysql_connect("$dbhost", "$dbuser", "$dbpass"))
die('<font size=+1>An Error Occurred</font><hr>Unable to connect to the database. <BR>Check $dbhost, $dbuser, and $dbpass in config.php.');
if(!@mysql_select_db("$dbname",$db))
die("<font size=+1>An Error Occurred</font><hr>Unable to find the database <b>$dbname</b> on your MySQL server.");
$resultID = mysql_query("UPDATE currentdj SET name = '$newname', password = '$djpass1', address = '$newaddress', aim = '$newaim', msn = '$newmsn', yim = '$newyim', icq = '$newicq', alias1 = '$als1', alias2 = '$als2', alias3 = '$als3' WHERE dj = '$edj'") or die(mysql_error());
if ($resultID == TRUE) {
print "DJ $newname has been successfully edited!";
} else {
print "Sorry, but DJ $newname was not edited. Please check your settings and try again.";
}
}
?>
<br><br><a href="main.php?pass=<?php echo "$pass"; ?>">Main</a>
<?php
///////////////
}
include ("footer.inc");
?>
Thanks,
Dave