Jump to content

help in php mysql


mplayer

Recommended Posts

Im really new to php and mysql, and I have been messing around with phpmaker for a few days.  I am creating a simple event calendar, but not using the actual "calendar" just "listing" the data.  My database consists below:

 

Database;

 

event_id` int(11) NOT NULL auto_increment,

  `event_status` enum('Yes','No') NOT NULL default 'No',

  `event_category` varchar(100) NOT NULL default '',

  `event_date` date NOT NULL default '0000-00-00',

  `event_title` varchar(50) NOT NULL default '',

  `event_desc` text,

  PRIMARY KEY  (`event_id`)

) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=4 ;

 

basically, I have my scripts to add, edit delete, but some things I need to accomplish, I cant.

 

I would like to set this up so when I have a user who enters information, it will go under the status as pending (database "No"), and email the admin.  Once manually approved, the record would be set to Yes. During the pending status, I do not want the record to show on the listing view, but only show once its status has been changed to yes. 

 

I hope I made sense with this, can anyone assist?

 

 

Link to comment
Share on other sites

im trying to create a section of my database/script so when users enter data into a form, it will go into a hold status before going public. Once this happens, the admin can manually approve the record before it is made public. Im not sure how to create this.

 

Here is my add page.

 

<?php 
session_start();
ob_start();
?>
<?php
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); // Always modified
header("Cache-Control: private, no-store, no-cache, must-revalidate"); // HTTP/1.1 
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache"); // HTTP/1.0
?>
<?php include ("ewconfig.php") ?>
<?php include ("db.php") ?>
<?php include ("eventsinfo.php") ?>
<?php include ("advsecu.php") ?>
<?php include ("phpmkrfn.php") ?>
<?php include ("ewupload.php") ?>
<?php

// Initialize common variables
$x_num = NULL;
$ox_num = NULL;
$z_num = NULL;
$ar_x_num = NULL;
$ari_x_num = NULL;
$x_numList = NULL;
$x_numChk = NULL;
$cbo_x_num_js = NULL;
$x_category = NULL;
$ox_category = NULL;
$z_category = NULL;
$ar_x_category = NULL;
$ari_x_category = NULL;
$x_categoryList = NULL;
$x_categoryChk = NULL;
$cbo_x_category_js = NULL;
$x_title = NULL;
$ox_title = NULL;
$z_title = NULL;
$ar_x_title = NULL;
$ari_x_title = NULL;
$x_titleList = NULL;
$x_titleChk = NULL;
$cbo_x_title_js = NULL;
$x_ondate = NULL;
$ox_ondate = NULL;
$z_ondate = NULL;
$ar_x_ondate = NULL;
$ari_x_ondate = NULL;
$x_ondateList = NULL;
$x_ondateChk = NULL;
$cbo_x_ondate_js = NULL;
$x_url = NULL;
$ox_url = NULL;
$z_url = NULL;
$ar_x_url = NULL;
$ari_x_url = NULL;
$x_urlList = NULL;
$x_urlChk = NULL;
$cbo_x_url_js = NULL;
$x_contact = NULL;
$ox_contact = NULL;
$z_contact = NULL;
$ar_x_contact = NULL;
$ari_x_contact = NULL;
$x_contactList = NULL;
$x_contactChk = NULL;
$cbo_x_contact_js = NULL;
$x_details = NULL;
$ox_details = NULL;
$z_details = NULL;
$ar_x_details = NULL;
$ari_x_details = NULL;
$x_detailsList = NULL;
$x_detailsChk = NULL;
$cbo_x_details_js = NULL;
$x_eventstatus = NULL;
$ox_eventstatus = NULL;
$z_eventstatus = NULL;
$ar_x_eventstatus = NULL;
$ari_x_eventstatus = NULL;
$x_eventstatusList = NULL;
$x_eventstatusChk = NULL;
$cbo_x_eventstatus_js = NULL;
?>
<?php

// Load key from QueryString
$bCopy = true;
$x_num = @$_GET["num"];
if (($x_num == "") || (is_null($x_num))) $bCopy = false;

// Get action
$sAction = @$_POST["a_add"];
if (($sAction == "") || ((is_null($sAction)))) {
if ($bCopy) {
	$sAction = "C"; // Copy record
} else {
	$sAction = "I"; // Display blank record
}
} else {

// Get fields from form
$x_num = @$_POST["x_num"];
$x_category = @$_POST["x_category"];
$x_title = @$_POST["x_title"];
$x_ondate = @$_POST["x_ondate"];
$x_url = @$_POST["x_url"];
$x_contact = @$_POST["x_contact"];
$x_details = @$_POST["x_details"];
$x_eventstatus = @$_POST["x_eventstatus"];
}
$conn = phpmkr_db_connect(HOST, USER, PASS, DB, PORT);
switch ($sAction) {
case "C": // Copy record
	if (!LoadData($conn)) { // Load record
		$_SESSION[ewSessionMessage] = "No records found";
		phpmkr_db_close($conn);
		ob_end_clean();
		header("Location: eventslist.php");
		exit();
	}
	break;
case "A": // Add
	if (AddData($conn)) { // Add new record
		$_SESSION[ewSessionMessage] = "Add New Record Successful";
		phpmkr_db_close($conn);
		ob_end_clean();
		header("Location: eventslist.php");
		exit();
	}
	break;
}
?>
<?php include ("header.php") ?>
<script type="text/javascript">
<!--
EW_LookupFn = "ewlookup.php"; // ewlookup file name
EW_AddOptFn = "ewaddopt.php"; // ewaddopt.php file name

//-->
</script>
<script type="text/javascript" src="ewp.js"></script>
<script type="text/javascript">
<!--
EW_dateSep = "/"; // set date separator
EW_UploadAllowedFileExt = "gif,jpg,jpeg,bmp,png,doc,xls,pdf,zip"; // allowed upload file extension

//-->
</script>
<script type="text/javascript">
<!--
function EW_checkMyForm(EW_this) {
if (EW_this.x_category && !EW_hasValue(EW_this.x_category, "TEXT")) {
if (!EW_onError(EW_this, EW_this.x_category, "TEXT", "Please enter required field - category"))
	return false;
}
if (EW_this.x_title && !EW_hasValue(EW_this.x_title, "TEXTAREA")) {
if (!EW_onError(EW_this, EW_this.x_title, "TEXTAREA", "Please enter required field - title"))
	return false;
}
if (EW_this.x_ondate && !EW_hasValue(EW_this.x_ondate, "TEXT")) {
if (!EW_onError(EW_this, EW_this.x_ondate, "TEXT", "Please enter required field - ondate"))
	return false;
}
if (!EW_checkusdate(EW_this.x_ondate.value)) {
if (!EW_onError(EW_this, EW_this.x_ondate, "TEXT", "Incorrect date, format = mm/dd/yyyy - ondate"))
	return false; 
}
if (EW_this.x_contact && !EW_hasValue(EW_this.x_contact, "TEXT")) {
if (!EW_onError(EW_this, EW_this.x_contact, "TEXT", "Please enter required field - contact"))
	return false;
}
if (EW_this.x_details && !EW_hasValue(EW_this.x_details, "TEXTAREA")) {
if (!EW_onError(EW_this, EW_this.x_details, "TEXTAREA", "Please enter required field - details"))
	return false;
}
if (EW_this.x_eventstatus && !EW_hasValue(EW_this.x_eventstatus, "RADIO")) {
if (!EW_onError(EW_this, EW_this.x_eventstatus, "RADIO", "Please enter required field - eventstatus"))
	return false;
}
return true;
}

//-->
</script>
<script type="text/javascript">
<!--
var EW_DHTMLEditors = [];

//-->
</script>
<p><span class="phpmaker">Add to TABLE: events<br><br><a href="eventslist.php">Back to List</a></span></p>
<form name="feventsadd" id="feventsadd" action="eventsadd.php" method="post" onSubmit="return EW_checkMyForm(this);">
<p>
<input type="hidden" name="a_add" value="A">
<?php
if (@$_SESSION[ewSessionMessage] <> "") {
?>
<p><span class="ewmsg"><?php echo $_SESSION[ewSessionMessage] ?></span></p>
<?php
$_SESSION[ewSessionMessage] = ""; // Clear message
}
?>
<table class="ewTable">
<tr>
	<td class="ewTableHeader"><span>category<span class='ewmsg'> *</span></span></td>
	<td class="ewTableAltRow"><span id="cb_x_category">
<input type="text" name="x_category" id="x_category" size="30" maxlength="20" value="<?php echo htmlspecialchars(@$x_category) ?>">
</span></td>
</tr>
<tr>
	<td class="ewTableHeader"><span>title<span class='ewmsg'> *</span></span></td>
	<td class="ewTableAltRow"><span id="cb_x_title">
<textarea cols="35" rows="4" id="x_title" name="x_title"><?php echo @$x_title; ?></textarea>
</span></td>
</tr>
<tr>
	<td class="ewTableHeader"><span>ondate<span class='ewmsg'> *</span></span></td>
	<td class="ewTableAltRow"><span id="cb_x_ondate">
<?php if (!(!is_null($x_ondate)) || ($x_ondate == "")) { $x_ondate = "mm/dd/yyyy";} // Set default value ?>
<input type="text" name="x_ondate" id="x_ondate" value="<?php echo FormatDateTime(@$x_ondate,6); ?>">
</span></td>
</tr>
<tr>
	<td class="ewTableHeader"><span>url</span></td>
	<td class="ewTableAltRow"><span id="cb_x_url">
<input type="text" name="x_url" id="x_url" size="30" maxlength="100" value="<?php echo htmlspecialchars(@$x_url) ?>">
</span></td>
</tr>
<tr>
	<td class="ewTableHeader"><span>contact<span class='ewmsg'> *</span></span></td>
	<td class="ewTableAltRow"><span id="cb_x_contact">
<input type="text" name="x_contact" id="x_contact" size="30" maxlength="100" value="<?php echo htmlspecialchars(@$x_contact) ?>">
</span></td>
</tr>
<tr>
	<td class="ewTableHeader"><span>details<span class='ewmsg'> *</span></span></td>
	<td class="ewTableAltRow"><span id="cb_x_details">
<textarea cols="35" rows="4" id="x_details" name="x_details"><?php echo @$x_details; ?></textarea>
</span></td>
</tr>
<tr>
	<td class="ewTableHeader"><span>eventstatus<span class='ewmsg'> *</span></span></td>
	<td class="ewTableAltRow"><span id="cb_x_eventstatus">
<?php if (!(!is_null($x_eventstatus)) || ($x_eventstatus == "")) { $x_eventstatus = "No";} // Set default value ?>
<?php echo RenderControl(1, 0, 5, 1); ?>
<input type="radio" name="x_eventstatus"<?php if (@$x_eventstatus == "Yes") { ?> checked<?php } ?> value="<?php echo htmlspecialchars("Yes"); ?>">
<?php echo "Yes"; ?>
<?php echo RenderControl(1, 0, 5, 2); ?>
<?php echo RenderControl(1, 1, 5, 1); ?>
<input type="radio" name="x_eventstatus"<?php if (@$x_eventstatus == "No") { ?> checked<?php } ?> value="<?php echo htmlspecialchars("No"); ?>">
<?php echo "No"; ?>
<?php echo RenderControl(1, 1, 5, 2); ?>
</span></td>
</tr>
</table>
<p>
<input type="submit" name="btnAction" id="btnAction" value="ADD">
</form>
<?php include ("footer.php") ?>
<?php
phpmkr_db_close($conn);
?>
<?php

//-------------------------------------------------------------------------------
// Function LoadData
// - Variables setup: field variables

function LoadData($conn)
{
global $x_num;
$sFilter = ewSqlKeyWhere;
if (!is_numeric($x_num)) return false;
$x_num =  (get_magic_quotes_gpc()) ? stripslashes($x_num) : $x_num;
$sFilter = str_replace("@num", AdjustSql($x_num), $sFilter); // Replace key value
$sSql = ewBuildSql(ewSqlSelect, ewSqlWhere, ewSqlGroupBy, ewSqlHaving, ewSqlOrderBy, $sFilter, "");
$rs = phpmkr_query($sSql,$conn) or die("Failed to execute query at line " . __LINE__ . ": " . phpmkr_error($conn) . '<br>SQL: ' . $sSql);
if (phpmkr_num_rows($rs) == 0) {
	$bLoadData = false;
} else {
	$bLoadData = true;
	$row = phpmkr_fetch_array($rs);

	// Get the field contents
	$GLOBALS["x_num"] = $row["num"];
	$GLOBALS["x_category"] = $row["category"];
	$GLOBALS["x_title"] = $row["title"];
	$GLOBALS["x_ondate"] = $row["ondate"];
	$GLOBALS["x_url"] = $row["url"];
	$GLOBALS["x_contact"] = $row["contact"];
	$GLOBALS["x_details"] = $row["details"];
	$GLOBALS["x_eventstatus"] = $row["eventstatus"];
}
phpmkr_free_result($rs);
return $bLoadData;
}
?>
<?php

//-------------------------------------------------------------------------------
// Function AddData
// - Add Data
// - Variables used: field variables

function AddData($conn)
{
global $x_num;
$sFilter = ewSqlKeyWhere;

// Check for duplicate key
$bCheckKey = true;
if ((@$x_num == "") || (is_null(@$x_num))) {
	$bCheckKey = false;
} else {
	$sFilter = str_replace("@num", AdjustSql($x_num), $sFilter); // Replace key value
}
if ($bCheckKey) {
	$sSqlChk = ewBuildSql(ewSqlSelect, ewSqlWhere, ewSqlGroupBy, ewSqlHaving, ewSqlOrderBy, $sFilter, "");
	$rsChk = phpmkr_query($sSqlChk, $conn) or die("Failed to execute query at line " . __LINE__ . ": " . phpmkr_error($conn) . '<br>SQL: ' . $sSqlChk);
	if (phpmkr_num_rows($rsChk) > 0) {
		$_SESSION[ewSessionMessage] = "Duplicate value for primary key";
		phpmkr_free_result($rsChk);
		return false;
	}
	phpmkr_free_result($rsChk);
}

// Field category
$theValue = (!get_magic_quotes_gpc()) ? addslashes($GLOBALS["x_category"]) : $GLOBALS["x_category"]; 
$theValue = ($theValue != "") ? " '" . $theValue . "'" : "NULL";
$fieldList["`category`"] = $theValue;

// Field title
$theValue = (!get_magic_quotes_gpc()) ? addslashes($GLOBALS["x_title"]) : $GLOBALS["x_title"]; 
$theValue = ($theValue != "") ? " '" . $theValue . "'" : "NULL";
$fieldList["`title`"] = $theValue;

// Field ondate
$theValue = ($GLOBALS["x_ondate"] != "") ? " '" . ConvertDateToMysqlFormat($GLOBALS["x_ondate"]) . "'" :  "'" . date("D, d M Y H:i:s") . "'";
$fieldList["`ondate`"] = $theValue;

// Field url
$theValue = (!get_magic_quotes_gpc()) ? addslashes($GLOBALS["x_url"]) : $GLOBALS["x_url"]; 
$theValue = ($theValue != "") ? " '" . $theValue . "'" : "NULL";
$fieldList["`url`"] = $theValue;

// Field contact
$theValue = (!get_magic_quotes_gpc()) ? addslashes($GLOBALS["x_contact"]) : $GLOBALS["x_contact"]; 
$theValue = ($theValue != "") ? " '" . $theValue . "'" : "NULL";
$fieldList["`contact`"] = $theValue;

// Field details
$theValue = (!get_magic_quotes_gpc()) ? addslashes($GLOBALS["x_details"]) : $GLOBALS["x_details"]; 
$theValue = ($theValue != "") ? " '" . $theValue . "'" : "NULL";
$fieldList["`details`"] = $theValue;

// Field eventstatus
$theValue = (!get_magic_quotes_gpc()) ? addslashes($GLOBALS["x_eventstatus"]) : $GLOBALS["x_eventstatus"]; 
$theValue = ($theValue != "") ? " '" . $theValue . "'" : "NULL";
$fieldList["`eventstatus`"] = $theValue;

// Inserting event
if (Recordset_Inserting($fieldList)) {

	// Insert
	$sSql = "INSERT INTO `events` (";
	$sSql .= implode(",", array_keys($fieldList));
	$sSql .= ") VALUES (";
	$sSql .= implode(",", array_values($fieldList));
	$sSql .= ")";	
	phpmkr_query($sSql, $conn) or die("Failed to execute query at line " . __LINE__ . ": " . phpmkr_error($conn) . '<br>SQL: ' . $sSql);
	$fieldList["`num`"] = phpmkr_insert_id($conn);
	$result = (phpmkr_affected_rows($conn) > 0);

	// Inserted event
	if ($result) Recordset_Inserted($fieldList);
} else {
	$result = false;
}
return $result;
}

// Inserting event
function Recordset_Inserting(&$newrs)
{

// Enter your customized codes here
return true;
}

// Inserted event
function Recordset_Inserted($newrs)
{
$table = "events";
}
?>

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.