Jump to content

Recommended Posts

The problem is when i go to select an owner to go with the pet im adding from the database in this veterinarian site it comes up with an empty select drop down box?? with no php warnings or errors ive noted the part of the code which is handling the "select an owner" half way down the code.

 

 

 

//Owner POST variables
$addOwner = $_POST['addOwner'];
$phoneNumber = $_POST['phoneNumber'];
$address = $_POST['address'];
$ownerName = $_POST['ownerName'];
$title = $_POST['title'];

//Patient POST vaiables
$addPatient = $_POST['addPatient'];
$petName = $_POST['petName'];
$petSpecies = $_POST['petSpecies'];
$petBreed = $_POST['petBreed'];
$petAge = $_POST['petAge'];
$petWeight = $_POST['petWeight'];
$ownerID = $_POST['ownerID'];



echo("<font face='Arial'>");
$self = $_SERVER['PHP_SELF'];

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>");


////////////////////////////////////////////////////////////////////////////////////////////////////////////
// BELOW IS THE CODE TO SELECT THE EXISTING OWNER FROM THE DATABASE WHICH IS A FOREIGN KEY TO LINK THE OWNER TABLE AND PET TABLE.
////////////////////////////////////////////////////////////////////////////////////////////////////////////

	echo ("Select the pets owner : <SELECT name='ownerID'>");
	while ($row = mysql_fetch_assoc($result))
		{
			foreach($row as $value)
		echo ("<OPTION value=''>".$value['ownerID']."</OPTION>");
		}	
	echo ("</SELECT>");






	echo ("<p>");

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

echo ("</fieldset>");       
                
}
else if (isset($_POST['addPatient']))
{
//Adding patient into database
	$createQuery2 = "INSERT INTO tblPatientBK (petName, petSpecies, petBreed, petAge, petWeight, ownerID) VALUES ('$petName','$petSpecies','$petBreed','$petAge','$petWeight','$ownerID')";
	$result = mysql_query($createQuery2);




} //end of else


else
{




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

	echo ("Title (e.g. Dr., Mr., Mrs., etc) : <input type='textbox' name='title' value=''> <p>");
	echo ("Name                             : <input type='textbox' name='ownerName' value=''><p>");
	echo ("Address                          : <input type='textbox' name='address' value=''> <p>");
	echo ("Phone Number                     : <input type='textbox' name='phoneNumber' value=''> <p>");
	echo ("<input type='submit' name='addOwner' value='Submit'> <p>");
	echo ("</p>");

echo ("</fieldset>");

} //end of else

?>		

without more detail about the database its hard to say

but, i'm sure you don't mean this

 

while ($row = mysql_fetch_assoc($result))
		{
			foreach($row as $value)
		echo ("<OPTION value=''>".$value['ownerID']."</OPTION>");
		}	

probably something like this

while ($row = mysql_fetch_assoc($result))
{
echo ("<OPTION value=''>".$row['ownerID']."</OPTION>");
}	

i tyred wat u sugested but didnt work? datbase structure is

 

$createQuery1 = "CREATE TABLE tblOwnerBK

(

ownerID    INT(6) NOT NULL AUTO_INCREMENT,

title      VARCHAR(5) NOT NULL,

name        VARCHAR(30) NOT NULL,

address    VARCHAR(20) NOT NULL,

phoneNumber INT(3) NOT NULL,

 

PRIMARY KEY (ownerID)

)";

$createQuery = "INSERT INTO tblOwnerBK (title, name, address, phoneNumber) VALUES ('mr','brad','20 ledbury','43564356')";

 

$createQuery2 = "CREATE TABLE tblPatientBK

(

petID      INT(6) NOT NULL AUTO_INCREMENT,

petName    VARCHAR(20) NOT NULL,

petSpecies  VARCHAR(20) NOT NULL,

petBreed    VARCHAR(20) NOT NULL,

petAge      INT(3) NOT NULL,

petWeight  INT(4) NOT NULL,

ownerID    INT(6) NOT NULL,

 

 

PRIMARY KEY (petID),

FOREIGN KEY (ownerID) REFERENCES tblOwnerBK (ownerID)

)";

 

 

echo("$errorString <br>");

$result = mysql_query($createQuery1);

$errorString = mysql_error();

 

echo("$errorString <br>");

$result = mysql_query($createQuery2);

$errorString = mysql_error();

 

$result = mysql_query($createQuery);

$errorString = mysql_error();

echo("$errorString <br>");

I should of said.. your going to need a select statement as well!

 

try this

$createQuery1 = "SELECT * tblOwnerBK ";
$result = mysql_query($createQuery1);
while ($row = mysql_fetch_assoc($result))
{
echo ("<OPTION value='".$row['ownerID']."'>".$row['Title']." ".$row['name']."</OPTION>");
}	

try this out...

 

 

$results=mysql_query("select ownerID from tblOwnerBK ");

 

echo ("Select the pets owner : <SELECT name='ownerID'>");

while ($row = mysql_fetch_assoc($result))

{

 

echo ("<OPTION value=''>".$row['ownerID']."</OPTION>");

}

echo ("</SELECT>");

 

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.