Jump to content

agr8lemon

New Members
  • Posts

    5
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

agr8lemon's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Wow, Thank you. I was trying to do $Depart_ID = (int)$_POST['Depart_ID']; because it wanted to make sure it was an integer and my fingers and brain must be tired. Anyways, it works now thank you very much!
  2. Hello everyone, I know there are a lot of articles about inserting into joined tables, but they all seem to do with auto incrementing both Keys at the same time. Mine is different and I'm hoping someone can help. I have two tables with a PK/FK relationship Emp_tbl ---------- ID (PK, int, not null, autoinc) Depart_ID (FK, int not null) Depart_tbl ---------- Depart_ID(PK, int, not null, autoinc) On my form I have a drop down that pulls the data from B to a drop-down that creates the value of the dropdown the integer of Depart_ID as follows: $sql_depart="SELECT Depart_Name, Depart_ID, Depart_Facility FROM dbo.Depart_tbl WHERE Disabled = '0' ORDER BY Depart_Name ASC"; $departResult=odbc_exec($dept_conn, $sql_depart); $departOptions=""; while($departRows=odbc_fetch_array($departResult)){ $departId=$departRows["Depart_ID"]; $Departments=$departRows['Depart_Name']; $departOptions.="<OPTION VALUE=\"$departId\">".$Departments.'</option>'; } odbc_close($dept_conn); So what I want to happen is to insert the data data into the Emp_tbl along with the proper Depart_ID for Depart_tbl (Keep in mind I don't want to change the Depart_tbl at all, just grab the PK value of and put that into the Emp_tbl for the join). Then this is my insert page: $_POST['Depart_ID'] = (int)$Depart_ID; ///Define our insert $sql="INSERT INTO dbo.Emp_tbl (Emp_First, Emp_Last, Emp_Title, Emp_Phone, Emp_Cell, Emp_Pager, Emp_Fax, Depart_ID) VALUES ('$_POST[Emp_First]','$_POST[Emp_Last]','$_POST[Emp_Title]','$_POST[Emp_Phone]','$_POST[Emp_Cell]','$_POST[Emp_Pager]','$_POST[Depart_Fax]','$Depart_ID')"; ///Make the insert $result=odbc_exec($emp_conn, $sql); The error I get is: Warning: odbc_exec() [function.odbc-exec]: SQL error: [Microsoft][ODBC SQL Server Driver] The INSERT statement conflicted with the FOREIGN KEY constraint "FK_Emp_Info_Emp_Department". The conflict occurred in database "PhoneDir", table "dbo.Depart_tbl", column 'Depart_ID'., SQL state 23000 in SQLExecDirect in Does this make sense? Can anyone help me? Thank you!
  3. Thank you, I guess I got a little semi-colon happy That did not fix the issue however.
  4. Hello everyone. I have a page with 3 separate drop down choices. Search SHEC Departments Search SJCF Departments Search SHEC Employees I'd like to show the results of the search on the same page. I'm trying to determine what SQL query to run based on what SELECT button they push. I'm having a issue trying to use a switch with $_GET. Here is an example of what I have. Sorry if the code is sloppy, I've been trying a bunch of things and have not organized it yet. <?php require"../includes/dept_mssql.php"; //Connect to the Department database require"../includes/emp_mssql.php"; //Conect to the Employee database //show all errors error_reporting(E_ALL); ini_set('display_errors', '3') ?> <html> <head> </head> <body> <div align="center"> <h1> Hospital Phone Directory </h1> <hr /> </div> <div align=center> <h2> SHEC Department Search </h2> <form name=shec_depart action="<?php echo $_SERVER['PHP_SELF']; ?>" method="get"> <?php $sql_depart_shec="SELECT Name, Depart_ID, Facility FROM dbo.Depart_tbl WHERE Facility = 'SHEC' OR Facility = 'BOTH' ORDER BY Name ASC"; $shecResult=odbc_exec($dept_conn, $sql_depart_shec); $shecOptions=""; while($shecRows=odbc_fetch_array($shecResult)){ $shecId=$shecRows["Depart_ID"]; $shecDepartments=$shecRows['Name']; $shecOptions.="<OPTION VAULE=\"$shecId\">".$shecDepartments; } ?> <select name="shec-depart"> <OPTION VALUE=>SHEC Departments<?php echo $shecOptions ?> </SELECT> <input type="submit" name="Submit" value="Search" /> <input type="hidden" name="submitted" id="submitted" value="true" /> </form> </div> <div align=center> <h2>SJCF Department Search</h2> <form name=sjcf_depart action="<?php echo $_SERVER['PHP_SELF']; ?>" method="get"> <?php $sql_depart_sjcf="SELECT Name, Depart_ID, Facility FROM dbo.Depart_tbl WHERE Facility = 'SJCF' OR Facility = 'BOTH' ORDER BY Name ASC"; $sjcfResult=odbc_exec($dept_conn, $sql_depart_sjcf); $sjcfOptions=""; while($sjcfRows=odbc_fetch_array($sjcfResult)){ $sjcfId=$sjcfRows["Depart_ID"]; $sjcfDepartments=$sjcfRows['Name']; $sjcfOptions.="<OPTION VAULE=\"$sjcfId\">".$sjcfDepartments; } ?> <select name="sjcf-dept" STYLE="width: 275px"> <OPTION VALUE=>SJCF Departments<?php echo $sjcfOptions ?> </SELECT> <input type="submit" name="Submit" value="Search" /> <input type="hidden" name="submitted" id="submitted" value="true" /> </form> </div> <div align=center> <h2> SHEC Employee Search</h2> <form name=shec_emp action="<?php echo $_SERVER['PHP_SELF']; ?>" method="get"> <?php $sql_emp_shec="SELECT * FROM dbo.Emp_tbl WHERE Facility = 'SHEC' OR Facility = 'BOTH' ORDER BY FirstName ASC"; $result=odbc_exec($emp_conn, $sql_emp_shec); ?> <select name="shec-name" STYLE="width: 275px"> <OPTION VALUE=A>A</option> <OPTION VALUE=B>B</option> </SELECT> <input type="submit" name="Submit" value="Search" /> <input type="hidden" name="submitted" id="submitted" value="true" /> </form> <?php if($_GET['submitted'] == true) { switch ($_SERVER['QUERY_STRING']) { case "shec-dept"; echo "do some query"; break; case "sjcf-dept"; echo "Do another query"; break; case "shec-name"; echo "Do yet a different query"; break; defalut; echo "error"; } } else { echo 'Get is not set'; } odbc_close($dept_conn); odbc_close($emp_conn); ?> At the moment the page displays, however making a selection from the dropdowns and hitting the submit button does not display any of the switch echos. Any help would be wonderful!! Thank you!
  5. Hello everyone, I've been a reading this forum for sometime, but this is my first post. First of all, thank you to everyone who answers questions for those of us that are banging our heads on the wall. OK, so here is my question. I want to save the field that the user last used when doing a search. I have two files: header.php and index.php header.php <?php echo ' <a href="index.php"><img border="0" src="Home.png" width="120" height="19"></a> <a href="add.php"><img border="0" src="AddRecord.png" width="120" height="19"></a> <a href="printstrings.php"><img border="0" src="PrintStrings.png" width="120" height="19"></a> '; ?> index.php <head> <script src="sorttable.js" type="text/javascript"></script> <style type="text/css"> td { empty-cells: show; } html, body{ background-image:url(Back01.jpg); } </style> <link rel="stylesheet" type="text/css" href="ltn.css" /> </head> <div align="center"> <?php include("password_protect.php"); ?> <?php include 'header.php'; ?> </div> <div align="center"> <form name="form" action="index.php" method="get"> Search for <input type="text" name="q" /> in field <select name="field"> <option value="USERNAME">Username</option> <option value="PORT">Port and Controller</option> <option value="PRINTNAME">Print String</option> <option value="NTTLIVE">NTT Live</option> <option value="LOCATION">Location</option> <option value="TERMNAME">Termname</option> <option value="SERIALNO">Serial Number</option> <option value="IPADDRESS">IP Adress</option> <option value="NOTES">Notes</option> </select> <input type="submit" name="Submit" value="Search" /> </form> </div> <?php if (@$_GET['q']) { ///// Get the search variable from URL $var = @$_GET['q'] ; $trimmed = trim($var); //trim whitespace from the stored variable $field = $_GET['field']; ////// check for an empty string and display a message. if ($trimmed == "") { echo "<p>Please enter a search...</p>"; exit; } ///// check for a search parameter if (!isset($var)) { echo "<p>We dont seem to have a search parameter!</p>"; exit; } /////connect to database mysql_connect("localhost","phi","shhphi!"); //(host, username, password) /////specify database mysql_select_db("ltn") or die("Unable to select database"); //select which database we're using ///// Build SQL Query $query = "select * from practiceltn where $field like \"%$trimmed%\" order by $field"; // EDIT HERE and specify your table and field names for the SQL query $numresults=mysql_query($query); $numrows=mysql_num_rows($numresults); // If we have no results, offer a google search as an alternative if ($numrows == 0) { echo "<p>Sorry, your search: "" . $trimmed . "" returned zero results</p>"; } else { // get results $result = mysql_query($query) or die("Couldn't execute query"); // begin to show results set echo ' <table class="sortable" border="1" cellpadding="1" cellspacing="0"> <thead bgcolor="white"> <tr> <th>Edit</th> <th>User Name</th> <th>IP Address</th> <th>Computer Name</th> <th>Serial Number</th> <th>Make/Model</th> <th>Location</th> <th>Port</th> <th>NTT Live</th> <th>Printstring</th> <th>FAMIS</th> <th>Deploy Date</th> <th>Notes</th> </tr> </thead>'; echo '<tbody>'; $color="1"; // now you can display the results returned while ($row= mysql_fetch_array($result)) { // Convert GTWAY number to it's logical statement switch ($row['GTWY']) { case 0: $gateway = 'TSHEC'; break; case 1: $gateway = 'T1121D'; break; case 2: $gateway = 'T112B2'; break; case 3: $gateway = 'T112B3'; break; case 4: $gateway = 'T112B4'; break; default: $gateway = ''; break; } // Setup the alternating colors if($color==1){ echo " <tr bgcolor='#dbe7ed'> <td><a href='ltnupdate.php?id=".$row['LTN_ID']."'><img src='app_48.gif' align='center'></a></td> <td>".$row['USERNAME']."</td> <td> <a href='http://".$row['IPADDRESS'].":5800'</a>" .$row['IPADDRESS']."</td> <td>".$row['TERMNAME']."</td> <td>".$row['SERIALNO']."</td> <td>".$row['MAKE']." ". $row['MODEL']."</td> <td>".$row['LOCATION']."</td> <td>".$row['PORT']."</td> <td>".$row['NTTLIVE']."</td> <td>".$row['PRINTNAME']."</td> <td>".$gateway. $row['MIS1MIS2']."</td> <td>".$row['PROBDATE']."</td> <td>".$row['NOTES']."</td> </tr>"; $color="2"; } else { echo " <tr bgcolor='#9bbde0'> <td><a href='ltnupdate.php?id=".$row['LTN_ID']."'><img src='app_48.gif' align='center'></a></td> <td>".$row['USERNAME']."</td> <td> <a href='http://".$row['IPADDRESS'].":5800'</a>" .$row['IPADDRESS']."</td> <td>".$row['TERMNAME']."</td> <td>".$row['SERIALNO']."</td> <td>".$row['MAKE']." ". $row['MODEL']."</td> <td>".$row['LOCATION']."</td> <td>".$row['PORT']."</td> <td>".$row['NTTLIVE']."</td> <td>".$row['PRINTNAME']."</td> <td>".$gateway. $row['MIS1MIS2']."</td> <td>".$row['PROBDATE']."</td> <td>".$row['NOTES']."</td> </tr>"; $color="1"; } } echo "</tbody><table>"; } }; ?> What I'm looking for is when some searches for something on the index, and they click the Home link (called from header.php) that it will keep the last field that hey searched for. I hope I've explained this correctly and thanks for the help!!
×
×
  • 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.