Inserting in MySQL using PHP in OpenSUSE 13.2

Hello,
few days before, I installed Opensuse 13.2, and also LAMP using yast-pattern. But since I installed it, my php scripts can not execute any sql query via mysqli_query command if arguments are strings. It just works with constants. For very simple example:

$query=“insert into table (record1, record2) VALUES (’$value1’, ‘$value2’)”

would not product any result (nothing would be inserted into table of database, but if I wrote:

$query=“insert into table (record1, record2) VALUES (‘12’, ‘2342’)”

12 and 2342 would be inserted into database. I think it is no need to tell that I use mysqli_query() command for this. As I already said - everything worked fine in OpenSUSE 13.1

My questions are:

  1. How can I insert something in database using string instead of constants?
  2. Is there any additional package I have to install to fix this problem?

Once again, I installed LAMP using yast pattern “WEB and LAMP server”.

Thank you for answering my questions.

I noticed the variables are enclosed in ‘ticks’ . Does it work if you take out the ticks?
Also, have you tried excaping the $'s ? like ‘$value’ ??

Hi,

You should learn/know the basic of shell quoting.
Here is your first example

$query="insert into table (record1, record2) VALUES ('$value1', '$value2')"

If you use single quotes to a $variable then it will not expand it will produce a literal $variable and not its value.

var1=foo; echo '$var1'

will produce

$var

while

var1=foo; echo "$var1"

will produce

foo

a POSIX man page is here.

http://pubs.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html

Note that is for the shell. If you are using some php script then i don’t know :slight_smile:

The question is about PHP, not shell.

Right, then by all means give the solution :slight_smile: