PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
facets
Forum Contributor
Posts: 273 Joined: Wed Apr 13, 2005 1:53 am
Location: Detroit
Post
by facets » Thu Aug 11, 2005 8:54 am
Hi All,
I'm having some trouble calling this function to update the DB.
Can anyone give me any pointers? All it seems to be doing is resetting / reloading the page and giving errors :
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource
tia, Will
Code: Select all
function updateSummary() {
if(empty($summaryId)) error_message('Empty Summary!');
$field_str .= " paperCategoryId = '$paperCategoryId', ";
$field_str .= " colloPaperName = '$colloPaperName', ";
$field_str .= " manufacturerName = '$manufacturerName', ";
$field_str .= " cpl = '$cpl', ";
$field_str .= " stockId = '$stockId', ";
$field_str .= " adhesiveId = '$adhesiveId', ";
$field_str .= " linerId = '$linerId', ";
$query = "UPDATE ausapapersummary SET $field_str WHERE summaryId = '$summaryId'";
$result = mysql_query($query);
if(!$result) error_message(sql_error());
$num_rows = mysql_affected_rows($link_id);
neophyte
DevNet Resident
Posts: 1537 Joined: Tue Jan 20, 2004 4:58 pm
Location: Minnesota
Post
by neophyte » Thu Aug 11, 2005 8:59 am
Code: Select all
$field_str .= " linerId = '$linerId', ";
Remove the comma from that line and give it a try.
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Thu Aug 11, 2005 9:14 am
your code doesn't set or bring in $summaryId either.
facets
Forum Contributor
Posts: 273 Joined: Wed Apr 13, 2005 1:53 am
Location: Detroit
Post
by facets » Thu Aug 11, 2005 9:16 am
still no joy there.
It appears that the data is being passed via $_POST as I can see the changes using the following code.
Code: Select all
echo '<pre>';
var_dump($_GET);
var_dump($_POST);
echo '</pre>';
But the change don't update in the DB. i'm using submit with the following code.
Code: Select all
switch($action) {
case "updateSummary": updateSummary(); break;
default: editSASummary(); break;
}
echo "<input type=\"submit\" name=\"updateSummary\" class=\"btn\" value=\"Edit Summary\">";
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Thu Aug 11, 2005 9:24 am
the fact remains, your function doesn't recieve the variables you are using.
facets
Forum Contributor
Posts: 273 Joined: Wed Apr 13, 2005 1:53 am
Location: Detroit
Post
by facets » Thu Aug 11, 2005 9:25 am
i think the submit button is working but I don;t believe the updateSummary function is being exectuted.
facets
Forum Contributor
Posts: 273 Joined: Wed Apr 13, 2005 1:53 am
Location: Detroit
Post
by facets » Thu Aug 11, 2005 9:26 am
sorry my mistake.. it should read more like this..
Code: Select all
$summaryId = isset($_GET['summaryId']) ? $_GET['summaryId'] : '';
$summaryId = $_POST['summaryId'];
$paperCategoryId = $_POST['paperCategoryId'];
$colloPaperName = $_POST['colloPaperName'];
$manufacturerName = $_POST['manufacturerName'];
$cpl = $_POST['cpl'];
$stockId = $_POST['stockId'];
$adhesiveId = $_POST['adhesiveId'];
$linerId = $_POST['linerId'];
if(empty($summaryId)) error_message('Empty Summary!');
$field_str .= " paperCategoryId = '$paperCategoryId', ";
$field_str .= " colloPaperName = '$colloPaperName', ";
$field_str .= " manufacturerName = '$manufacturerName', ";
$field_str .= " cpl = '$cpl', ";
$field_str .= " stockId = '$stockId', ";
$field_str .= " adhesiveId = '$adhesiveId', ";
$field_str .= " linerId = '$linerId', ";
$query = "UPDATE ausapapersummary SET $field_str WHERE summaryId = '$summaryId'";
$result = mysql_query($query);
if(!$result) error_message(sql_error());
$num_rows = mysql_affected_rows($link_id);
}
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Thu Aug 11, 2005 9:37 am
that doesn't make the variables available in the function. Functions has a difference scope of memory than outside of them. You have to pass variables in if they aren't superglobals. Read up on the global keyword, or function arguments.