zachsformacs95
New Member
Ok, I'm from webdevforums which I hear got hacked... Anyway, I'm pretty new to SQL. I have a database, and each record in the table has a unique id. If I want to delete a row, I pass on the table name and that unique id like so:
It shows a confirmation box which, on OK, proceeds to delete the row -
All of this works fine. I delete the row like so:
Once again, all of this works fine. However, I would like to notify the user which row has been deleted. I want to get the "teacher" field of the row in this table that has the id of $id and store that in a variable. How would I do this?
I've tried:
But that returns "Resource id #2".
Thanks in advance. Note: I've simplified my code, if for whatever reason you want to see more of the original code, let me know.
Code:
<input type="button" onclick="show_confirm('tablename', '<?php echo $id; ?>')" value="Delete" />
It shows a confirmation box which, on OK, proceeds to delete the row -
Code:
window.location = "edit.php?p=delete&table=" + table + "&id=" + id;
All of this works fine. I delete the row like so:
Code:
$con = mysql_connect("localhost", "username", "password");
if (!$con) {
die( 'Could not connect to database: ' . mysql_error() );
}
@mysql_select_db("database") or die( "Unable to select database");
mysql_query("DELETE FROM " . $_GET['table'] . " WHERE id = '" . $_GET['id'] . "'");
mysql_close($con);
Once again, all of this works fine. However, I would like to notify the user which row has been deleted. I want to get the "teacher" field of the row in this table that has the id of $id and store that in a variable. How would I do this?
I've tried:
Code:
$teacher = mysql_query("SELECT teacher FROM " . $table . " WHERE id = '" . $id . "'");
But that returns "Resource id #2".
Thanks in advance. Note: I've simplified my code, if for whatever reason you want to see more of the original code, let me know.
Last edited: