Forum Moderators: coopster
<table width="76%" border="0" cellpadding="2" cellspacing="0" class="maintextCopy">
<tr>
<td colspan="3" align="left"><em><strong>Event name: </strong></em></td>
</tr>
<tr>
<td colspan="3" align="left"><input name="Name" type="text" value="<?=$objU->Name?>" class="inputbox" onKeyDown="changeCSS(this, 'text');" size="35" maxlength="250"></td>
</tr>
Another option I've tried with it is this:
<table width="76%" border="0" cellpadding="2" cellspacing="0" class="maintextCopy">
<tr>
<td colspan="3" align="left"><em><strong>Event name: </strong></em></td>
</tr>
<tr>
<td colspan="3" align="left"><textarea name="Name" cols="60" rows="1" class="textareabox" value=<?=$objU->Name?>></textarea></td>
</tr>
Here's the function:
function insert_event($user_id=0)
{
$message= "";
$sql= "INSERT INTO tbl_events (Name)
VALUES ('".addslashes($this->Name)."')";
$res= @mysql_query($sql, $this->dblink);
if (!$res)
$message.= "Unable to add event, please try again later.<br>";
return $message;
}
Any help is greatly appreciated as I am still very new to this.
<td colspan="3" align="left"><textarea name="Name" cols="60" rows="1" class="textareabox" value="<?php echo $objU->Name; ?>" ></textarea></td>
I also assume the the insert event function gets the posted variables into its member variables. That something else you may want to check once the form is processed.
// Check posted var
echo $_POST['Name'];
Originally:
function insert_event($user_id=0)
{
$message= "";
$sql= "INSERT INTO tbl_events (Name)
VALUES ('".addslashes($this->Name)."')";
$res= @mysql_query($sql, $this->dblink);
if (!$res)
$message.= "Unable to add event, please try again later.<br>";
return $message;
}
New function:
function insert_event($user_id=0)
{
$message= "";
$sql= "INSERT INTO tbl_events (Name)
VALUES ('".addslashes($_POST[Name])."')";
$res= @mysql_query($sql, $this->dblink);
if (!$res)
$message.= "Unable to add event, please try again later.<br>";
return $message;
}
It seems to be working well. There are other places on the site where the $this-> seems to get things to post to the database though. Do you know when the appropriate time to use either $_POST or $this-> would be?
// eg: global scope
$foo_obj = new foo();
Then "Name" must be a member variable that is linked in someway to the $_POST['Name'] before it can be used.
eg:
class foo {
var $Name = '';
function __construct() {
if( isset($_POST['Name']) ) {
$this->Name = some_filter_func($_POST['Name']);
}
}
function insert_event($user_id=0) {
// Name is initialized
}
}
so once a foo instance is created them $foo_obj->Name can retrieve the Name variable contents because that is initialized during the constructor.