[SOLVED] MySQL UPDATE woes

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

Post Reply
facets
Forum Contributor
Posts: 273
Joined: Wed Apr 13, 2005 1:53 am
Location: Detroit

[SOLVED] MySQL UPDATE woes

Post 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>";



}
?>
Last edited by facets on Sun Aug 14, 2005 6:55 am, edited 1 time in total.
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Post 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?
facets
Forum Contributor
Posts: 273
Joined: Wed Apr 13, 2005 1:53 am
Location: Detroit

Post 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>
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Post 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?
facets
Forum Contributor
Posts: 273
Joined: Wed Apr 13, 2005 1:53 am
Location: Detroit

Post 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 ? :)
User avatar
neophyte
DevNet Resident
Posts: 1537
Joined: Tue Jan 20, 2004 4:58 pm
Location: Minnesota

Post 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.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post 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());
Post Reply