Would some one please help me, i have a block user script. Basically everything is working ok.
When the user clicks block on the other users profile, this echos the user id, and inserts the user_id and other profile_id into the database and sets the column ‘blocked’ from ‘0’ to ‘1’.
the user who is logged in can now not see the other user they have blocked, however the other the user they blocked can still see their profile.
the way my database works is that it needs both sets id in both columns like so:
user_id | blocked_id | blocked
1 2 1
2 1 1
In order for both users to not see each other and both be blocked i need to try insert the two id’s twice almost.
It’s kind of like duplicating the values inserted into the table to create the same result twice but only the other way around in the table columns.
so at the moment i have:
$sql = mysql_query("INSERT INTO ptb_block_user (user_id, blocked_id) VALUES (".$_SESSION['user_id'].", ".$user_to_id.")");
and i would need to insert these values twice but the opposite way round so it looks like the table above.
I hope im making myself clear, does anyone know how i could do this?
Thanks.
<?php
session_start();
confirm_logged_in();
if (isset ($_GET['to'])) {
$user_to_id = $_GET['to'];
}
if (!isset($_GET['to']))
exit('No user specified.');
$user_id = $_GET['to'];
$sql = mysql_query("INSERT INTO ptb_block_user (user_id, blocked_id) VALUES (".$_SESSION['user_id'].", ".$user_to_id.")");
$result1 = mysql_query("UPDATE ptb_block_user SET blocked='1' WHERE user_id=".$_SESSION['user_id']."")
or die(mysql_error());
if($result1)
{
$_SESSION['message2']="<div class=\"infobox-profile\"><strong>User Blocked</strong> - This user has successfully been blocked. You will no longer be abler to interact with each other's profiles.</div><div class=\"infobox-close\"></div>";
header("Location: {$_SERVER['HTTP_REFERER']}");
}
else
if($result2)
{
$_SESSION['message2']="<div class=\"infobox-favourites\"><strong>User Unblocked</strong> - This user has successfully been unblocked. You can now interact with each other's profiles.</div><div class=\"infobox-close4\"></div>";
header("Location: {$_SERVER['HTTP_REFERER']}");
}
?>
Your question is not entirely clear to me, but it seems like you’re asking how to insert both values with the same query.
VALUEScan take multiple tuples:Your code is highly vulnerable to mysql injection, and you should not use
ext/mysql:http://www.php.net/manual/en/faq.databases.php#faq.databases.mysql.deprecated