Question 1:
I have made a little feedback script for one of my website, it works great. But the owner of the website does not know how to use html, let alone how to use phpmyadmin to delete records. So I devised a little login system for them and I have a link that shows when they are logged in called Delete Feedback, what I want this link to do is delete the feedback. Right now i have not been able to accomplish this. My current fields in my database are: ID (primary key), Subject, Message. When I delete the ID in phpmyadmin it deletes the other two, so I figured I could just do this with SQL/PHP...Haven't been able to.
Also I need this to work in a for loop, here is a pic of what it looks like currently:

Code: Select all
$sql = "SELECT COUNT(*) FROM feedback";
$result = mysql_query($sql) or trigger_error("SQL", E_USER_ERROR);
$r = mysql_fetch_row($result);
$numrows = $r[0];
// number of rows to show per page
$rowsperpage = 5;
// find out total pages
$totalpages = ceil($numrows / $rowsperpage);
// get the current page or set a default
if (isset($_GET['currentpage']) && is_numeric($_GET['currentpage'])) {
// cast var as int
$currentpage = (int) $_GET['currentpage'];
} else {
// default page num
$currentpage = 1;
} // end if
##########
// if current page is greater than total pages...
if ($currentpage > $totalpages) {
// set current page to last page
$currentpage = $totalpages;
} // end if
// if current page is less than first page...
if ($currentpage < 1) {
// set current page to first page
$currentpage = 1;
} // end if
###########
// the offset of the list, based on current page
$offset = ($currentpage - 1) * $rowsperpage;
##########
// get the info from the db
$sql = "SELECT * FROM feedback ORDER BY ID DESC LIMIT $offset, $rowsperpage";
$result = mysql_query($sql) or trigger_error("SQL", E_USER_ERROR);
#########
//Number fetch array for $result
$row2 = mysql_fetch_array($result);
for($counter = 1; $counter <= 5; $counter += 1)
{
$id = $_GET[ID];
$delete = mysql_query("DELETE FROM feedback WHERE ID = $id");
echo "<a href=\"editphpfeedback.php?$delete$ \">Delete Feedback?</a><br />";
echo "<font face='comic sans ms' size='-1'>Subject: <b><font color='red'> " . $row2['Subject'] . "</font></b>";
echo "<br />Message: <b>" . $row2['Message'] . "</b><br /><br />";
echo "<hr color='#EEEEEE' /></font>";
echo "</form>";
$row2 = mysql_fetch_array($result);
}
########
/****** build the pagination links ******/
// if not on page 1, don't show back links
if ($currentpage > 1) {
// show << link to go back to page 1
echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=1'><<</a> ";
// get previous page num
$prevpage = $currentpage - 1;
// show < link to go back to 1 page
echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$prevpage'><</a> ";
} //End IF
#########
// range of num links to show
$range = 5;
// loop to show links to range of pages around current page
for ($x = ($currentpage - $range); $x < (($currentpage + $range) + 1); $x++) {
// if it's a valid page number...
if (($x > 0) && ($x <= $totalpages)) {
// if we're on current page...
if ($x == $currentpage) {
// 'highlight' it but don't make a link
echo " [<b>$x</b>] ";
// if not current page...
} else {
// make it a link
echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$x'>$x</a> ";
} // end else
} // end if
} // end for
//Show next page link even if page is 1
if ($currentpage <= $totalpages - 1) {
//get next page num
$nextpage = $currentpage + 1;
//show > to go to next page
echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$nextpage'>></a> ";
//show >> to go to last page
echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$totalpages'>>></a> ";
} // end if
I have pagination going on? (don't quite know how to word that) but the point of this is, I have 5 results shown per page, and I pull 5 records from my database. These are 2 seperate events in my script and they do not work with each other currently. What happens then is even though I don't have 5 records in the database it is still putting:
Subject:
Message:
5 times. Is there any way I can make those two work together so that the amount of times Subject, Message shows up is equal to the amount of rows in the database? I'm willing to try anything. (The code for this is above).
Question Number 3:
I want to make a Name optional field, but I don't want Name:, to show unless somebody puts something in the Name field. Is there any way to do this?
Once again thanks in advance I know this is a lot to ask from a new person on the forums.