Page 1 of 1

Here's a tough one for ya! Try to follow along:

Posted: Thu Jan 29, 2009 7:16 pm
by affluent980
I have a database table in which i have leads with their LeadID as a primary key, and columns like name, phone, etc, and most importantly, the Revenue column. I am trying to set up my page so that i can edit the value in the revenue column for one lead at a time. This is the form on the page:

<?
/**
* If user is not logged in, then do not display anything.
* If user is logged in, then display the form to edit
* lead detail information.
*/
if($session->logged_in){
?>

<h1>Lead Detail Edit : <? echo $_GET['leadid']; ?></h1>
<?
if($form->num_errors > 0){
echo "<td><font size=\"2\" color=\"#ff0000\">".$form->num_errors." error(s) found</font></td>";
}
?>
<form action="process.php" method="POST">
<table align="left" border="1" cellspacing="0" cellpadding="3">


<tr>
<td>Revenue:</td>
<td><input type="text" name="Revenue" maxlength="50" value=" ">
</td>
<td><? echo $form->error("email"); ?></td>
</tr>
<tr><td colspan="2" align="right">
<input type="hidden" name="subdet" value="1">
<input type="submit" value="Edit Lead"></td></tr>
<tr><td colspan="2" align="left"></td></tr>
</table>
</form>

<?

/* Link back to main */
echo "<br>Back To [<a href=\"main.php\">Main</a>]<br>";

}
}

?>

This seems to be working fine. and it posts the value i put in the Revenue input and subdet to process.php which is here:

/* User submitted edit lead detail form */
else if(isset($_POST['subdet'])){
$this->procEditDetails();
}

Which tells it to go to procEditDetails on process.php which is here:

/**
* procEditDetails - Attempts to edit the lead details
*/
function procEditDetails(){
global $session, $form;
/* Account edit attempt */
$retval = $session->editDetails($_POST['Revenue']);

/* Account edit successful */
if($retval){
$_SESSION['leadedit'] = true;
header("Location: ".$session->referrer);
}
/* Error found with form */
else{
$_SESSION['value_array'] = $_POST;
$_SESSION['error_array'] = $form->getErrorArray();
header("Location: ".$session->referrer);
}
}

which passes Revenue to the function editDetails on session.php which is here:

/**
* editDetails - Attempts to edit the lead details
*
*/
function editDetails($subRevenue){
global $database, $form; //The database and form object
/* Change Revenue */
if($subRevenue){
$database->updateLeadDetails($this->Revenue,"Revenue",$subRevenue);
}

/* Success! */
return true;
}

Which passes i don't know what on to the function updateLeadDetails on database.php which is here:

/**
* updateLeadDetails - Updates a field, specified by the field
* parameter, in the leadid's row of the database.
*/
function updateLeadDetails($Revenue, $field, $value){
$q = "UPDATE ".TBL_Leads." SET ".$field." = '$value' WHERE LeadID = '$LeadID'";
return mysql_query($q, $this->connection);
}

And it passes everything back fine, with no errors, and in fact, confirms that update was successful, but it doesn't change the revenue value for that LeadID. Am i not passing on the right variables? Please help! If you need any more information, i will provide. This one has me stumped after 4 hours of trying to figure it out.

Re: Here's a tough one for ya! Try to follow along:

Posted: Thu Jan 29, 2009 7:21 pm
by Benjamin
Use code tags please.

Re: Here's a tough one for ya! Try to follow along:

Posted: Fri Jan 30, 2009 1:50 am
by infolock
First of all, your first set of code has one too many closing braces..


Secondly, try echo'ing out ALL QUERIES and make sure all your queries are being run.

Finally, put an OR DIE(MySQL_ERROR()) at the end of all mysql_query statements. see if it errors out for ya then.

Example:

Code: Select all

 
<?php
$sql = "SELECT * FROM table";
echo "<br />$sql<br />";
mysql_query($sq) OR DIE (MySQL_Error());
?>
 

Re: Here's a tough one for ya! Try to follow along:

Posted: Fri Jan 30, 2009 6:31 am
by mavieng
There is no variable name declared with $leadID inside your function. If you want to use value of $leadID declared outside the function then you should declare it as global inside your function before using it and you can also print the value of $q to check if you are executing correct query or not.

example:

Code: Select all

 
<?php
function updateLeadDetails($Revenue, $field, $value)
{
global $LeadID;
$q = "UPDATE TBL_Leads SET ".$field." = '$value' WHERE LeadID = '$LeadID'";
return mysql_query($q, $this->connection);
}
?>