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?

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')
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.