Jump to content

Posting values from an SQL database onto a HTML form


mb326

Recommended Posts

Hi,

 

I can't appear to find a tutorial or any posts to do this, but I'm trying to access values from an SQL Database and display them in the fields of a HTML form. What I've initially tried doesn't work and echoes an 'unexpected T_STRING variable, in the bold line of the form code below. Please can anyone give me some guidelines?

 

// query to retrieve value from posted variable
$eventID = $_POST['EventID'];
$query = mysql_query($database, "SELECT * FROM EventCalendar WHERE eventID = $eventID");

$getData = mysql_fetch_object($query);

$content = '<div class =\"section\"><H1>Change Event Details</H1>\n';
$content .= '<form action="changeSuccessful.php" method="post">';

[b]$content .= '<p> Location   		<input type="text" name="$_GET['$getData->location']" size="20"/> </p>';[/b]

...is invalid, should be something more like:

 

// query to retrieve value from posted variable
$eventID = $_POST['EventID'];
$query = mysql_query("SELECT * FROM EventCalendar WHERE eventID = '$eventID'") or die(mysql_error());
$getData = mysql_fetch_array($query);
$content = '<div class =\"section\"><H1>Change Event Details</H1>\n';
$content .= '<form action="changeSuccessful.php" method="post">';
$content .= "<p> Location   		<input type='text' name='{$getData['location']}' size='20'/> </p>";

 

I suggest using single quotes inside HTML elements.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.