Iqbal
Iqbal

Reputation: 11

Code not giving output

I have been brainstorming with this piece of code since a very long time but no success.

$name = $_GET['name'];
$email = $_GET['email'];
$question = $_GET['question'];
mysql_connect ("localhost", "root", "") or die ('Error: ' . mysql_error());
mysql_select_db ("contact");
$query ="INSERT INTO contactus (name, email, question) VALUES ('".$name."', '".$email."', '".$question."')";
$done=mysql_query($query); 
echo "Hello $name {$_GET["name"]}";
echo "\nYour query $question {$_GET["question"]}";

Upvotes: 1

Views: 94

Answers (3)

mario
mario

Reputation: 145482

If you use double quotes you can also use the PHP3-esque notation without curly braces:

echo "\nYour query $question $_GET[question]";

Note the lack of quotes around the array key. This syntax is only valid within double quotes, though. In normal PHP context you do need them.

Upvotes: 0

fingerman
fingerman

Reputation: 2470

another option:

echo "hello" . $name . "{" .$_GET['name']."}"; ....

Upvotes: -1

Nick Rolando
Nick Rolando

Reputation: 26157

Replace quotes around name and question with single quotes:

echo "Hello $name {$_GET['name']}";

echo "\nYour query $question {$_GET['question']}";

Since you already define the string with double quotes, use single quotes to specify a string within your string.

Upvotes: 6

Related Questions