Can't UPDATE MySQL entry, not sure why...

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
GodsHand
Forum Newbie
Posts: 4
Joined: Thu Mar 30, 2006 4:42 pm

Can't UPDATE MySQL entry, not sure why...

Post by GodsHand »

feyd | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


asically when I click on DONE, I want my script to change whatever STATUS is currently to 1. This script just doesn't work though, and I'm not sure what I'm missing here... I didn't include the usual mysql connect stuff.

I'm a bit of a noob so be gentle...

Code: Select all

<?
if ( $mode=="done") 
{
mysql_query ("UPDATE users SET status='1' WHERE id='$id'");
Print "Entry has been updated <p>";
}

	$query = "SELECT id, name, time, notes, runs, user FROM upload WHERE status='0' AND destination='Advertising' ORDER BY id DESC";
	$result	= mysql_query($query) or die('Error, query failed');
	
	if	(mysql_num_rows($result) == 0)
		{echo "Database is empty <br>";}
			
	else
		{while(list($id, $name, $time, $notes, $runs, $user) = mysql_fetch_array($result))
		{
?>
<div id="DownloadNew">
	<a href="downloadstest.php?id=<?=$id;?>"><div id="DownloadNewArrow" onclick="new Effect.Pulsate(this, {duration: 3})"></div></a>
	<div id="DownloadNewFile">
		<a href="downloadstest.php?id=<?=$id;?>" class="filename">
		<? $trimmed = substr($name, 0, 28); if($trimmed != $name) echo $trimmed .= '...'; else if($trimmed <= $name) echo $name; ?></a><br />
		<span class="description"><?=$notes;?></span>
	</div>
	<div id="DownloadNewSquiggly">}</div>
	<div id="DownloadNewInfo">
	<img src="media/download_new_user.png" /> <a href="javascript: openWindow()"><span class="username"><?=$user;?></span></a><br />
	<img src="media/download_new_time.png" /> <?=$time;?></span><br />
	<img src="media/download_new_rundate.png" /> <strong>Runs:</strong> <?=$runs;?></span>
	</div>
	<div id="DownloadNewDone">

	<a href="admin.php?id=<?=$id;?>&mode=done"><input name="" type="checkbox" value="" /> Done?</a><br />
	<select name="">
		<option>Move?</option>
	</select>
	</div>
</div>
<?    }} ?>

feyd | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Run the following in a new file and tell us the results please.

Code: Select all

<?php

$ve = phpversion();
$os = PHP_OS;
$er = intval(error_reporting());
$rg = (in_array(strtolower(ini_get('register_globals')), array(0, false, '', null, 'off')) ? 'Off' : 'On');
$de = (in_array(strtolower(ini_get('display_errors')), array(0, false, '', null, 'off')) ? 'Off' : 'On');
$so = (in_array(strtolower(ini_get('short_open_tag')), array(0, false, '', null, 'off')) ? 'Off' : 'On');
$eol = (isset($_SERVER['HTTP_HOST']) ? "<br />\n" : "\n");

$ec = array(
   'E_STRICT' => 2048,
   'E_ALL' => 2047,
   'E_USER_NOTICE' => 1024,
   'E_USER_WARNING' => 512,
   'E_USER_ERROR' => 256,
   'E_COMPILE_WARNING' => 128,
   'E_COMPILE_ERROR' => 64,
   'E_CORE_WARNING' => 32,
   'E_CORE_ERROR' => 16,
   'E_NOTICE' => 8,
   'E_PARSE' => 4,
   'E_WARNING' => 2,
   'E_ERROR' => 1,
);

$e = array();
$t = $er;
foreach ($ec as $n => $v)
{
   if (($t & $v) == $v)
   {
      $e[] = $n;
      $t ^= $v;
   }
}
$er = $er . ' (' . implode(' | ', $e) . ')';

echo 'PHP Version: ' . $ve . $eol;
echo 'PHP OS: ' . $os . $eol;
echo 'Error Reporting: ' . $er . $eol;
echo 'Register Globals: ' . $rg . $eol;
echo 'Short Tags: ' . $so . $eol;
echo 'Display Errors: ' . $de . $eol;

?>
GodsHand
Forum Newbie
Posts: 4
Joined: Thu Mar 30, 2006 4:42 pm

Post by GodsHand »

First, I apologize about not using the correct tags. Thanks for fixing that for me!

Here's the results:
PHP Version: 5.1.2
PHP OS: WINNT
Error Reporting: 2047 (E_ALL)
Register Globals: Off
Short Tags: On
Display Errors: On
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Your code was written assuming register_globals is turned on when it is not. Rewrite your code (a bit) to not assume register_globals is on.

hint: it'll involve $_POST and $_GET and the other superglobals.

Furthermore, I will suggest that you shouldn't code for short tags being on either. Why? Because they can be turned off and on some servers are, quite readily. (All of my servers have it off, for instance.)
GodsHand
Forum Newbie
Posts: 4
Joined: Thu Mar 30, 2006 4:42 pm

Post by GodsHand »

Thanks for getting me on the right track. I'll see what I can figure out.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: Can't UPDATE MySQL entry, not sure why...

Post by Benjamin »

I am surpised this works anyway...

Code: Select all

$query = "SELECT id, name, time, notes, runs, user FROM upload WHERE status='0' AND destination='Advertising' ORDER BY id DESC";
$result	= mysql_query($query) or die('Error, query failed');
Isn't user a reserved mysql keyword?

It should probably be like this..

Code: Select all

$query = "SELECT `id`, `name`, `time`, `notes`, `runs`, `user` FROM `upload` WHERE `status`='0' AND `destination`='Advertising' ORDER BY `id` DESC";
$result	= mysql_query($query) or die('Error, query failed');
GodsHand
Forum Newbie
Posts: 4
Joined: Thu Mar 30, 2006 4:42 pm

Post by GodsHand »

Well I know that code definitely works. The format you posted it as, is that the correct way I should be formatting?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

backticks, like agtLewis posted is the more correct way. This is due to MySQL not understanding what you say is a field when it is a reserved word that means something else entirely.
Post Reply