Delete Query Not Deleting [closed] - php

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I'm wondering why the first delete query won't work, when the second does?
if(isset($_POST['accept request' . $user_from])) {
$delete_request = mysql_query("DELETE FROM friend_requests WHERE user_from='$user_from' AND user_to='user_to'");
header("location: friend_requests.php");
echo "<br /><br />You are now friends with " . $user_to;
}
if(isset($_POST['ignorerequest' . $user_from])) {
$delete_request = mysql_query("DELETE FROM friend_requests WHERE user_from='$user_from' AND user_to='$user_to'");
header("location: friend_requests.php");
echo "Friend Request Declined";
}
Please ignore the fact that they're not prepared, and that it's a security issue. I purely want to know why the first delete request doesn't work (yes, the if gets triggered properly)

your missing the dollar sign on your user_to variable
"DELETE FROM friend_requests WHERE user_from='$user_from' AND user_to='$user_to'"

Related

PHP JSON If or Else [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
I'm trying to write a PHP script so if the network type is a JSON feed, I'm pulling indicates mobile event is triggered and if not another event is triggered. I can't figure out the if or else, I've tried a bunch of variations.
Code:
echo( "Network Type: " . $decoded_response['current_carrier']['network_type']);
if ($decoded_response['current_carrier']['network_type']) = 'mobile') {
echo "Event1";
} else {
echo "Event2";
}
if ($decoded_response['current_carrier']['network_type']) = 'mobile'){
maybe this should be
if ($decoded_response['current_carrier']['network_type'] == 'mobile'){
You are using single = instead of == to check for equality. = would assign and not test.

Checking userlevel but it won't work [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
I'm not the best at php and mysql and i'm still learning however i have this userlevel variable which i define in my session
and if i message it back to myself using
<?php echo"$session->userlevel"; ?>
It'll work, it'll tell me that me that my userlevel is "0" which it should be however when i'm using an if statement to check it won't work?
<?php
if ($_SESSION['userlevel'] = 0) {
echo "Userlevel 0 was found!";
}
?>
Any though
if($_SESSION['userlevel'] = 0)
should be
if($_SESSION['userlevel'] == 0)
Otherwise you don't check, you assign the value 0 to $_SESSION['userlevel']

Update record number unexpectedly fails [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
I am trying to get this to update a record and was wondering why I cant get this to work?
I can write a new record no problem but the update doesn't work; is it something simply I am missing?
else {
echo "ID NOT EMPTY-";
//---inside else statement shows this echo and the $id number printed on screen WHERE should have varible $ID but I changed it to debug
echo "$id";
$SQLstring3 = "UPDATE $Tablename SET(blank='1') WHERE(id='5')";
$QueryResult = #mysql_query($SQLstring3, $DBConnect);
}
I think the problem might be the way you are using SET and WHERE. Putting them the parentheses () immediately following them might make them seem like a MYSQL function, which it tries to execute. What you have is this:
"UPDATE $Tablename SET(blank='1') WHERE(id='5')";
Try removing the parentheses:
"UPDATE $Tablename SET blank='1' WHERE id='5'";

$_GET[''] not returning a value [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
$cid = $_GET['cid'];
$aid = $_GET['aid'];
echo 'test';
echo $aid;
echo $cid;
http://whatever.com/script.php?cid=40?aid=20
$cid and $aid do not echo values. Echoing is not my intended usage, I'm trying to compare $aid to a value I get from the database using $cid.
When I noticed my comparison statement validating true when it was definitely supposed to be false, I echoed out the vars and realized the statement is returning true because they are both null.
I'm completely stumped.
Your test URL should not have two question marks. Use ampersands for additional parameters after the first.
http://whatever.com/script.php?cid=40&aid=20
^

This UPDATE appears to be successful but is not [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
My update seems to be successful but for some reason when I check my database it is not updating anything. Here is what I have:
$status="Approve";
$reservation=$_POST['reservations'];
for($i=0; $i < sizeof($reservation); $i++){
$sql = "UPDATE res_list
SET Office_Approval_Status = '$status'
WHERE r_no = 'reservation[$i]'" ;
}
$result=mysql_query($sql);
//condition that check if inserting is successful
if($result){
echo " &nbsp Successful";
echo "<BR><BR>";
} else {
echo "&nbsp Error";
}
Now what happens is it displays that the update is successful but for some reason when I check my database it is not updating anything. The "Office_Approval_Status" is still pending. Is there something wrong with my code?
You are missing a $ in front of your variable in the query.
WHERE r_no = '$reservation[$i]'"
^
Keep in mind that you are also vulnerable to SQL injection attacks and that mysql_* functions are deprecated and should not be used in new code. Definitely escape any variables you are using in queries and seriously consider using prepared statements instead.

Categories