...

View Full Version : Updating info in database



arturxxx
10-27-2012, 02:03 PM
I have tried to make it update the info if it already exists but with no luck, I am a newbie to php and I hope you guys will help me :)

<?php
define("DB_SERVER", "xxxx");

define("DB_USER", "xxxx");

define("DB_PASS", "xxxx");

define("DB_NAME", "xxxx");

mysql_connect(DB_SERVER, DB_USER, DB_PASS);
mysql_select_db(DB_NAME);
session_start();

$runtime = $_GET['runtime'];
$user = $_GET['username'];
$profit = $_GET['profit'];
$exp = $_GET['exp'];

$query = "SELECT * FROM rune_sig WHERE username = '$username'";
$result = mysql_query($query);

if (mysql_num_rows($result) )
{
@mysql_query("UPDATE rune_sig SET runtime = '$runtime', exp = '$exp', profit = '$profit'");
}
else
{
if ($run>=0 && $user && $profit>=0 && $exp>=0) {
@mysql_query("INSERT INTO rune_sig
(`username`, `runtime`, `profit`, `exp`, `time`) VALUES
('$user', '$runtime', '$profit', '$exp', NOW())");
} else {
echo '<font style="font-size:100px;font-family:georgia;"><br><center>GTFO</center></font>';
echo '<font style="font-size:50px;font-family:georgia;"><center><i>These are my PHP files.</i></center></font>';
}
}
?>

davidjones1990
10-27-2012, 03:01 PM
Hi

You need to tell MYSQL what row it needs to update. SO adding WHERE username = '$username' onto the end of the update query should do it.

arturxxx
10-27-2012, 03:13 PM
Hi

You need to tell MYSQL what row it needs to update. SO adding WHERE username = '$username' onto the end of the update query should do it.

Hmm, I didn't know that it would clear out the data and set it to the new one. Is there any way to add the value to the current one?

davidjones1990
10-27-2012, 03:37 PM
So assuming that its a integer you can do something like this:

profit = profit + '$profit'

but depending on your need you may want to use CSV's so the info would look like this 10,20,30 or a seperate table altogether.

If you explain what you are trying to do in more detail I could suggest some more detailed solutions.

arturxxx
10-27-2012, 03:59 PM
So assuming that its a integer you can do something like this:

profit = profit + '$profit'

but depending on your need you may want to use CSV's so the info would look like this 10,20,30 or a seperate table altogether.

If you explain what you are trying to do in more detail I could suggest some more detailed solutions.

I got it to work, you can't imagine how happy I am right now. Thank you!

davidjones1990
10-27-2012, 04:04 PM
No problem buddy



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum