brad12345 Posted April 1, 2008 Share Posted April 1, 2008 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 ?> Quote Link to comment https://forums.phpfreaks.com/topic/98949-can-anyone-tell-why-this-script-doesnt-work/ Share on other sites More sharing options...
MadTechie Posted April 1, 2008 Share Posted April 1, 2008 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>"); } Quote Link to comment https://forums.phpfreaks.com/topic/98949-can-anyone-tell-why-this-script-doesnt-work/#findComment-506284 Share on other sites More sharing options...
brad12345 Posted April 1, 2008 Author Share Posted April 1, 2008 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>"); Quote Link to comment https://forums.phpfreaks.com/topic/98949-can-anyone-tell-why-this-script-doesnt-work/#findComment-506288 Share on other sites More sharing options...
MadTechie Posted April 1, 2008 Share Posted April 1, 2008 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>"); } Quote Link to comment https://forums.phpfreaks.com/topic/98949-can-anyone-tell-why-this-script-doesnt-work/#findComment-506292 Share on other sites More sharing options...
zenag Posted April 1, 2008 Share Posted April 1, 2008 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>"); Quote Link to comment https://forums.phpfreaks.com/topic/98949-can-anyone-tell-why-this-script-doesnt-work/#findComment-506296 Share on other sites More sharing options...
brad12345 Posted April 1, 2008 Author Share Posted April 1, 2008 nice one guys got it to work thanks to yous Stoked! Quote Link to comment https://forums.phpfreaks.com/topic/98949-can-anyone-tell-why-this-script-doesnt-work/#findComment-506308 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.