[PHP-DB] Selecting Drop Down Value From DB to Edit
I have the below code that populates a drop down list. The code will correctly insert the value $StateID into another a table. The problem I am running into is that when I select the record to edit the drop-downlist has the first option as the value instead of what the corresponding StateID in the column reads. How can I correct this? The form to insert and edit have the below code and correctly insert the StateID. I tried to write and if statement to state that if the StateID were == to the StateID in he table then print selected, but I think I am missing something. Any suggestions? Thanks. ?php // populates state drop-down list $get_stateid_query = mysql_query(SELECT * FROM State INNER JOIN RaceResults ON State.StateID WHERE RaceID='$RaceID'); echo select name=\StateID\\n; while ($myrow = mysql_fetch_array($get_stateid_query)) { echo ' option value='.$myrow[StateID].''.$myrow[StateName]./option\n; } echo /select\n; ? -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Selecting Drop Down Value From DB to Edit
td width=10 bgcolor=#CC td width=131 valign=middle height=25 class=raceresutlstitle bgcolor=#CCRace Date:/td td width=660 valign=middle bgcolor=#CC input type=Text name=RaceDate value=2002-03-17 /td /tr tr td width=10 td valign=middle height=25 class=raceresutlstitleRace Name:/td td valign=middle input type=text name=RaceName value=An Ras Mor /td /tr tr td width=10 bgcolor=#CC td valign=middle height=25 class=raceresutlstitle bgcolor=#CCRace Distance:/td td valign=middle bgcolor=#CC select name=RaceDistID option value=14 Mi/option /select /td /tr tr td width=10 td valign=middle height=25 class=raceresutlstitleRace Type: /td td valign=middle class=newstxt select name=RaceTypeID option value=1Road/option option value=1Cross-Country/option option value=1Outdoor Track/option /select /td /tr tr td width=10 bgcolor=#CC td valign=middle height=25 class=raceresutlstitle bgcolor=#CCRace Time:/td td valign=middle bgcolor=#CC span class=hdtxtHH input type=text name=RaceTimeHH size=2 maxlength=2 value=00 MM input type=text name=RaceTimeMM size=2 maxlength=2 value=23 SS input type=text name=RaceTimeSS size=2 maxlength=2 value=48 /span/td /tr tr td width=10 td valign=middle height=25 class=raceresutlstitleRace Pace:/td td valign=middle span class=hdtxt MM input type=text name=RacePaceMM size=2 maxlength=2 value=5 SS input type=text name=RacePaceSS size=2 maxlength=2 value=57 /span/td /tr tr td width=10 bgcolor=#CC td valign=middle height=25 class=raceresutlstitle bgcolor=#CC# of Comp.:/td td valign=middle bgcolor=#CC input type=text name=RaceNumbComp value=2000 /td /tr tr td width=10 bgcolor=#ff td valign=middle height=25 class=raceresutlstitle bgcolor=#ffRace Place:/td td valign=middle bgcolor=#ff input type=text name=RacePlace value=15 /td /tr tr td width=10 bgcolor=#cc td valign=middle height=25 class=raceresutlstitle bgcolor=#ccRace City:/td td valign=middle bgcolor=#cc select name=CityID option value=1Somerville/option option value=1/option option value=1Boston/option /select /td /tr tr td width=10 bgcolor=#ff td valign=middle height=25 class=raceresutlstitle bgcolor=#ffRace State:/td td valign=middle bgcolor=#ff select name=StateID option value=1 if ($StateID == $StateID) print selectedCA/option /select /td /tr tr td width=10 bgcolor=#cc td valign=middle height=25 class=raceresutlstitle bgcolor=#ccPR:/td td valign=middle bgcolor=#cc select name=PRID option value=1No/option option value=1Yes/option /select /td /tr tr td width=10 bgcolor=#cc td valign=middle height=25 class=raceresutlstitle bgcolor=#ccRace Report:/td td valign=middle bgcolor=#cc textarea name=RaceReport cols=50 rows=3 value=This is a test/textarea /td /tr tr align=center td width=10 td valign=middle colspan=2 height=28 input type=submit name=Submit value=Update Race /td /tr /table /form /body /html I hope this clarifies the situation. Rick Emery [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... I'm trying to decipher: when I select the record to edit the drop-downlist has the first option as the value instead of what the corresponding StateID in the column reads. How can I correct this? The form to insert and edit have the below code and correctly insert the StateID What exactly is happening? Run the script, do a View Source on the resulting page; show us the HTML generated. -Original Message- From: Steve Fitzgerald [mailto:[EMAIL PROTECTED]] Sent: Tuesday, March 26, 2002 5:22 PM To: [EMAIL PROTECTED] Subject: [PHP-DB] Selecting Drop Down Value From DB to Edit I have the below code that populates a drop down list. The code will correctly insert the value $StateID into another a table. The problem I am running into is that when I select the record to edit the drop-downlist has the first option as the value instead of what the corresponding StateID in the column reads. How can I correct this? The form to insert and edit have the below code and correctly insert the StateID. I tried to write and if statement to state that if the StateID were == to the StateID in he table then print selected, but I think I am missing something. Any suggestions? Thanks. ?php // populates state drop-down list $get_stateid_query = mysql_query(SELECT * FROM State INNER JOIN RaceResults ON State.State
[PHP-DB] Select Inner Join Question
I'm trying to display a summary list of calls with one attribute being CallType. I have CallType and CallTypeID defined in a table name calltypes. The problem I am having is taking the output of CallID defined in calls and having the script match the CallTypeID to the CallType. If I run the display_calltype_sql query in MySQL client and set the CallID to a known integer (set by auto_increment) then I can do what I am trying to do. I guess the problem comes down to getting the $CallID out of the calls table and inserting the value into the second SQL query. I thought my queries did this, but I must be mistaken. Any suggestions? $display_calls_sql = SELECT CallID,CallDateTime,CallSubject,CallStatus FROM calls WHERE ContactID = $ContactID; $display_calltype_sql = SELECT CallType FROM calltypes INNER JOIN calls ON calltypes.CallTypeID = calls.CallTypeID WHERE CallID = '$CallID' ; $display_calls_result = @mysql_query($display_calls_sql,$connection) or die(mysql_error()); $display_calltype_result = @mysql_query ($display_calltype_sql, $connection) or die (mysql_error()); while (list ($CallID, $CallDateTime, $CallSubject, $CallStatus) = mysql_fetch_row($display_calls_result)){ print (tr\n. td width=\21\ height=\24\nbsp;/td\n. td align=\center\$CallID/td\n. td width=\17\nbsp;/td\n. td width=\75\ valign=\top\$CallType/td\n. td width=\26\nbsp;/td\n. td$CallDateTime/td\n. td width=\19\nbsp;/td\n. tda href=\display_call.php?ContactID=$ContactID\$CallSubject/a/td\n. td width=\25\nbsp;/td\n. td$CallStatus/td\n. td width=\30\nbsp;/td\n. /tr\n); } ? -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP-DB] List Results Not Working
I'm trying to list the results of a query, but I keep getting the following error: Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING' I must be missing something because I can't find what's causing the parse error. Any thoughts? $db = @mysql_select_db($db_name, $connection) or die(mysql_error()); $display_calls_sql = SELECT CallID,CallDateTime,CallSubject,CallStatus FROM calls WHERE ContactID = $ContactID; $display_calls_result = @mysql_query($display_calls_sql,$connection) or die(mysql_error()); $numrows = mysql_num_rows($display_calls_result); if ($numrows0) { while ($list = mysql_fetch_array($display_calls_result)){ echo .$list[CallID]. .$list[CallDateTime]. a href=\display_call.php?ContactID=$ContactID\ .$list[CallSubject]. /a .$list[CallStatus]. brbr; }} -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP-DB] Re: UPDATE Not Updating
I echoed out the $update_contact_sql and I'm getting FirstName='Value', etc. WHERE ContactID='' There is no value in ContactID. I've changed the double quotes to single quotes and dropped the quotes all together with $ContactID. I ran the query in MySQL client and gave the ContactID a value which worked fine. I'm not sure why the query string is not passing the value. Steve Fitzgerald [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... I belive this UPDATE should work, but it isn't. I get no errors. I have also tried using FieldName= '$Fieldname', but that does not seem to work either. $table_name = contacts; $update_contact_sql = UPDATE $table_name SET FirstName =\$FirstName\, LastName = \$LastName\, Title = \$Title\, WorkPhone = \$WorkPhone\, HomePhone = \$HomePhone\, Mobile = \$Mobile\, EmailName = \$EmailName\, Birthday = \$Birthday\ WHERE ContactID = \$ContactID\ ; $result = @mysql_query($update_contact_sql, $connection) or die (Couldn't execute query.); -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP-DB] Permissions
I'm trying to build a menu page that builds links based upon specified permissions that are associated with a username or userid. I figure it might be best to associate individual privleges to specific menu items within the usertable (using checkboxes, etc). then building the menu based upon the values of those priveleges. However, I'm not sure of the mechanics to implement such a system. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP-DB] Re: SQL Error
Steve Fitzgerald [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... I keep getting the following SQL error: The last fieldname is CompanyID not ContactID. You have an error in your SQL syntax near ')' at line 14 Line 14 is: '$FirstName', so the error must correspond to a different part of the code. Any ideas? $add_contact_sql = INSERT INTO $table_name (ContactID, FirstName, LastName, Title, WorkPhone, HomePhone,Mobile,EmailName,Birthday,CompanyID) VALUES ('', '$FirstName', '$LastName', '$Title', '$WorkPhone', '$HomePhone', '$Mobile', '$EmailName', '$Birthday', '$CompanyID', //this is actually CompanyID not ContactD ); $result = @mysql_query($add_contact_sql, $connection) or die (mysql_error()); ? -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP-DB] SQL Error
I keep getting the following SQL error: You have an error in your SQL syntax near ')' at line 14 Line 14 is: '$FirstName', so the error must correspond to a different part of the code. Any ideas? $add_contact_sql = INSERT INTO $table_name (ContactID, FirstName, LastName, Title, WorkPhone, HomePhone,Mobile,EmailName,Birthday,CompanyID) VALUES ('', '$FirstName', '$LastName', '$Title', '$WorkPhone', '$HomePhone', '$Mobile', '$EmailName', '$Birthday', '$ContactID', ); $result = @mysql_query($add_contact_sql, $connection) or die (mysql_error()); ? -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP-DB] INSERT Won't Insert
This should be a simple insert. I must be missing something because I keep getting: Couldn't execute query. What am I missing? ? error_reporting(15); $db_name = dbname; $table_name=company; $connection = @mysql_connect(servname,username, password)or die (Couldn't connect.); $db = @mysql_select_db($db_name, $connection) or die (Couldn't select database.); $add_co_sql = INSERT INTO $table_name (CompanyID, CompanyName, Address, City, StateorProvince, PostalCode,Region,Country,WebSite) VALUES (\\, \$CompanyName\,\$Address\,\$City\,\$StateorProvince\,\$PostalCode\ ,\$Region\,\$Country\,\$WebSite\ ; $result = @mysql_query($add_co_sql, $connection) or die (Couldn't execute query.); ? -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP-DB] Avoiding Multiple IDs
What is the best method for avoiding multiple ids for the same information. For example: I have a table name company that has unique ids. The CompanyID are tied to a table name contacts which have unique ids (ContactID). The problem seems to be that if I add a contact with an existing CompanyName then I will get multiple ids for the same CompanyName. I've considered using a drop-down menu for CompanyName when adding/modifying contacts, but it seems as if I might run into the same problem of multiple ids. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP-DB] UPDATE Not Updating
I belive this UPDATE should work, but it isn't. I get no errors. I have also tried using FieldName= '$Fieldname', but that does not seem to work either. $table_name = contacts; $update_contact_sql = UPDATE $table_name SET FirstName =\$FirstName\, LastName = \$LastName\, Title = \$Title\, WorkPhone = \$WorkPhone\, HomePhone = \$HomePhone\, Mobile = \$Mobile\, EmailName = \$EmailName\, Birthday = \$Birthday\ WHERE ContactID = \$ContactID\ ; $result = @mysql_query($update_contact_sql, $connection) or die (Couldn't execute query.); -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP-DB] A Join Question
I'm trying to create a join statement that pulls out a CompanyName based on a given CompanyID that is tied to a specified ContactID. For example, if ContactID=1 then the corresponding CompanyName might be Smith, Inc. depending on what was entered. Here are the tables. table = Contacts FIELD | TYPE | ATTRIBUTES | NULL | DEFAULT | EXTRA | ContactID | INT(4) | UNSIGNEED | NO | AUTO_INCREMENT | Primary Key/Unique CompanyID | INT(4) | // more fields table = Company FIELD | TYPE | ATTRIBUTES | NULL | DEFAULT | EXTRA | CompanyID | INT(4) | UNSIGNEED | NO | AUTO_INCREMENT | Primary Key/Unique CompanyName | INT(4) | //more fields - What I have tried so far is: SELECT * FROM contacts,company WHERE contacts.CompanyID=$ContactID and companyID= $ContactID I've tried slightly other variations including: SELECT CompanyName,WebSite FROM $table_name1,$table_name2 WHERE contacts.CompanyID='$CompanyID' also, SELECT * FROM Contacts,Company WHERE Contacts.CompanyID=Company.CompanyID AND Contacts.CompanyID='$ContactID' With this I get an empty set. None of these seem to work. I'm obviously not doing the join right, but I'm not sure what I'm leaving out. Thanks. Steve -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP-DB] INSERT with a JOIN
I'm trying to create an INSERT statement that will change a field in one table based upon the id defined in another table. Here is what I tried: $sql1 = INSERT INTO $table_name1 (FirstName,LastName,WorkPhone, HomePhone,EmailName,Birthday) VALUES ('[$FirstName]','[$LastName]','[$WorkPhone]','[$HomePhone]','[$EmailName]',' [Birthday]') ; $sql2 = INSERT INTO $table_name2 (CompanyName,WebSite) VALUES ('[$CompanyName]','[$WebSite]') WHERE contacts ON company.CompanyID = contacts.CompanyID WHERE ContactID='$ContactID' ; $result_1 = @mysql_query($sql1,$connection) or die(Couldn't execute query.); $result_2 = @mysql_query($sql2,$connection) or die(Couldn't execute query.); ? The goal is based upon a unique field call ContactID I want to be able to update the CompanyName associated with the ContactID. For example: ContactID=1 might have an associated CompanyName= Smith, Inc. What I want to do is UPDATE/INSERT a new CompanyName and have that reflected by changing the CompanyID associated with the ContactID. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP-DB] multiple table query error
I've figured out (with some help) how to query two tables at the same time. In order to get a corresponding CompanyName with a specified ContactID I created a SQL query that selects both tables ($table_name1,$table_name2) and then selects contacts.CompanyID = '$CompanyID'. The result is a match for data in the contacts table, but the data from the company table is the same no matter which ContactID I select. I have two CompanyNames (with unique CompanyID) and two separate contacts each one having a different CompanyID associated. What am I doing wrong? Steve ? error_reporting(5); $db_name = crm; $table_name1= contacts; $table_name2= company; $connection = @mysql_connect(, , ) or die(Couldn't connect.); $db = @mysql_select_db($db_name, $connection) or die(Couldn't select database.); $chk_id = SELECT ContactID FROM $table_name1 WHERE ContactID = $ContactID; $chk_id_res = @mysql_query($chk_id,$connection) or die(Couldn't execute query.); $chk_id_num = mysql_num_rows($chk_id_res); $sql1 = SELECT FirstName, LastName,WorkPhone, HomePhone, EmailName, Birthday FROM $table_name1 WHERE ContactID = '$ContactID' ; $sql2 = SELECT CompanyName,WebSite FROM $table_name1,$table_name2 WHERE contacts.CompanyID='$CompanyID' ; $result_1 = @mysql_query($sql1,$connection) or die(Couldn't execute query.); $result_2 = @mysql_query($sql2,$connection) or die(Couldn't execute query.); while ($row = mysql_fetch_array($result_1)) { $FirstName = $row['FirstName']; $LastName = $row['LastName']; $WorkPhone = $row['WorkPhone']; $HomePhone = $row['HomePhone']; $EmailName = $row['EmailName']; $Birthday = $row['Birthday']; } while ($row = mysql_fetch_array($result_2)) { $CompanyName = $row['CompanyName']; $WebSite = $row['WebSite']; } ? -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP-DB] 2 Tables- 1 Insert Problem
I'm trying to insert data into two separate tables using 1 INSERT. The code below represents a first crack at it, but I can't seem to figure out how to get this to work properly. Thanks. Steve ? $db_name=testDB; $table_name1 = my_contacts; $table_name2= company; $connection = @mysql_connect (,,or die (Couldn't connect.); $db = @mysql_select_db($db_name, $connection) or die (Couldn't select database.); $sql_1 = INSERT INTO $table_name1 (id,fname,lname,address1,address2,address3,postcode,country,prim_tel,sec_tel ,email,birthday) VALUES (\\, \$fname\,\$lname\,\$address1\,\$address2\,\$address3\,\$postcode\ , \$country\,\$prim_tel\,\$sec_tel\,\$email\,\$birthday\) ; $sql_2 = INSERT INTO $table_name2 WHERE my_contacts.company=$companyid (companyname,website) VALUES (\\, \$companyname\,\$website\) ; $result = @mysql_query ($sql_1,$sql_2,$connection) or die (Couldn't execute query.); ? -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP-DB] Search Query
I'm trying to build a search query that will allow users to search (via a textbox) different tables. For example, I have a table name contacts with columns ContactID, FirstName, LastName, and Active. I want to be able to search for John Smith or Smith where Active=yes (as opposed to Active=no which would indicate the contact is no longer active). I would then like to have the result(s) to have a link to their respective ContactID. I don't think this is that difficult, but I'm having difficulty applying the SELECT statement with the text box. Any help would be greatly appreciated. Steve Fitzgerald -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]