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 "   Successful";
echo "<BR><BR>";
} else {
echo "  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.
Related
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
SO, I want to create a pretty big mysql table that should save all of the squares of a chess board and their value, I'm using a PHP for() since it has 64 squares.
This always gives me 'not working'
<?php
mysql_connect('localhost','pierostesting','');
mysql_select_db('my_pierostesting');
$query="CREATE TABLE board (";
for($i=0;$i<63;$i++){
$query .= "i".$i." INT(1) NOT NULL,";
}
$query .="turno BOOL";
if (mysql_query($query)){
echo 'working';
}else echo 'not working'; ?>
I'm an idiot, didn't close the bracket.
try echoing out your complete SQL string, then use phpMyAdmin and see if the sql string actually works, or if it throws errors. You may have a sql syntax error.
If it does work, make sure your connection variables are correct (host, db name, username, password)
that should get you close to the answer.
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'";
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
^
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'"
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 9 years ago.
Improve this question
I am running the below code and know that this is the suspect peice as I have placed an echo above and below it. The first runs fine but the second does not.
If I change the query to something like "show tables" it will run but I cannot see what if anything is wrong with this. I have checked reserved words and syntax. Am I missing something obvious!
try
{
$sth = $dbh->prepare('SELECT COUNT(*) AS val FROM users WHERE username=:user');
$sth->binvalue('user',$_POST['user']);
$sth->execute();
}
catch(PDOException $e)
{
echo $e->getMessage();
}
There is a type error:
instead of
$sth->binvalue('user',$_POST['user']);
Try
$sth->bindvalue('user',$_POST['user']);
^
$sth->binvalue('user',$_POST['user']);
should be
$sth->bindValue(':user',$_POST['user']);
Notice both the bindValue and the :user