0

Hi was just wanting to know that if your using variables do you write it like this:

INSERT INTO table_name VALUES ($name)

or do you leave the $ out?

2
Contributors
1
Reply
3
Views
5 Years
Discussion Span
Last Post by Biiim
0

it depends which quotes your query is in, double quotes process variables and single quotes print them literally eg.

assuming $name == 'Biiim'

echo 'INSERT INTO table_name VALUES ($name)';
//prints out:INSERT INTO table_name VALUES ($name) 
echo "INSERT INTO table_name VALUES ($name)";
//prints out:INSERT INTO table_name VALUES (Biiim)

you can use concatenating also

echo "INSERT INTO table_name VALUES (".$name.")";
//prints out:INSERT INTO table_name VALUES (Biiim) 

echo 'INSERT INTO table_name VALUES ('.$name.')';
//prints out:INSERT INTO table_name VALUES (Biiim)

and even mix them

echo 'INSERT '."INTO table_name".' VALUES ('.$name.")";
//prints out:INSERT INTO table_name VALUES (Biiim)

also in a mysql query if the value is a string you will want it in quotes

echo "INSERT INTO table_name VALUES ('".$name."')";
//prints out:INSERT INTO table_name VALUES ('Biiim')

Edited by Biiim: missed code tags

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.