Reputation: 193
I have been testing my sql statement, in different ways, but it's not working. I'm having trouble writing my variables and my session in the sql statement.
function onelike()
{
$_SESSION['admin_id']
$resultLikeCheck = "SELECT FROM tbladminXshouts WHERE postId = $row['id'] AND admin_id = $_SESSION['admin_id']";
$results = mysql_query($resultLikeCheck) or die('');
if(mysql_num_rows($results) == 0)
{
echo ('
`<form action="" method="POST">
<input type="hidden" name="id" value="'.$row['id'].'"/>
<input type = "submit" name="Gilla" value = "Gilla"/>
</form>`
');
}
}
What is wrong with it?
Upvotes: 1
Views: 116
Reputation: 822
You can try this.
$adminID= $_SESSION['admin_id'];
$rowID= $row['id'];
onelike($adminID,$rowID);
function onelike($adminID,$rowID)
{
$resultLikeCheck = "SELECT * FROM tbladminXshouts WHERE postId = '{$rowID}' AND admin_id = '{$adminID}'";
$results = mysql_query($resultLikeCheck) or die('');
And I'd recommend using mysqli_ functions instead of mysql_
Edit:
I think your problem is you are not passing your variables into the function. Functions in PHP have their own local variables and can't access variables outside themselves unless you send them in.
And yes, @Sajjad Merchant is right, the best way to interpolate variables into strings for queries is withuse of "{}"
Upvotes: 0
Reputation:
$resultLikeCheck = "SELECT FROM tbladminXshouts WHERE postId = $row['id'] AND admin_id ='{$_SESSION['admin_id']}'";
use of "{}" to interpolate variables inside strings.
Upvotes: 2