Jump to content

echo select statement using foreach


brad12345

Recommended Posts

hi all i have a veterinarian website 

 

i have 2 tables in mysql one is for the owner of the pet and his/her details primary key (ownerID)

the other is for the pets details primary key (petID) with foreign key (ownerID) to link the two tables so we know what pet belongs to what owner.

 

I got the script working where i could add new owners and their details, now after this the user is redirected to another page that they can add their pets details.

 

what i am trying to do is allow the user to have a form where along with the pets details they can choose an existing owner from the owners table through a drop down <select> box

this is the code i have but cant figure out how to get the list of "ownerID" to output into the drop down box....

 

if (isset($_POST['addOwner']))
{

	//Insert new owner data into the database martinb 
	$createQuery1 = "INSERT INTO tblOwnerBK (title, name, address, phoneNumber) VALUES ('$title','$ownerName','$address','$phoneNumber')";
	$result = mysql_query($createQuery1);


	  
	  //Form to add new patient
echo ("<form action='$self' method='POST'>");
echo ("<fieldset>");
	echo ("<legend>Add a new patient</legend><p>");

	echo ("Pet Name : <input type='textbox' name='petName' value=''> <p>");
	echo ("Species : <input type='textbox' name='petSpecies' value=''><p>");
	echo ("Breed : <input type='textbox' name='petBreed' value=''> <p>");
	echo ("Age : <input type='textbox' name='petAge' value=''> <p>");
	echo ("Weight : <input type='textbox' name='petWeight' value=''> <p>");


// This is where im having trouble below im not sure if this is what i should be doing but im getting an error

	echo ("<SELECT name='ownerID'>");
	while ($row = mysql_fetch_assoc($result))
		{
			foreach($row as $value)
		echo ("<OPTION value=''>$value['name']</OPTION>");    // THIS IS LINE 104
		}	
	echo ("</SELECT>");


	echo ("<input type='submit' name='addPatient' value='Submit'> <p>");
	echo ("</p>");

echo ("</fieldset>");    

 

 

 

ERROR IS

 

Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING on line 104

 

Hopefully you guys can help

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/98942-echo-select-statement-using-foreach/
Share on other sites

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.