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 have problem with query to base, problem appears after OR:
Parse error: syntax error, unexpected 'or' (T_LOGICAL_OR) in
Here is the code:
$chat2=mysql_query('SELECT * from chat where
user1!="" OR user2!="" AND status="oczekuje" AND user1="'.$_SERVER['REMOTE_ADDR'].'"
OR user2="'.$_SERVER['REMOTE_ADDR'].'" '); or die();
$dodaj2=mysql_fetch_array($chat2);
$ilosc2=mysql_num_rows($chat2);
Here screen from sublime: http://scr.hu/47nh/haujn
Why "OR" is not on red color like AND?
Right now, or die(); is a separate statement because there is a ; right before it. You should change to
$chat2=mysql_query('SELECT * from chat where
user1!="" OR user2!="" AND status="oczekuje" AND user1="'.$_SERVER['REMOTE_ADDR'].'"
OR user2="'.$_SERVER['REMOTE_ADDR'].'" ') or die();
Furthermore, you want to consider:
use mysqli_* or PDO to prevent SQL injection attacks
add some parentheses to the query. How can you know that MySQL evaluates AND and OR in the same way as intended?
To elaborate point 2, AND takes precedence over OR, so it is evaluated as
user1!="" OR
(user2!="" AND status="oczekuje" AND user1="'.$_SERVER['REMOTE_ADDR'].'") OR
user2="'.$_SERVER['REMOTE_ADDR'].'"
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 8 years ago.
Improve this question
This is my code:
UPDATE post SET pagetext = replace(pagetext, 'hiiiiiii','lol')
But it doesn't work and I get the following error:
#1064 - You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use
near ''hiiiiiii''lol') FROM post WHERE' at line 1
Any ideas?
MySQL server version for the right syntax to use near ''hiiiiiii''lol')
^
Look close, you dont have a comma between those parameters and because of that your string becomes invalid having 2 quotation marks inside.
It appears there was a problem with phymyadmin, the query is indeed correct.
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
Without getting into too much details on my project, I'm currently trying to use PHP to download a remote file and store it in the current directory on the server. Please keep in mind I do not know much of anything about PHP and am trying to learn.
I'm using the following code:
<?php file_get_contents(''http://xxx.xx.xx/file.php/'');?>
As you can see, this is pretty basic, and I'm not even really sure if it will get the job done.
Any help is greatly appreciated!
Try this:
<?php file_get_contents("http://xxx.xx.xx/file.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
New PHP programmer here. Need some syntax help.
Like I know what im trying to do, here, check if that session variable is set and if its a certain string value, but the "(" you need for isset is messing the syntax up. I can't find the help im looking for via google for what is really a very simple syntax question, so I had to come here.
if (isset($_SESSION['IsValid'] AND $_SESSION['IsValid']=="Yes")) {
}else{
}
Typos:
if (isset($_SESSION['IsValid']) AND $_SESSION['IsValid']=="Yes") {
^---missing ^---only one ) here
isset() is a function and checks a SINGLE variable if it "exists". You're trying to isset() the result of your AND operation, which is illegal syntax.
if( isset($_SESSION['IsValid']) && $_SESSION['IsValid'] == "Yes" ) {
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 am unable to insert integer data from insert statement.
$value = $_POST[from];
$query = mysql_query("INSERT INTO trip(tripid,from)VALUES(NULL, $value)");
Here from is integer value, but i am getting syntax error as :
You have an error in your SQL syntax;check the manual that corresponds to your MySQL server version for the right syntax to use near'from)VALUES(NULL, 1)'` at line 1.
from is Reserved Words in MySQL http://dev.mysql.com/doc/mysqld-version-reference/en/mysqld-version-reference-reservedwords-5-5.html
try this
mysql_query("INSERT INTO trip(tripid,`from`)VALUES(NULL, $value)");