Jump to content

simple problem!!


grlayouts

Recommended Posts

Not using a WHERE clause will update all records, are you sure thats what you want? Try...

[code]
<?php
error_reporting(E_ALL) ; ini_set("display_errors","1");
include("config.php");
$drugupdate = 100 * '$stat[drugfact]';
$sql = "update players set UTCQ=UTCQ+'$drugupdate'";
mysql_query($sql) or die(mysql_error() . ' in <br>' . $sql);
?>
[/code]
Link to comment
Share on other sites

[quote]Am I missing something? Don't you have to use quotes around a string?[/quote]

Not sure which part your talking about. This line...

[code=php:0]
$drugupdate = 100 * '$stat[drugfact]';
[/code]

needs to be...

[code=php:0]
$drugupdate = 100 * $stat['drugfact'];
[/code]

though.
Link to comment
Share on other sites

Exactly.
I don't see why this wouldn't work:
[code]
<?php
error_reporting(E_ALL) ; ini_set("display_errors","1");
include("config.php");
$drugupdate = 100 * $stat['drugfact'];
$sql = "UPDATE players SET UTCQ=UTCQ+$drugupdate";
mysql_query($sql) or die(mysql_error() . ' in <br />' . $sql);
?>
[/code]
Link to comment
Share on other sites

ok ive updated the code to include the $stat

[code]
<?php
include("config.php");
error_reporting(E_ALL) ; ini_set("display_errors","1");
$stat = mysql_fetch_array(mysql_query("select * from players"));
$drugupdate = 100 * $stat['drugfact'];
$sql = "UPDATE players SET UTCQ=UTCQ+$drugupdate";
mysql_query($sql) or die(mysql_error() . ' in <br />' . $sql);
?>
[/code]

still nothing updating?
Link to comment
Share on other sites

What are you wanting to do excactly? As Ive previously said, without a WHERE clause your update statement will update ALL records, is that what you want? That code is terrible and getting worse.

Also, are you getting any errors yet?
Link to comment
Share on other sites

[code]
<?php
include("config.php");
error_reporting(E_ALL) ; ini_set("display_errors","1");
$sql = "UPDATE players SET UTCQ=drugfact*100";
if (mysql_query($sql)) {
  echo "update success";
} else {
  die(mysql_error() . ' in <br />' . $sql);
}
?>
[/code]
Link to comment
Share on other sites

[quote]but thats not difining drugfact as something from the database?[/quote]

You said [i]drugfact[/i] is a field in your database. My code will take whatever value is in [i]drugfact[/i] times it by 100 and insert the total into UTCQ.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.