Jump to content

Multipule drop down menus on an update page - How to omit unselected fields


barniegilly

Recommended Posts

Hi I have an update page with multipule drop down menus,  I am looking for a way to allow only the drop down menus that have been altered to be sent to the database.  One way was to add the following code, where the $type_id equals 0 then add nothing to the database.

 

	if ($type_id == 0)  
	{
	$type_id = "";
	}

 

However I am getting a syntex error with this,  if I enter a value into the $type_id it selects that fine.  eg.

 

	if ($type_id == 0)  
	{
	$type_id = "2";
	}

 

What is the right way to send nothing to the database?

 

Fuller code of the page is here

 

<?php require_once("includes/sessions.php"); ?>

<?php require_once("includes/connections.php"); ?>

<?php require_once("includes/functions.php"); ?>

<?php confirm_logged_in();?>

<?php usersid(); ?>

<?php find_selected_event();

  find_selected_region();

  ?>

<?php $selected_event = getevent_byid ($url_eventid);

  $orgdescrip = orgdescription($url_eventid);

  $leveldescrip = leveldescription($url_eventid);

  $typedescrip = typedescription($url_eventid);

  $champdescrip = champdescription($url_eventid);

  $disdescrip = disdescription($url_eventid);

  $venuedescrip = venuedescription($url_eventid);

  $statusdescrip = statusdescription($url_eventid);

?>

<?php if (!isset($new_event)) {$new_event = false;} ?>

<?php

// make sure the subject id sent is an integer

if (intval($_GET['url_eventid']) == 0) {

redirect_to('controlpanel.php');

}

 

include_once("includes/form_functions.inc.php");

 

// START FORM PROCESSING

// only execute the form processing if the form has been submitted

if (isset($_POST['submit'])) {

// initialize an array to hold our errors

$errors = array();

 

// perform validations on the form data

 

$required_fields = array('title');

$errors = array_merge($errors, check_required_fields($required_fields, $_POST));

 

$required_numberfields = array();

$errors = array_merge($errors, check_number_fields($required_numberfields, $_POST));

 

$fields_with_lengths = array();

$errors = array_merge($errors, check_max_field_lengths($fields_with_lengths, $_POST));

 

// clean up the form data before putting it in the database

 

 

$url_eventid = mysql_prep($_GET['url_eventid']);

$user_id = mysql_prep($_POST['user_id']);

$title = trim(mysql_prep($_POST['title']));

$event_details = mysql_prep($_POST['event_details']);

$type_id = mysql_prep($_POST['type_id']);

$champ_id = mysql_prep($_POST['champ_id']);

$dis_id = mysql_prep($_POST['dis_id']);

$org_id = mysql_prep($_POST['org_id']);

$venue_id = mysql_prep($_POST['ven_id']);

$level_id = mysql_prep($_POST['level_id']);

$status_id = mysql_prep($_POST['status_id']);

 

if ($type_id == 0) 

{

$type_id = "";

}

// Database submission only proceeds if there were NO errors.

if (empty($errors)) {

 

$sql = "UPDATE events SET \n"

. "title = '{$title}',\n"

. "event_details = '{$event_details}',\n"

    . "type_id = {$type_id},\n"

. "champ_id = {$champ_id},\n"

. "dis_id = {$dis_id},\n"

. "org_id = {$org_id},\n"

. "ven_id = {$venue_id},\n"

. "user_id = {$url_userid},\n"

. "level_id = {$level_id},\n"

. "status_id = {$status_id}\n"

. "WHERE event_id = {$url_eventid} \n"

. "LIMIT 1";

 

 

if ($result = mysql_query($sql, $connection)) {

// as is, $message will still be discarded on the redirect

$message = "The event was successfully updated.";

// get the last id inserted over the current db connection

$new_event_id = mysql_insert_id();

redirect_to("newevent.php");

} else {

$message = "I am sorry but the event could not be updated.";

$message .= "<br />" . mysql_error();

}

} else {

if (count($errors) == 1) {

$message = "There was 1 error in the form.";

} else {

$message = "There were " . count($errors) . " errors in the form.";

}

}

// END FORM PROCESSING

}

 

?>

 

<?php  /*THIS CODE WITH RETURN IN THE BROWSER THE URLS THAT ARE BEING

PULLED DOWN*/

 

if(empty($_GET))

    echo "No GET variables";

else

    print_r($_GET);

 

?>

<?php include("includes/header.inc.php"); ?>

<title>Horse Events</title>

<?php include_once("includes/meta.inc.php");?>

<?php include_once("includes/cssfavgoogle.inc.php");?>

<link href="css/adminpanel.css" rel="stylesheet" type="text/css" />

<style>

input[type=number] {

width:40px;

}

</style>

</head>

<body>

<div id="wrapper">

<div id="header">

<img src="images/horseevents_wheretogo.png" align="right" />

<?php require_once ("includes/adminmenu.inc.php"); ?>

   

</div>

   

    <div id="adminleft">

      <h2>YOUR UPCOMING EVENTS

      <?php echo "<a href=\"newevent.php?url_userid={$url_userid}\"><img src=\"images/pink/add_event.png\" align=\"right\" width=\"131\" height=\"19\" /></a>" ?></h2>     

    <table id="datetable" width="300" border="0" >

    <?php

  $event_users_set = get_upcomingeventsforuser ($url_userid);

  while ($eventid = mysql_fetch_array ($event_users_set)){

  echo"<tr class=\'date\'>";

  echo"<td>" . $eventid["stdate"] ."</td>";

  echo"<td><a href=\"editevent.php?url_userid={$url_userid}&url_eventid=". urlencode ($eventid['event_id']) . "\">". $eventid ['title'] . "</td>";

  echo"</tr></a>";

  }

?>

</table>

    <br />

          <h2>YOUR PAST EVENTS</h2>     

    <table id="datetable" width="300" border="0" >

    <?php

  $event_users_set = get_pasteventsforuser ($url_userid);

  while ($eventid = mysql_fetch_array ($event_users_set)){

  echo"<tr class=\'date\'>";

  echo"<td>" . $eventid["stdate"] ."</td>";

  echo"<td><a href=\"editevent.php?url_userid={$url_userid}&url_eventid=". urlencode ($eventid['event_id']) . "\">". $eventid ['title'] . "</td>";

  echo"</tr></a>";

  }

?>

</table>

    </div>

    <div id="admincontent">

    <span class="h1pln">Edit Your Event</span><a class="delete" href="deleteevent.php?url_eventid=<?php echo $url_eventid; ?>" onClick="return confirm('Are you sure you want to delete?')">Delete</a><br />

    <span class="h3pln">Please make sure you complete all the compulary fields<span class="compuls">*</span>.<br />

The more accurately you enter your event the more people will be able to then find it.  <br />

<br />

If there are any selections we do not currently have available please click here and I will add them to your drop down menus.</span>

    <?php if (!empty($message)) {echo "<p class=\"message\">" . $message . "</p>";} ?>

<?php if (!empty($errors)) { display_errors($errors); } ?>

<form id="newevent" action="editevent.php?url_eventid=<?php  echo urlencode ($selected_event ['event_id']); ?>" method="post">

      <table id="neweventdisplay" cellpadding="5" width="400" border="0">

  <tr>

  <td><input type="text" name="event_id"  value="<?php echo $url_eventid; ?>" /></td>

  <td><input type="text" name="user_id"  value="<?php echo $url_userid;  ?>" /></td>

  </tr>

  <tr>

    <td class="heading">Event Title</td>

    <td><input id="titleinput" name="title" type="text" value="<?php echo $selected_event ['title']; ?>" /><span class="compuls">*</span><span class="smalltext">Enter up to 36 characters</span></td>

  </tr>

  <tr>

  <td class="heading">Current Status</td>

  <td><?php echo  $statusdescrip ['status_description']; ?>

  <select name="status_id" >

    <?php

$status_set = findstatus();

$statuslist = mysql_fetch_assoc ($status_set);

?>

<?php

do {

?>  <option value="<?php echo $statuslist ['status_id']; ?>" ><?php echo $statuslist ['status_description']; ?></option>

<?php

} while ($statuslist = mysql_fetch_assoc ($status_set));

?></select>

    <span class="compuls">*</span></td>

  </tr>

      <tr>

    <td class="heading">Organiser</td>

    <td><?php echo  $orgdescrip ['org_name']; ?>

    <select name="org_id">

    <?php

$organisers_set = findorganisers();

$orglist = mysql_fetch_assoc ($organisers_set);

?>

<?php

do {

?>  <option value="<?php echo $orglist ['org_id']; ?>" ><?php echo $orglist ['org_name']; ?></option>

<?php

} while ($orglist = mysql_fetch_assoc ($organisers_set));

?></select></td>

  </tr>

    <tr>

    <td class="heading">Start Date</td>

    <td id="dateinput"><?php echo $selected_event ['stdate']; ?></td>

  </tr>

    <tr>

    <td class="heading">Type Of Event</td>

    <td><?php echo  $typedescrip ['type_description']; ?>

    <select name="type_id">

    <?php

$type_set = findtype();

$typelist = mysql_fetch_assoc ($type_set);

?>

<?php

do {

?>  <option value="<?php echo $typelist ['type_id']; ?>" ><?php echo $typelist ['type_description'], $typelist ['type_id']; ?></option>

<?php

} while ($typelist = mysql_fetch_assoc ($type_set));

?></select><span class="compuls">*</span></td>

  </tr>

  <tr>

    <td class="heading">Venue</td>

    <td><?php echo  $venuedescrip ['ven_name']; ?><select name="ven_id">

    <?php

$venues_set = findvenues();

$venuelist = mysql_fetch_assoc ($venues_set);

?>

<?php

do {

?>  <option value="<?php echo $venuelist ['ven_id']; ?>" ><?php echo $venuelist ['ven_name'], $venuelist ['ven_id']; ?></option>

<?php

} while ($venuelist = mysql_fetch_assoc ($venues_set));

?></select></td>

  </tr>

 

  <tr>

    <td class="heading">Discipline</td>

    <td><?php echo  $disdescrip ['dis_description']; ?><select name="dis_id">

    <?php

    $discipline_set = finddisciplines();

$dislist = mysql_fetch_assoc ($discipline_set);

?>

<?php

do {

?>  <option value="<?php echo $dislist ['dis_id']; ?>" ><?php echo $dislist ['dis_description'], $dislist ['dis_id']; ?></option>

<?php

} while ($dislist = mysql_fetch_assoc ($discipline_set));

?></select><span class="compuls">*</span></td>

  </tr>

  <tr>

    <td class="heading">Level</td>

    <td><?php echo  $leveldescrip ['level_description']; ?> <select name="level_id">

    <?php

$level_set = findlevels();

$levellist = mysql_fetch_assoc ($level_set);

?>

<?php

do {

?>  <option value="<?php echo $levellist ['level_id']; ?>" ><?php echo $levellist ['level_description'], $levellist ['level_id']; ?></option>

<?php

} while ($levellist = mysql_fetch_assoc ($level_set));

?></select></td>

  </tr>

    <tr>

    <td class="heading">Is This A Championship</td>

    <td><?php echo  $champdescrip ['champ_description']; ?><select name="champ_id">

    <?php

$championship_set = findchampionships();

$champlist = mysql_fetch_assoc ($championship_set);

?>

<?php

do {

?>  <option value="<?php echo $champlist ['champ_id']; ?>" ><?php echo $champlist ['champ_description'], $champlist ['champ_id']; ?></option>

<?php

} while ($champlist = mysql_fetch_assoc ($championship_set));

?></select></td>

  </tr>

  <tr>

    <td class="heading">Event Details</td>

    <td><textarea name="event_details" cols="45" rows="15" ><?php echo $selected_event ['event_details']; ?>  </textarea></td>

  </tr>

  <tr>

    <td class="heading">Upload Schedule</td>

    <td></td>

  </tr>

 

  <tr>

  <td></td>

  <td><input type="submit" name="submit" id="convert" value="Update Your Event"></td>

  </tr>

</table>

<a  class="delete" href="controlpanel.php">Cancel</a>

</form>

    </div>

    <div id="adminright">

    </div>

<br clear="all" />

<?php require("includes/lowerlistings.inc.php"); ?>

<?php require("includes/footer.inc.php"); ?>

</div><!--End of Wrapper-->

</body>

</html>

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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