Page 3 of 5
Posted: Tue Dec 05, 2006 3:06 pm
by feyd
Output buffering is a band-aid 99.999% of the time when it's used for
header() issues.
Use full URLs with header redirections.. If you want to know why, search the multitude of times I've said this.
Posted: Wed Dec 06, 2006 10:56 am
by RobertGonzalez
This does not require AJAX at all. Just post the page back to itself...
Code: Select all
<?php
include 'config.php';
mysql_connect($dbhost, $dbuser, $dbpass) or die('Error connecting to mysql');
mysql_select_db($dbname) or die('Cannot select DB');
// Check to see if there is a request to delete a record first
if (isset($_GET['act']) && $_GET['act'] == 'del')
{
// Now check to see if there is an ID selected for this request
if (isset($_GET['id']) && $_GET['id'] != null && is_numeric($_GET['id']))
{
// There is, so remove the record, then select the list
$id = $_GET['id'];
$sql_delete = "DELETE FROM `deltest1` WHERE `cid` = $id";
mysql_query($sql_delete) or die(mysql_error()); // gives errors
echo 'Record id ' . $id . ' has been deleted...<br />';
}
}
// This query is your list builder, minus the recently deleted record
$query = "SELECT `cid`, `csubject`, `cmessage` FROM `deltest1`";
$result = mysql_query($query) or die('Error, query failed ##1');
echo '<table>';
while ($row = mysql_fetch_array($result))
{
echo $row['csubject'] . $row['cmessage'];
echo '<a href="' . basename($_SERVER['SCRIPT_FILENAME']) . '?act=del&id=' . $row['cid'] . '" title="Delete"><img src="http://image.fpsbanana.com/ico/del.gif"></a>';
}
echo '</table>';
?>
Posted: Wed Dec 06, 2006 2:07 pm
by JustinMs66
wow, thanks for that code.
its alot better now. but the only change is that it says "Comment Deleted" at the top, it still displays the comment instead of showing that the comment has been deleted by not showing it :/
Posted: Wed Dec 06, 2006 2:16 pm
by RobertGonzalez
Is this hosted someplace where we can see it in action?
Posted: Wed Dec 06, 2006 2:18 pm
by JustinMs66
yea, here:
http://csscobalt.com/to_do_list_fpsb/t1/delete9.php
i just have random nonsence entries for right now.
Posted: Wed Dec 06, 2006 2:18 pm
by ok
Posted: Wed Dec 06, 2006 2:23 pm
by JustinMs66
ok wrote:You need to run this:
where would i put "
COMMIT;" ?
Posted: Wed Dec 06, 2006 2:26 pm
by ok
After the DELETE statement.
Posted: Wed Dec 06, 2006 2:29 pm
by JustinMs66
ok i tried that, using this code:
Code: Select all
$sql_delete = "DELETE FROM `deltest1` WHERE `cid` = $id";
mysql_query($sql_delete) or die(mysql_error()); // gives errors
COMMIT;
echo 'Record id ' . $id . ' has been deleted...<br />';
but it still only says that text at the top, it dosnt look like it's been deleted until you refresh :/
go here to test:
http://csscobalt.com/to_do_list_fpsb/t1/delete10.php
Posted: Wed Dec 06, 2006 3:18 pm
by ok
LOL...
COMMIT is a SQL statement:
Code: Select all
mysql_query("COMMIT") or die(mysql_error()); // gives errors
Posted: Wed Dec 06, 2006 3:23 pm
by RobertGonzalez
Justin, please refrain from bumping your thread.
Try this code and see if it changes anything. I can't imagine why you would need a COMMIT here, as this should delete the record as soon as you send the query to the database.
Code: Select all
<?php
include 'config.php';
mysql_connect($dbhost, $dbuser, $dbpass) or die('Error connecting to mysql');
mysql_select_db($dbname) or die('Cannot select DB');
// Check to see if there is a request to delete a record first
if (isset($_GET['act']) && $_GET['act'] == 'del')
{
// Now check to see if there is an ID selected for this request
if (isset($_GET['id']) && $_GET['id'] != null && is_numeric($_GET['id']))
{
// There is, so remove the record, then select the list
$id = $_GET['id'];
$sql = "DELETE FROM `deltest1` WHERE `cid` = $id";
$result = mysql_query($sql);
if (!$result || !mysql_affected_rows()
{
die(mysql_error()); // gives errors
}
else
{
echo 'There were ' . mysql_affected_rows() . ' deleted from the table, including record id ' . $id . ' ...<br />';
}
}
}
// This query is your list builder, minus the recently deleted record
$sql = "SELECT `cid`, `csubject`, `cmessage` FROM `deltest1`";
$result = mysql_query($sql) or die('Error, query failed ##1');
echo '<table>';
while ($row = mysql_fetch_array($result))
{
echo $row['csubject'] . $row['cmessage'];
echo '<a href="' . basename($_SERVER['SCRIPT_FILENAME']) . '?act=del&id=' . $row['cid'] . '" title="Delete"><img src="http://image.fpsbanana.com/ico/del.gif"></a>';
}
echo '</table>';
?>
Posted: Fri Dec 08, 2006 1:20 pm
by JustinMs66
ok. cool. EVERYTHING works Perfectly now.
using this code:
Code: Select all
<?php
include('config.php');
mysql_connect($dbhost, $dbuser, $dbpass) or die('Error connecting to mysql');
mysql_select_db($dbname) or die('Cannot select DB');
$query = "SELECT `cid`, `csubject`, `cmessage` FROM `deltest1`";
$result = mysql_query($query) or die('Error, query failed ##1');
if (isset($_GET['act']) && $_GET['act'] == 'del')
{
if (isset($_GET['id']) && $_GET['id'] != null && is_numeric($_GET['id']))
{
$id = $_GET['id'];
$sql_delete = "DELETE FROM `deltest1` WHERE `cid` = $id";
mysql_query($sql_delete) or die(mysql_error()); // gives errors
mysql_query("COMMIT") or die(mysql_error()); // gives errors
echo 'Record id ' . $id . ' has been deleted...<br />';
}
}
while ($row = mysql_fetch_array($result))
{
$id = $row["cid"];
echo $row["csubject"] . $row["cmessage"];
echo '<a href="' . basename($_SERVER['SCRIPT_FILENAME']) . '?act=del&id=' . $id . '" title="Delete"><img src="http://image.fpsbanana.com/ico/del.gif"></a>';
}
?>
anyway, what i need to do now, is this:
i want, when a user first looks at this page, for it do display the comments, but WITHOUT the trash can image. and at the top of the page, their will be a login box. now once the user logs in, the trash can images will be displayed, and the login box will disapear. can you help me with this?
Posted: Fri Dec 08, 2006 1:27 pm
by RobertGonzalez
Yes, I can help with that. But first you need to try it. Think about the logic behind. Then write the logic out in the form of code comments. Then code the comments and try it out. If there are problems with what you try post back and we will help you.
Posted: Fri Dec 08, 2006 1:35 pm
by JustinMs66
Everah wrote:Yes, I can help with that. But first you need to try it. Think about the logic behind. Then write the logic out in the form of code comments. Then code the comments and try it out. If there are problems with what you try post back and we will help you.
ok i think i can code the user login thing, but for the display code, would it have to be a cookie? like this:
first, where i have this code:
Code: Select all
echo '<a href="' . basename($_SERVER['SCRIPT_FILENAME']) . '?act=del&id=' . $id . '" title="Delete"><img src="http://image.fpsbanana.com/ico/del.gif"></a>';
would have to be where i put my code. now it would be something like(logically)
if cookie.content = 1 then }
echo "image code";
else if cookie.content = 0 then{
echo "login to trash comments";
}
would it be something like that logically? or is their a more efective way to do it then using cookies?
Posted: Fri Dec 08, 2006 2:06 pm
by RobertGonzalez
Whatever mechanism you use to manage user sessions will tell you what you need to know.
Code: Select all
<?php
while ($row = mysql_fetch_array($result))
{
$id = $row["cid"];
echo $row["csubject"] . $row["cmessage"];
if ($user_is_logged_in === true)
{
echo '<a href="' . basename($_SERVER['SCRIPT_FILENAME']) . '?act=del&id=' . $id . '" title="Delete"><img src="http://image.fpsbanana.com/ico/del.gif"></a>';
}
}
?>
But again, try something first and see if it works.