Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <html>
- <head>
- <title>How To Insert Data Into MySQL db using form in php</title>
- </head>
- <body>
- <?php
- $hostname = "10.15.14.247";
- $db_user = "root"; // change to your database password
- $db_password = "master"; // change to your database password
- $database = "acesbd"; // provide your database name
- $db = mysql_connect($hostname, $db_user, $db_password);
- mysql_select_db($database,$db);
- echo"<form method=post action=''><input type=hidden name=todo value=search>";
- if($search_text != "" and $search_text != 'procura'){
- ?>
- <input type=text name=search_text value="<?php echo $_POST['search_text']; ?>"><input type=submit value=Search><br>
- <?php
- }
- else echo"<input type=text name=search_text value='procura' onFocus=\"this.value=''\"><input type=submit value=Search><br>";
- echo"<select name='dropdown'>";
- $sqlin = "SELECT US_ID, US_nome FROM unidades_saude ORDER BY US_nome";
- if($result = mysql_query($sqlin ,$db)) {
- echo"<option value=0>--seleccionar extensão--</option>";
- while ($row = mysql_fetch_array($result)){
- $field1=$row[0];
- $field2=$row[1];
- echo "<option value=$field1>$field2</option>";
- }
- echo"</select>";
- }else {
- echo "ERROR1: ".mysql_error();
- }
- echo"<br><input type=radio name=type value=any checked>Qualquer ocorrência <input type=radio name=type value=exact>Palavra exacta
- </form>";
- $columnsSelect = ("CON_Nome,
- TS_nome,
- US_nome,
- CON_Email,
- CON_Telefone,
- CON_Fax,
- CON_Ext_Tele,
- TS_ID,
- US_ID,
- CON_ID");
- $columnsSearch = array("CON_Nome",
- "TS_nome",
- "US_nome",
- "CON_Email",
- "CON_Telefone",
- "CON_Fax",
- "CON_Ext_Tele");
- $todo=$_POST['todo'];
- if(isset($todo) and $todo=="search"){
- $search_text=$_POST['search_text'];
- $type=$_POST['type'];
- $search_text=ltrim($search_text);
- $search_text=rtrim($search_text);
- if ($search_text == 'procura')
- $query="SELECT $columnsSelect FROM view_con_ts_us ORDER BY CON_ID ASC";
- //$query="SELECT US_nome FROM unidades_saude";
- else{
- switch ($type) {
- case "any":
- if ($dropdown == 0) {
- $kt=split(" ",$search_text);//Breaking the string to array of words
- // Now let us generate the sql
- while(list($key,$val)=each($kt)){
- if($val<>" " and strlen($val) > 0){
- $x = 0;
- while($columnsSearch[$x] != null){
- $q .= " $columnsSearch[$x] like '%$val%' or ";
- $x++;
- }
- }
- }// end of while
- $q=substr($q,0,(strlen($q)-3));
- // this will remove the last or from the string.
- $query="SELECT $columnsSelect FROM view_con_ts_us WHERE ($q) ORDER BY CON_ID ASC";
- }else{
- $kt=split(" ",$search_text);//Breaking the string to array of words
- // Now let us generate the sql
- while(list($key,$val)=each($kt)){
- if($val<>" " and strlen($val) > 0){
- $x = 0;
- while($columnsSearch[$x] != null){
- $q .= " $columnsSearch[$x] like '%$val%' or ";
- $x++;
- }
- }
- }// end of while
- $q=substr($q,0,(strlen($q)-3));
- // this will remove the last or from the string.
- $query="SELECT $columnsSelect FROM view_con_ts_us WHERE ($q) and US_ID = $dropdown ORDER BY CON_ID ASC";
- }
- break;
- case "exact":
- if ($dropdown == 0) {
- $query="SELECT $columnsSelect FROM view_con_ts_us WHERE CON_Nome = '$search_text' or
- TS_nome = '$search_text' or
- US_nome = '$search_text' or
- CON_Email = '$search_text' or
- CON_Telefone = '$search_text' or
- CON_Fax = '$search_text' or
- CON_Ext_Tele = '$search_text' ORDER BY CON_ID ASC";
- }else
- $query="SELECT $columnsSelect FROM view_con_ts_us WHERE (CON_Nome = '$search_text' or
- TS_nome = '$search_text' or
- US_nome = '$search_text' or
- CON_Email = '$search_text' or
- CON_Telefone = '$search_text' or
- CON_Fax = '$search_text' or
- CON_Ext_Tele = '$search_text') and US_ID = $dropdown ORDER BY CON_ID ASC";
- break;
- }
- } // end of if else based on type value
- echo $query;
- echo "<br><br>";
- if($result = mysql_query($query ,$db)){
- while($row = mysql_fetch_array($result)){
- ?>
- <table border="1" bgcolor="#CCFFCC" style="border-collapse: collapse; border-left-width:0; border-top-width:0; border-bottom-width:0" bordercolor="#FFFFFF" cellpadding="2" cellspacing="0" height="10" width="100%" style="table-layout:fixed"><tr>
- <td height=25 width="80px" bordercolor="#952500" style="border-style: solid; border-width: 1" bgcolor="#FFDDDD"><p class="corpo_tabela"><?php echo"$row[0]" ?></p></td>
- <td height=25 width="80px" bordercolor="#952500" style="border-style: solid; border-width: 1" bgcolor="#FFDDDD"><p class="corpo_tabela"><?php echo"$row[1]" ?></p></td>
- <td height=25 width="80px" bordercolor="#952500" style="border-style: solid; border-width: 1" bgcolor="#FFDDDD"><p class="corpo_tabela"><?php echo"$row[2]" ?></p></td>
- <td height=25 width="80px" bordercolor="#952500" style="border-style: solid; border-width: 1" bgcolor="#FFDDDD"><p class="corpo_tabela"><?php echo"$row[3]" ?></p></td>
- <td height=25 width="80px" bordercolor="#952500" style="border-style: solid; border-width: 1" bgcolor="#FFDDDD"><p class="corpo_tabela"><?php echo"$row[4]" ?></p></td>
- <td height=25 width="80px" bordercolor="#952500" style="border-style: solid; border-width: 1" bgcolor="#FFDDDD"><p class="corpo_tabela"><?php echo"$row[5]" ?></p></td>
- <td height=25 width="80px" bordercolor="#952500" style="border-style: solid; border-width: 1" bgcolor="#FFDDDD"><p class="corpo_tabela"><?php echo"$row[6]" ?></p></td>
- </tr></table>
- <?php
- }
- }else {
- echo "ERROR1: ".mysql_error();
- }
- }
- ?>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement