Jump to content

search page problem


UD2008

Recommended Posts

Hi Guys, I know it's been a while since the last post, but I'm having a big problem.

 

I have a php page on which I can search and retrieve data from the mysql database and display it into different fields (this works), but when I want to update the database (I also have multiple checkboxes with different names), when I uncheck a checked checkbox and press submit, the change is not being made in the database.

 

Well here is the code of the search page:

<?php

  // Get the search variable from URL

  $var = @$_GET['search'];
  $trimmed = trim($var); //trim whitespace from the stored variable

if ($trimmed) {
// rows to return
$limit=10; 

//connect to your database ** EDIT REQUIRED HERE **
mysql_connect("host","username","password"); //(host, username, password)

//specify database ** EDIT REQUIRED HERE **
mysql_select_db("database") or die("Unable to select database"); //select which database we're using

// Build SQL Query  
$select = mysql_query("SELECT * FROM nbs_vmb_contacts WHERE nbs_vmb_group_id = '2' AND nbs_vmb_contact_name LIKE \"%$trimmed%\" OR nbs_vmb_zip LIKE \"%$trimmed%\""); 
// EDIT HERE and specify your table and field names for the SQL query
$data = mysql_fetch_array($select);
}
?>
<div id="left">
<div id="left_01">
<div id="toppage">
<h3><?php echo $tcm_label[8]; ?></h3>
</div>
<div style="margin:0px 1px 0px 1px">
  <form id="form_ins_contact" name="form_ins_contact" method="post" action="wijzigen.php">
    <table width="780" height="600" border="0" align="center" cellpadding="0" cellspacing="2">
      <tr>
        <td width="122" align="right"><strong><?php echo $tcm_label[54]; ?></strong></td>
        <td class="td_no_border">
        	<select name="nbs_vmb_group_id">
          		<option value="1">NBS</option>
        	</select>        
        </td>
        <td align="right"></td>
        <td class="td_no_border2"></td>
        <td width="192" align="right" class="td_no_border2"><input name="nbs_vmb_contact_id" type="hidden" size="10" value="<?php echo($data['nbs_vmb_contact_id']); ?>" /></td>
        <td class="td_no_border2"></td>
      </tr>
      <tr>
        <td align="right"><strong><?php echo $tcm_label[19]; ?></strong></td>
        <td width="75" class="td_no_border">
        	<select name="nbs_vmb_contact_aanhef">
        		<option value="m" <?php if($data['nbs_vmb_contact_aanhef'] == "m") echo "selected"; ?> >Dhr</option>
                <option value="v" <?php if($data['nbs_vmb_contact_aanhef'] == "v") echo "selected"; ?> >Mevr</option>
        	</select>        
        </td>
        <td class="td_no_border2"></td>
        <td class="td_no_border2"></td>
        <td class="td_no_border2"></td>
        <td class="td_no_border2"></td>
      </tr>
      <tr>
        <td align="right"><strong><?php echo $tcm_label[21]; ?></strong></td>
        <td colspan="3" class="td_no_border"><input name="nbs_vmb_contact_prechar" type="text" size="20" value="<?php echo($data['nbs_vmb_contact_prechar']); ?>" /></td>
        <td align="right"><strong><?php echo $tcm_label[22]; ?></strong></td>
        <td class="td_no_border"><input name="nbs_vmb_contact_name" type="text" size="45" value="<?php echo($data['nbs_vmb_contact_name']); ?>" /></td>
      </tr>
      <tr>
        <td align="right"><strong><?php echo $tcm_label[23]; ?></strong></td>
        <td colspan="3" class="td_no_border"><input name="nbs_vmb_contact_tussenv" type="text" size="15" value="<?php echo($data['nbs_vmb_contact_tussenv']); ?>" /></td>
        <td align="right"><strong><?php echo $tcm_label[24]; ?></strong></td>
        <td class="td_no_border"><input name="nbs_vmb_contact_sur" type="text" size="45" value="<?php echo($data['nbs_vmb_contact_sur']); ?>" /></td>
      </tr>
      <tr>
        <td align="right"><strong><?php echo $tcm_label[25]; ?></strong></td>
        <td colspan="3" class="td_no_border"><input name="nbs_vmb_address" type="text" size="55" value="<?php echo($data['nbs_vmb_address']); ?>" /></td>
      </tr>
      <tr>
      	<td align="right"><strong><?php echo $tcm_label[26]; ?></strong></td>
        <td colspan="3" class="td_no_border"><input name="nbs_vmb_number" type="text" size="15" value="<?php echo($data['nbs_vmb_number']); ?>" /></td>
        <td align="right"><strong><?php echo $tcm_label[27]; ?></strong></td>
        <td class="td_no_border" width="194"><input name="nbs_vmb_numberadd" type="text" size="15" value="<?php echo($data['nbs_vmb_numberadd']); ?>" /></td>
      </tr>
      <tr>
      	<td align="right"><strong><?php echo $tcm_label[28]; ?></strong></td>
        <td colspan="3" class="td_no_border"><input name="nbs_vmb_postbusnr" type="text" size="20" value="<?php echo($data['nbs_vmb_postbusnr']); ?>" /></td>
        <td align="right"><strong><?php echo $tcm_label[29]; ?></strong></td>
        <td class="td_no_border"><input name="nbs_vmb_zip" type="text" size="15" value="<?php echo($data['nbs_vmb_zip']); ?>" /></td>
      </tr>
      <tr>
        <td align="right"><strong><?php echo $tcm_label[30]; ?></strong></td>
        <td colspan="3" class="td_no_border"><input name="nbs_vmb_city" type="text" size="55" value="<?php echo($data['nbs_vmb_city']); ?>" /></td>
        <td align="right"><strong><?php echo $tcm_label[31]; ?></strong></td>
        <td class="td_no_border"><input name="nbs_vmb_country" type="text" size="35" value="<?php echo($data['nbs_vmb_country']); ?>" /></td>
      </tr>
      <tr>
        <td align="right"><strong><?php echo $tcm_label[32]; ?></strong></td>
        <td colspan="3" class="td_no_border"><input name="nbs_vmb_phone" type="text" size="30" value="<?php echo($data['nbs_vmb_phone']); ?>" /></td>
        <td align="right"><strong><?php echo $tcm_label[33]; ?></strong></td>
        <td class="td_no_border"><input name="nbs_vmb_mobphone" type="text" size="30" value="<?php echo($data['nbs_vmb_mobphone']); ?>" /></td>
      </tr>
      <tr>
        <td align="right"><strong><?php echo $tcm_label[34]; ?></strong></td>
        <td colspan="3" class="td_no_border"><input name="nbs_vmb_emailadres" type="text" size="55" value="<?php echo($data['nbs_vmb_emailadres']); ?>" /></td>
        <td align="right"><strong><?php echo $tcm_label[35]; ?></strong></td>
        <td class="td_no_border"><input name="nbs_vmb_contact_day" type="text" maxlength="2" size="1" value="<?php echo($data['nbs_vmb_contact_day']); ?>" />
        <input name="nbs_vmb_contact_month" type="text" maxlength="2" size="1" value="<?php echo($data['nbs_vmb_contact_month']); ?>" />
        <input name="nbs_vmb_contact_year" type="text" maxlength="4" size="3" value="<?php echo($data['nbs_vmb_contact_year']); ?>" /></td>
      </tr>
      <tr>
        <td align="right"><strong><?php echo $tcm_label[36]; ?></strong></td>
        <td colspan="3" class="td_no_border"><input value="1" name="nbs_vmb_lid_vmb" type="checkbox" <?php if($data['nbs_vmb_lid_vmb'] == "1") echo "checked"; ?> /></td>
      </tr>
      <tr>
        <td align="right"><strong><?php echo $tcm_label[37]; ?></strong></td>
        <td colspan="3" class="td_no_border"><input value="1" name="nbs_vmb_selfburns" type="checkbox" <?php if($data['nbs_vmb_selfburns'] == "1") echo  "checked"; ?> /></td>
        <td align="right"><strong><?php echo $tcm_label[38]; ?></strong></td>
        <td class="td_no_border"><input name="nbs_vmb_year" type="text" size="15" value="<?php echo($data['nbs_vmb_year']); ?>" /></td>
      </tr>
      <tr>
        <td align="right"><strong><?php echo $tcm_label[39]; ?></strong></td>
        <td colspan="3" class="td_no_border"><select name="nbs_vmb_relativeto">
        	<option selected="selected">Selecteer relatie</option>
            <option id="Relatie" <?php if($data['nbs_vmb_relativeto'] == "Relatie") echo "selected"; ?> >Relatie</option>
            <option id="Ouder" <?php if($data['nbs_vmb_relativeto'] == "Ouder") echo "selected"; ?> >Ouder</option>
            <option id="Broer/zus" <?php if($data['nbs_vmb_relativeto'] == "Broer/zus") echo "selected"; ?> >Broer/zus</option>
            <option id="Familie" <?php if($data['nbs_vmb_relativeto'] == "Familie") echo "selected"; ?> >Familie</option>
            <option id="Vriend" <?php if($data['nbs_vmb_relativeto'] == "Vriend") echo "selected"; ?> >Vriend</option>
          </select></td>
      </tr>
       <tr>
        <td align="right"><strong><?php echo $tcm_label[40]; ?></strong></td>
        <td colspan="3" class="td_no_border"><input value="1" name="nbs_vmb_profrelatie" type="checkbox" <?php if($data['nbs_vmb_profrelatie'] == "1") echo "checked"; ?> /></td>
        <td align="right"><strong><?php echo $tcm_label[41]; ?></strong></td>
        <td class="td_no_border"><input value="1" name="nbs_vmb_psychonet" type="checkbox" <?php if($data['nbs_vmb_psychonet'] == "1") echo "checked"; ?> /></td>
      </tr>
      <tr>
      	<td align="right"><strong><?php echo $tcm_label[42]; ?></strong></td>
        <td colspan="3" class="td_no_border"><input value="1" name="nbs_vmb_revalinet" type="checkbox" <?php if($data['nbs_vmb_revalinet'] == "1") echo "checked"; ?> /></td>
        <td align="right"><strong><?php echo $tcm_label[43]; ?></strong></td>
        <td class="td_no_border"><input value="1" name="nbs_vmb_reintegranet" type="checkbox" <?php if($data['nbs_vmb_reintegranet'] == "1") echo "checked"; ?> /></td>
      </tr>
      <tr>
        <td align="right"><strong><?php echo $tcm_label[44]; ?></strong></td>
        <td colspan="3" class="td_no_border"><input value="1" name="nbs_vmb_juridischehulp" type="checkbox" <?php if($data['nbs_vmb_juridischehulp'] == "1") echo "checked"; ?> /></td>
      </tr>
      <tr>
        <td align="right"><strong><?php echo $tcm_label[45]; ?></strong></td>
        <td colspan="3" class="td_no_border"><input value="1" name="nbs_vmb_nomail" type="checkbox" <?php if($data['nbs_vmb_nomail'] == "1") echo "checked"; ?> /></td>
      </tr>
      <tr>
        <td align="right"><strong><?php echo $tcm_label[46]; ?></strong></td>
        <td colspan="3" class="td_no_border"><textarea name="nbs_vmb_comments" cols="30" rows="6"><?php echo($data['nbs_vmb_comments']); ?></textarea></td>
        <td></td>
        <td class="td_no_border2"><img src="../images/intra icon.png" width="96" height="96" /></td>
      </tr>
    </table>
    <table width="281" border="0" align="center" cellpadding="0" cellspacing="2">
      <tr>
        <td align="center" class="td_no_border2" nowrap="nowrap">
        	<input type="submit" class="buttons" value="Wijzig Contact" />
        </td>
      </tr>
    </table>
  </form>
  </div>
</div>
</div>

 

And here the code to update:

<?php
$db = mysql_connect("host", "username", "password") or die("Could not connect.");
if(!$db) 
die("no db");
if(!mysql_select_db("database",$db))
	die("No database selected.");

if(isset($_POST['submit'])) {
   $nbs_vmb_contact_id=$_POST['nbs_vmb_contact_id'];
   $nbs_vmb_group_id=$_POST['nbs_vmb_group_id'];
   $nbs_vmb_shared=$_POST['nbs_vmb_shared'];
   $nbs_vmb_contact_aanhef=$_POST['nbs_vmb_contact_aanhef'];
   $nbs_vmb_contact_prechar=$_POST['nbs_vmb_contact_prechar'];
   $nbs_vmb_contact_name=$_POST['nbs_vmb_contact_name'];
   $nbs_vmb_contact_tussenv=$_POST['nbs_vmb_contact_tussenv'];
   $nbs_vmb_contact_sur=$_POST['nbs_vmb_contact_sur'];
   $nbs_vmb_address=$_POST['nbs_vmb_address']; 
   $nbs_vmb_number=$_POST['nbs_vmb_number'];
   $nbs_vmb_numberadd=$_POST['nbs_vmb_numberadd'];
   $nbs_vmb_postbusnr=$_POST['nbs_vmb_postbusnr'];
   $nbs_vmb_zip=$_POST['nbs_vmb_zip'];
   $nbs_vmb_city=$_POST['nbs_vmb_city'];
   $nbs_vmb_country=$_POST['nbs_vmb_country']; 
   $nbs_vmb_phone=$_POST['nbs_vmb_phone'];
   $nbs_vmb_mobphone=$_POST['nbs_vmb_mobphone'];
   $nbs_vmb_emailadres=$_POST['nbs_vmb_emailadres'];
   $nbs_vmb_contact_date=$_POST['nbs_vmb_contact_date'];
   $nbs_vmb_lid_vmb = isset($_POST['nbs_vmb_lid_vmb']) ? "1" : "0";
   $nbs_vmb_selfburns = ($_POST['nbs_vmb_selfburns'] == 1) ? "1" : "0"; 
   $nbs_vmb_year=$_POST['nbs_vmb_year'];
   $nbs_vmb_relativeto=$_POST['nbs_vmb_relativeto'];
   $nbs_vmb_profrelatie = ($_POST['nbs_vmb_profrelatie'] == 1) ? "1" : "0";
   $nbs_vmb_psychonet = ($_POST['nbs_vmb_psychonet'] == 1) ? "1" : "0";
   $nbs_vmb_revalinet = ($_POST['nbs_vmb_revalinet'] == 1) ? "1" : "0";
   $nbs_vmb_reintegranet = ($_POST['nbs_vmb_reintegranet'] == 1) ? "1" : "0"; 
   $nbs_vmb_juridischehulp = ($_POST['nbs_vmb_juridischehulp'] == 1) ? "1" : "0";
   $nbs_vmb_nomail = ($_POST['nbs_vmb_nomail'] == 1) ? "1" : "0";
   $nbs_vmb_comments=$_POST['nbs_vmb_comments'];
   
   $query = mysql_query("UPDATE nbs_vmb_contacts SET nbs_vmb_group_id = '$nbs_vmb_group_id', nbs_vmb_shared = '$nbs_vmb_shared', nbs_vmb_contact_aanhef = '$nbs_vmb_contact_aanhef', nbs_vmb_contact_prechar = '$nbs_vmb_contact_prechar', nbs_vmb_contact_name = '$nbs_vmb_contact_name', nbs_vmb_contact_tussenv = '$nbs_vmb_contact_tussenv', nbs_vmb_contact_sur = '$nbs_vmb_contact_sur', nbs_vmb_address = '$nbs_vmb_address', nbs_vmb_number = '$nbs_vmb_number', nbs_vmb_numberadd = '$nbs_vmb_numberadd', nbs_vmb_postbusnr = '$nbs_vmb_postbusnr', nbs_vmb_zip = '$nbs_vmb_zip', nbs_vmb_city = '$nbs_vmb_city', nbs_vmb_country = '$nbs_vmb_country', nbs_vmb_phone = '$nbs_vmb_phone', nbs_vmb_mobphone = '$nbs_vmb_mobphone', nbs_vmb_emailadres = '$nbs_vmb_emailadres', nbs_vmb_contact_date = '$nbs_vmb_contact_date', nbs_vmb_lid_vmb = '$nbs_vmb_lid_vmb', nbs_vmb_selfburns = '$nbs_vmb_selfburns', nbs_vmb_year = '$nbs_vmb_year', nbs_vmb_relativeto = '$nbs_vmb_relativeto', nbs_vmb_profrelatie = '$nbs_vmb_profrelatie', nbs_vmb_psychonet = '$nbs_vmb_psychonet', nbs_vmb_revalinet = '$nbs_vmb_revalinet', nbs_vmb_reintegranet = '$nbs_vmb_reintegranet', nbs_vmb_juridischehulp = '$nbs_vmb_juridischehulp', nbs_vmb_nomail = '$nbs_vmb_nomail', nbs_vmb_comments = '$nbs_vmb_comments' WHERE nbs_vmb_contact_id = '$nbs_vmb_contact_id'"); 
    {       
      echo('<SCRIPT> 
           alert("Gegevens van ' .$nbs_vmb_contact_name. ' zijn bijgewerkt."); location.href("index.php");</SCRIPT>');
      }
}
?>

 

Something is not right, but I can't lay my finger on it.

 

Please help, I am in a time limit.

 

Thanks.

Link to comment
https://forums.phpfreaks.com/topic/173659-search-page-problem/
Share on other sites

Hey,

 

  Checkboxes do not send any value when you uncheck them...  My guess is some of the checkboxes work, and some do not.  If you use isset, instead of == 1, it may work better (but I don't know for sure):    $nbs_vmb_lid_vmb = isset($_POST['nbs_vmb_lid_vmb']) ? "1" : "0";

 

 

Link to comment
https://forums.phpfreaks.com/topic/173659-search-page-problem/#findComment-917071
Share on other sites

Archived

This topic is now archived and is closed to further replies.

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