Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.
Moderator: General Moderators
vipul73
Forum Commoner
Posts: 27 Joined: Mon May 12, 2003 5:32 am
Post
by vipul73 » Tue May 27, 2003 2:27 pm
How do I assign the retrieved value to hidden field
Code: Select all
<?php
$email = $_POST["email"];
$db = mysql_connect("localhost", "root");
mysql_select_db("visitor",$db);
$sql = "INSERT INTO invoice (email) VALUES ('$email')";
$result = mysql_query($sql);
$last_id = mysql_insert_id();
echo "Thank you! Information entered.\n";
//This displays perfectly
echo $last_id;
//This is giving problems
echo '<input name="lastid" type="hidden" id="lastid" value="$last_id">';
?>
Stoker
Forum Regular
Posts: 782 Joined: Thu Jan 23, 2003 9:45 pm
Location: SWNY
Contact:
Post
by Stoker » Tue May 27, 2003 3:44 pm
> //This is giving problems
What kind of problems? What is the output you get?
vipul73
Forum Commoner
Posts: 27 Joined: Mon May 12, 2003 5:32 am
Post
by vipul73 » Tue May 27, 2003 3:49 pm
The hidden field value remains $last_id and is not changed
nielsene
DevNet Resident
Posts: 1834 Joined: Fri Aug 16, 2002 8:57 am
Location: Watertown, MA
Post
by nielsene » Tue May 27, 2003 4:31 pm
vipul73 wrote: How do I assign the retrieved value to hidden field
Code: Select all
//This is giving problems
echo '<input name="lastid" type="hidden" id="lastid" value="$last_id">';
?>
Variable replacement is not done inside single quotes. To make this work you need to do one of the following (which one you like is normally a stylistic preference).
Single Quote with concatenation
Code: Select all
echo '<input name="lastid" type="hidden" id="lastid" value="'.$last_id.'">';
or
Double Quote with Escapes
Code: Select all
echo "<input name="lastid" type="hidden" id="lastid" value="$last_id">";
or
HEREDOC
Code: Select all
$input=<<<END_INPUT
<input name="lastid" type="hidden" id="lastid" value="$last_id">
END_INPUT;
echo $input;
vipul73
Forum Commoner
Posts: 27 Joined: Mon May 12, 2003 5:32 am
Post
by vipul73 » Tue May 27, 2003 4:59 pm
Single Quote with concatenation works perfecty
Thanx a lot