PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
Wldrumstcs
Forum Commoner
Posts: 98 Joined: Wed Nov 26, 2003 8:41 pm
Post
by Wldrumstcs » Thu Jan 06, 2005 7:46 am
Okay, I have a dropdown menu starting on line 30 that is supposed to display all the usernames in a database. For some reason, my code isn't working. Where's the error?
Code: Select all
<?php
mysql_connect("localhost","$username","$password") or die ("Unable to connect to MySQL server.");
$db = mysql_select_db("$database") or die ("Unable to select requested database.");
$query="SELECT * FROM teachers ORDER BY id ASC";
$result=mysql_query($query);
$main = "<form method='POST' action='delete.php?a=verify'>
<table border='0' width='100%' cellspacing='0' cellpadding='0' id='table10'>
<tr>
<td align='center' width='100%' colspan='2'>
<b><font size='2'>*NOTE*: Don't abuse this power...</font></b></td>
</tr>
<tr>
<td height='10'>
</td>
</tr>
<tr>
<td align='right' width='50%' valign='top'>
<p align='right'><b>Your Name:</b></td>
<td align='left' width='50%'>$_COOKIE[username]<br>
<font size='2'>(To login under a different username, </font>
<a href='http://www.*****.com/login.php?a=logout'>
<font size='2'>click here.)</font></a></td>
</tr>
<tr>
<td align='right' width='50%'><b>Teacher that will be deleted:</b></td>
<td width='50%' align='left'>
<select name='filter_teachers'>
<option value='showall'>Choose a Teacher</option>
<option>----------------------</option>";
while ($teacher = mysql_fetch_array($result)) {
$main .= "<option value='$teacher[username]'>$teacher[username]</option>\n";
}
$main .= "</select>
</td>
</tr>
<tr>
<td align='right' width='50%'> </td>
<td align='left' width='50%'> </td>
</tr>
</table>
<p>
<input type='submit' value='Proceed' name='submit' tabindex='3' style='font-weight: bold; border-style: dashed; border-width: 1px; background-color: #999999'></p>
</form>";
?>
Bill H
DevNet Resident
Posts: 1136 Joined: Sat Jun 01, 2002 10:16 am
Location: San Diego CA
Contact:
Post
by Bill H » Thu Jan 06, 2005 8:23 am
You create the var $main, but you never print() or echo it.
Wldrumstcs
Forum Commoner
Posts: 98 Joined: Wed Nov 26, 2003 8:41 pm
Post
by Wldrumstcs » Thu Jan 06, 2005 3:17 pm
No, I did, but not in the portion I gave you. Most of the rest of the stuff is just HTML. The drop down menu displays fine, but it only reads 1 name, not the whole list in the DB.
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Thu Jan 06, 2005 3:43 pm
post a copy of the output sent to the browser please.
Wldrumstcs
Forum Commoner
Posts: 98 Joined: Wed Nov 26, 2003 8:41 pm
Post
by Wldrumstcs » Thu Jan 06, 2005 3:46 pm
It outputs that entire $main, but the drop down menu just shows the last name.
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Thu Jan 06, 2005 4:21 pm
post the html.
Wldrumstcs
Forum Commoner
Posts: 98 Joined: Wed Nov 26, 2003 8:41 pm
Post
by Wldrumstcs » Thu Jan 06, 2005 4:31 pm
Heres my entire code:
Code: Select all
<?
mysql_connect("localhost","$username","$password") or die ("Unable to connect to MySQL server.");
$db = mysql_select_db("$database") or die ("Unable to select requested database.");
$admin = 0;
if($_COOKIE[id] != '' AND $_COOKIE[username] != '' and $_COOKIE[password] !='') {
$result = mysql_query("SELECT count(username) FROM teachers WHERE username='$_COOKIE[username]' AND password='$_COOKIE[password]' AND id='$_COOKIE[id]'");
if($result > 0)
$admin = 1;
}
if($admin == 1) {
IF($_GET[a] == "delete") {
mysql_connect("localhost","$username","$password") or die ("Unable to connect to MySQL server.");
$db = mysql_select_db("$database") or die ("Unable to select requested database.");
$sql = "DELETE FROM teachers WHERE username='$_POST[filter_teachers]'";
$result = mysql_query($sql);
$main = "<font size='4'><b>$_POST[filter_teachers] has been deleted from the database.</b></font><br>You are being redirected...";
echo "<head><meta http-equiv='refresh' content='3;URL=admin.php'></head>";
}ELSEIF($_GET[a] == "verify") {
$main = " <form method='POST' action='delete.php?a=delete'>
<table border='0' width='100%' cellspacing='0' cellpadding='0' id='table10'>
<tr>
<td align='right' width='100%' colspan='2'>
<p align='center'><b><font size='2'>*NOTE*: Don't abuse this power...</font></b></td>
</tr>
<tr>
<td height='10'>
</td>
</tr>
<tr>
<td align='right' width='50%'>
<p align='right'><b>Your Name:</b></td>
<td align='left' width='50%'>$_COOKIE[username]</td>
</tr>
<tr>
<td align='right' width='50%'>
<p align='right'><b>Teacher that will be deleted:</b></td>
<td align='left' width='50%'>$_POST[filter_teachers]</td>
</tr>
</table>
<p>
<a href='javascript:history.go(-1);'>
If you want to change something, click here.</a></p>
<p>
<input type='hidden' name='filter_teachers' value="$_POST[filter_teachers]">
<input type='submit' value='OK, Delete $_POST[filter_teachers]' name='submit1' tabindex='3' style='font-weight: bold; border-style: dashed; border-width: 1px; background-color: #999999'></p>
</form>
";
}
ELSEIF($_GET[a] != "logout" OR $_GET[a] != "verify" OR $_GET[a] != "post"){
mysql_connect("localhost","$username","$password") or die ("Unable to connect to MySQL server.");
$db = mysql_select_db("$database") or die ("Unable to select requested database.");
$query="SELECT * FROM teachers ORDER BY id ASC";
$result=mysql_query($query);
$main = "<form method='POST' action='delete.php?a=verify'>
<table border='0' width='100%' cellspacing='0' cellpadding='0' id='table10'>
<tr>
<td align='center' width='100%' colspan='2'>
<b><font size='2'>*NOTE*: Don't abuse this power...</font></b></td>
</tr>
<tr>
<td height='10'>
</td>
</tr>
<tr>
<td align='right' width='50%' valign='top'>
<p align='right'><b>Your Name:</b></td>
<td align='left' width='50%'>$_COOKIE[username]<br>
<font size='2'>(To login under a different username, </font>
<a href='http://www.*****.com/wwshs/login.php?a=logout'>
<font size='2'>click here.)</font></a></td>
</tr>
<tr>
<td align='right' width='50%'><b>Teacher that will be deleted:</b></td>
<td width='50%' align='left'>
<select name='filter_teachers'>
<option value='showall'>Choose a Teacher</option>
<option>----------------------</option>";
while ($teacher = mysql_fetch_array($result)) {
$main .= "<option value='$teacher[username]'>$teacher[username]</option>\n";
}
$main .= "</select>
</td>
</tr>
<tr>
<td align='right' width='50%'> </td>
<td align='left' width='50%'> </td>
</tr>
</table>
<p>
<input type='submit' value='Proceed' name='submit' tabindex='3' style='font-weight: bold; border-style: dashed; border-width: 1px; background-color: #999999'></p>
</form>";
}
?>
<html>
<head>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
</head>
<style fprolloverstyle>A:hover {color: #000000; text-decoration: blink}
</style>
<link rel="stylesheet" type="text/css" href="stylesheet.css">
<script type="text/javascript">
function init() {
if (!document.getElementById) return
var imgOriginSrc;
var imgTemp = new Array();
var imgarr = document.getElementsByTagName
('img')
for (var i = 0; i < imgarr.length; i++) {
if (imgarr[i].getAttribute('hrsc')) {
imgTemp[i] = new Image();
imgTemp[i].src = imgarr[i].getAttribute('hrsc');
imgarr[i].onmouseover = function() {
imgOriginSrc = this.getAttribute('src');
this.setAttribute('src',this.getAttribute('hrsc'))
}
imgarr[i].onmouseout = function() {
this.setAttribute('src',imgOriginSrc)
}
}
}
}
onload=init;
</script>
<body link="#000000" vlink="#000000" alink="#000000" bgcolor="#000000">
<table border="0" width="100%" id="table1" height="100%" bgcolor="#FF7800" cellspacing="0" cellpadding="0">
<tr>
<td width="100%" colspan="3" height="22">
<table border="0" width="100%" bgcolor="#FF7800" id="table9" cellspacing="0" cellpadding="0">
<tr>
<td width="50%">
<img border="0" src="leftlogo.gif" width="481" height="119"></td>
<td width="50%">
<p align="right">
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td width="100%" colspan="3" height="22">
<p align="center"><font size="4"> <a href="index.php">Main</a> | <a href="homework.php">Homework</a> | <a href="links.php">Links</a> | </font> <a href="teachers.php">
<font size="4">Teachers</a> | <a href="tests.php">Tests</a><? IF($_COOKIE[username] == "" OR $_COOKIE[password] == ""){ echo "";}ELSEIF($_COOKIE[username] != "" AND $_COOKIE[password] != ""){ echo " | <a href='admin.php'>Admin</a>";} ?>
</font></td>
</tr>
<tr>
<td width="100%" colspan="3" height="22" bgcolor="#FF7800">
<p align="right"><? IF($_COOKIE[username] == "" OR $_COOKIE[password] == ""){ echo "You are not logged in. <a href='http://www.*****.com/wwshs/login.php'>Click here to login.</a>";}ELSEIF($_COOKIE[username] != "" AND $_COOKIE[password] != ""){ echo "Welcome $_COOKIE[username]. <a href='logout.php'>Click here to logout.</a>";} ?></td>
</tr>
<tr>
<td width="100%" colspan="3" height="22" bgcolor="#FF7800">
<p align="center"><script LANGUAGE="JavaScript1.2">
<!-- Begin
var months=new Array(13);
months[1]="January";
months[2]="February";
months[3]="March";
months[4]="April";
months[5]="May";
months[6]="June";
months[7]="July";
months[8]="August";
months[9]="September";
months[10]="October";
months[11]="November";
months[12]="December";
var time=new Date();
var lmonth=months[time.getMonth() + 1];
var date=time.getDate();
var year=time.getYear();
if (year < 2000) // Y2K Fix, Isaac Powell
year = year + 1900; // http://onyx.idbsu.edu/~ipowell
document.write("<center>" + lmonth + " ");
document.write(date + ", " + year + "</center>");
// End -->
</script></td>
</tr>
<tr>
<td width="25%" align="center" valign="top">
<table border="0" width="100%" id="table2">
<tr>
<td height="40"> </td>
</tr>
<tr>
<td><a href="index.php">
<img border="0" src="main.gif" hrsc="mainover.gif"></a></td>
</tr>
<tr>
<td height="15"></td>
</tr>
<tr>
<td><a href="homework.php">
<img border="0" src="homework.gif" hrsc="homeworkover.gif"></a></td>
</tr>
<tr>
<td height="15"></td>
</tr>
<tr>
<td><a href="links.php"><img border="0" src="links.gif" hrsc="linksover.gif"></a></td>
</tr>
<tr>
<td height="15"></td>
</tr>
<tr>
<td><a href="teachers.php">
<img border="0" src="teachers.gif" hrsc="teachersover.gif"></a></td>
</tr>
<tr>
<td height="15"></td>
</tr>
<tr>
<td><a href="tests.php">
<img border="0" src="tests.gif" hrsc="testsover.gif"></a></td>
</tr>
</table>
<p> </td>
<td width="50%" align="center" valign="top">
<table border="0" width="100%" id="table4" cellspacing="0" cellpadding="0">
<tr>
<td>
<table border="0" width="100%" id="table6" height="70" cellspacing="0" cellpadding="0">
<tr>
<td width="39" align="right" valign="top" height="70">
<img border="0" src="title_left.gif" width="39" height="70"></td>
<td background="title_filler.gif" align="center" height="70">
<p align="center"><font size="6"><b>Delete a Teacher</b></font></td>
<td width="38" align="left" height="70" valign="top">
<img border="0" src="title_right.gif" width="38" height="70"></td>
</tr>
</table>
</td>
</tr>
</table>
<p><? echo "$main"; ?></p>
<p> </p>
</td>
<td width="25%" align="center" valign="top">
<table border="0" width="100%" id="table3">
<tr>
<td align="center" width="100%">
<font size="5"><b>Latest Assignments</b></font><hr size="1" color="#000000">
<table border="0" width="100%" id="table1">
<table border="0" width="100%" id="table1">
<tr>
<td width="34%" align="center"><b>Teacher</b></td>
<td width="33%" align="center"><b>Date</b></td>
<td width="33%" align="center"><b>Assignment Details</b></td>
</tr>
<?
mysql_connect("localhost","$username","$password") or die ("Unable to connect to MySQL server.");
$db = mysql_select_db("$database") or die ("Unable to select requested database.");
$query=mysql_query("SELECT * FROM assignments ORDER BY id LIMIT 7");
$num=mysql_num_rows($query);
$i=0;
while ($i < $num) {
$id=mysql_result($query,$i,"id");
$teacher=mysql_result($query,$i,"teacher");
$month=mysql_result($query,$i,"month");
$day=mysql_result($query,$i,"day");
echo "
<tr>
<td align='center' width='34%'>
$teacher</td>
<td align='center' width='33%'>
$month $day</td>
<td align='center' width='33%'>
<a href='details.php?id=$id'>Click Here</td>
</tr>
";
}
?>
</table>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td width="100%" colspan="3" height="51">
<p align="center">
<img border="0" src="wwshs.gif" width="92" height="92"><p align="center">
<font size="2">©2004 </font><p align="center"> </td>
</tr>
</table>
</body>
</html>
<?
}else{ echo "
<meta http-equiv='refresh' content='3;URL=login.php'>
<html>
<body bgcolor='#000000'>
<div align='center'>
<table border='0' width='100%' height='100%' id='table1' bgcolor='#FF7800' cellspacing='0' cellpadding='0'>
<tr>
<td align='center'>
<p align='center'><font size='5'><b>You must be logged in to view this page</b></font><br><font size='3'>You are being redirected...</font></p></td>
</tr>
</table>
</div>
</body>
</html>
";}
?>
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Thu Jan 06, 2005 4:45 pm
not the code, the final HTML that gets sent to the browser. Like "View Source", copy, paste.
Wldrumstcs
Forum Commoner
Posts: 98 Joined: Wed Nov 26, 2003 8:41 pm
Post
by Wldrumstcs » Fri Jan 07, 2005 6:30 am
Actually, I am now getting an error:
"Parse error: parse error, unexpected T_VARIABLE in /home/tidbitfa/public_html/wwshs/delete.php on line 108"
That is really line 104 on here...