Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
I want to add and delete the dates from the database. I have written a code snippet in PHP and it seems to transfer control fine but the values in the database are not getting changed ( niether addition nor deletion). I have attached the code snippet. Please anyone have a look at it and suggest me something . Really stuck with this problem from last two days.
I have written the following php code:Code: Select all
<?php
//Gets constants and database functions and executes anything else in page_start.php.
require( '../includes/page_start.php' );
//Uncomment this line if you need a database connection for this page.
//$g_db_connection = connect();
//Use this variable to include any file containing JavaScript that you wish to have placed in the HTML head section.
$javascript = '<script language="javascript" type="text/javascript" src="../includes/javascript/form_validator.js"></script>';
//These variables should be left as they are unless you wish to apply an alternate style sheet to this page.
$css = DEFAULT_CSS;
$ie_css = IE_CSS;
//Use these variables to add or modify META description and keywords specific to this page.
$meta_description = DEFAULT_META_DESC;
$meta_keywords = DEFAULT_META_KEYS;
//This variable is used in the cookie crumbs, as well as below for the rest of the title tag.
$page_name = 'Open House Dates';
//This variable is used to set the last portion of the HTML title tag.
$title_addendum = 'Prospective Students - ' . $page_name;
//This variable should be set to the path to the left navigation pane for this page. If no left navigation is to be used,
//leave it empty.
$left_nav = './includes/elements/prospective_navigation.inc';
//The remaining require statements must follow definition of the variables above.
//Change the header and footer require statements only if you wish to use a template other than the main template.
//NOTE: A special template exists for popup windows. Use includes/elements/popup_header.inc or includes/elements/popup_footer.inc
require( DEFAULT_HEADER );
?>
<div id="content">
<script Language="JavaScript">
function validateForm(thedateForm)
{
// Customize these calls for your form
// Start ------->
if (!validRequired(thedateForm.addate,"Add Date"))
return false;
if (!validRequired(thedateForm.deletedate,"Delete Date"))
return false;
if (!validRequired(thedateForm.category,"Category"))
return false;
// <--------- End
return true;
}
</script>
<form name="thedateForm" method="<?=$_POST?>" action="openhouse_date_submit.php" onsubmit="return validateForm( this )">
<table>
<tr>
<td colspan="2">
<p>
(Fields with <font color="red" size="3" valign="middle"><b>*</b></font> are required)
</p>
</td>
</tr>
<tr>
<td>
<font color="red" size="3"></font><strong>Add Date:</strong>
</td>
<td>
<input type="text" name="addate" size="20">
</td>
</tr>
<tr>
<td>
<font color="red" size="3"></font><strong>Delete Date:</strong>
</td>
<td>
<input type="text" name="deletedate" size="20">
</td>
</tr>
<tr>
<td>
<font color="red" size="3">*</font><strong>Category:</strong>
</td>
<td>
<select name="category">
<option value="">< Pick one ></option>
<option value="0">Fall Open Houses - 2006</option>
<option value="1">Spring Open Houses - 2007</option>
<option value="2">Transfer Days - 2007</option>
<option value="3">BS level Accepted Student Open Houses-2007</option>
</select>
</td>
</tr>
<tr>
<td colspan="2">
<input type="submit" value="Submit">
</td>
</tr>
</table>
</form>
</div>
<?php
require( DEFAULT_FOOTER );
?>
openhouse_data_submit.php looks like this:
<?php
//Gets constants and database functions and executes anything else in page_start.php.
require( '../includes/page_start.php' );
//Uncomment this line if you need a database connection for this page.
$g_db_connection = connect();
//Use this variable to include any file containing JavaScript that you wish to have placed in the HTML head section.
$javascript = '';
//These variables should be left as they are unless you wish to apply an alternate style sheet to this page.
$css = DEFAULT_CSS;
$ie_css = IE_CSS;
//Use these variables to add or modify META description and keywords specific to this page.
$meta_description = DEFAULT_META_DESC;
$meta_keywords = DEFAULT_META_KEYS;
//This variable is used in the cookie crumbs, as well as below for the rest of the title tag.
$page_name = 'Open House Dates';
//This variable is used to set the last portion of the HTML title tag.
$title_addendum = 'Prospective Students - ' . $page_name;
//This variable should be set to the path to the left navigation pane for this page. If no left navigation is to be used,
//leave it empty.
$left_nav = './includes/elements/prospective_navigation.inc';
//The remaining require statements must follow definition of the variables above.
//Change the header and footer require statements only if you wish to use a template other than the main template.
//NOTE: A special template exists for popup windows. Use includes/elements/popup_header.inc or includes/elements/popup_footer.inc
require( DEFAULT_HEADER );
?>
<div id="content">
<?php
error_reporting(E_ALL);
?>
<?php
if( isset( $_GET[ 'category' ], $_GET ['addate'], $_GET ['deletedate']) )
{
$addate = $_GET[ 'addate' ];
$deletedate = $_GET[ 'deletedate' ];
$category = $_GET[ 'category' ];
$query = "INSERT INTO dbo.ashishdate VALUES ('$category', '$addate') AND DELETE * FROM dbo.ashishdate WHERE category = '$category' AND date = '$deletedate'" ;
mssql_query($query);
//$result = db_query( "INSERT INTO dbo.ashishdate VALUES ($category, $addate) AND DELETE * FROM dbo.ashishdate WHERE category = $category AND date = $deletedate");
}
else if( isset( $_GET[ 'category' ], $_GET ['addate']) )
{
$addate = $_GET[ 'addate' ];
$category = $_GET[ 'category' ];
$query = "INSERT INTO dbo.ashishdate VALUES ('$category', '$addate')";
mssql_query($query);
//$result = db_query( "INSERT INTO dbo.ashishdate VALUES ($category, $addate)");
}
else if (isset( $_GET[ 'category' ], $_GET ['deletedate']) )
{
$deletedate = $_GET[ 'deletedate' ];
$category = $_GET[ 'category' ];
$query = "DELETE * FROM dbo.ashishdate WHERE category = '$category' AND date = '$deletedate'" ;
mssql_query($query);
//$result = db_query("DELETE * FROM dbo.ashishdate WHERE category = $category AND date = $deletedate");
?>
<?php
}
else
{
?>
<p>
You did not submit all the required information. Please go back and try again.
</p>
<?php
}
?>
</div>
<?php
require( DEFAULT_FOOTER );
?>feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]