Page 1 of 1

[SOLVED] MySQL UPDATE woes

Posted: Sat Aug 13, 2005 3:37 am
by facets
Hi All,

I'm banging my head on this one. Can any one point out my errors?
I'm not getting any errors in the apache logs etc.

The database will just not update

Code: Select all

<?php

include "../includes/functions.inc";
// Open connection to the database
mysql_connect("localhost", "materials", "materials")
or die("Failure to communicate with database");

mysql_select_db("materialsregister");

$action = isset($_GET['action']) ? $_GET['action'] : '';

if (isset($_GET['action']) ? $_GET['action'] : '') {
// Format the data

$summaryId = $_POST['summaryId'];
$paperCategoryId = $_POST['paperCategoryId'];
$colloPaperName = $_POST['colloPaperName'];
$manufacturerName = $_POST['manufacturerName'];
$cpl = $_POST['cpl'];

// Update values

$query = "UPDATE ausapapersummary SET paperCategoryId='$paperCategoryId', colloPaperName='$colloPaperName', manufacturerName='$manufacturerName', cpl='$cpl' WHERE summaryId = 122";

$result = mysql_query($query);

	if (mysql_affected_rows() == 1) {
		$success_msg = "<P>Your comment has been updated.</P>";
	} 
	else {
		error_log(mysql_error());
		$success_msg = "<P>Something went wrong.</P>";
	}
} 

else {
// Get the comment header and comment


	$summaryId = isset($_GET['summaryId']) ? $_GET['summaryId'] : '';
	$sql_query = mysql_query("SELECT * FROM ausapapersummary WHERE summaryId = 122");
	$query_data = mysql_fetch_array($sql_query); 

$colloPaperName = $query_data['colloPaperName'];
$manufacturerName = $query_data['manufacturerName'];
$cpl = $query_data['cpl'];

print "<html><title></title><head></head><body>";

echo "<form name=\"editSASummary\" action=\"".$_SERVER['PHP_SELF']."\" method=\"post\">\n";
echo "<input type=\"hidden\" name=\"action\" value=\"updateSummary\">";
echo "<input type=\"hidden\" name=\"summaryId\" value=$summaryId>";
echo "<table class=\"sorttable\">\n";

$second = array('Collo Paper Name','Manufactured Name','Computer Loopup Prefix');
$secondTitles = array('colloPaperName','manufacturerName','cpl');
$secondValues = array($colloPaperName,$manufacturerName,$cpl);
	
for($x = 0; $x<count($second); $x++) {
	echo "<tr><td width=\"200px\" colspan=\"2\" valign=\"top\">".$second[$x]."</td>\n";
	echo "<td width=\"200px\" colspan=\"4\"><input type=\"text\" name=\"".$secondTitles[$x]."\" size=\"50\" maxlength=\"100\" value=\"".$secondValues[$x]."\"></td></tr>\n\n";
}

echo "<INPUT TYPE=\"hidden\" NAME=\"summaryId\" VALUE=$summaryId>";
echo "<INPUT TYPE=\"submit\" NAME=\"submit\" VALUE=\"Submit\"></body></html>";



}
?>

Posted: Sat Aug 13, 2005 3:45 am
by onion2k
What happens when you echo the $query variable, and run it in mysql (via phpMyAdmin or whatever)? Does it work, or does it give you a slightly more useful error message?

Posted: Sat Aug 13, 2005 3:52 am
by facets
CODE : UPDATE ausapapersummary SET paperCategoryId='2' WHERE summaryId = 122

Had no errors and updates ok!
Hmm, where to look now, I thought it was the UPDATE code.

Could it have something to do with the HTML it's rendering?
Sprecifically the input values?

Code: Select all

<html><title></title><head></head><body>

<form name="editSASummary" action="/collotype/materialsRegister/newSubTEST.php" method="post">

<input type="hidden" name="summaryId" value=><table class="sorttable">

<tr><td width="200px" colspan="2" valign="top">Collo Paper Name</td>
<td width="200px" colspan="4">
<input type="text" name="colloPaperName" size="50" maxlength="100" [b]value="Permanent Kraft"[/b]></td></tr>

<tr><td width="200px" colspan="2" valign="top">Manufactured Name</td>
<td width="200px" colspan="4">
<input type="text" name="manufacturerName" size="50" maxlength="100" [b]value="Fasson 60# Cast Gloss / S100R / 44#PK"[/b]></td></tr>

<tr><td width="200px" colspan="2" valign="top">Computer Loopup Prefix</td>
<td width="200px" colspan="4">
<input type="text" name="cpl" size="50" maxlength="100" [b]value="01606"[/b]></td></tr>

<INPUT TYPE="submit" NAME="submit" VALUE="Submit"></body></html>

Posted: Sat Aug 13, 2005 5:54 am
by onion2k
CODE : UPDATE ausapapersummary SET paperCategoryId='2' WHERE summaryId = 122
That doesn't look like the same query from your PHP code.. where did the colloPaperName, manufacturerName and cpl fields go?

Posted: Sat Aug 13, 2005 6:20 am
by facets
I've stripped out the variables and entered data directly.
I this what you are refering to?

I'm using phpmyadmin.

UPDATE ausapapersummary SET colloPaperName='Permanent Kraft', manufacturerName='Fasson 60# Cast Gloss / S100R / 44#PK', cpl='01606' WHERE summaryId = 122

The following errors

Code: Select all

$colloPaperName = 'this';
$manufacturerName = 'is';
$cpl = 'a test';

// Update values

$query = "UPDATE ausapapersummary SET colloPaperName='$colloPaperName', manufacturerName='$manufacturerName', cpl='$cpl' WHERE summaryId = 122";

$result = mysql_query($query);
are you giving me a hint without actually declaring it ? :)

Posted: Sat Aug 13, 2005 8:54 am
by neophyte
Run the code in your browser. echo your $sql to make sure you have your variables in the right place. Copy the sql that appears in your browser into phpmyadmin. It 'll give you very useful debugging information.

Posted: Sat Aug 13, 2005 1:30 pm
by John Cartwright
It would help if you gave us the error instead of saying "heres the error" and not giving it to us :wink:
My shot in the dark being:

Code: Select all

$colloPaperName = 'this';
$manufacturerName = 'is';
$cpl = 'a test';

// Update values

$query = "UPDATE `ausapapersummary` SET `colloPaperName`='$colloPaperName', `manufacturerName`='$manufacturerName', `cpl`='$cpl' WHERE `summaryId` = 122";

$result = mysql_query($query) or die(mysql_error());