Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 10-27-2012, 02:03 PM   PM User | #1
arturxxx
New to the CF scene

 
Join Date: Oct 2012
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
arturxxx is an unknown quantity at this point
Question Updating info in database

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 Code:
 <?php
define
("DB_SERVER""xxxx");

define("DB_USER""xxxx");

define("DB_PASS""xxxx");

define("DB_NAME""xxxx");

mysql_connect(DB_SERVERDB_USERDB_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>=&& $user && $profit>=&& $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>';
}
}
?>

Last edited by arturxxx; 10-27-2012 at 02:07 PM.. Reason: Misspelled title
arturxxx is offline   Reply With Quote
Old 10-27-2012, 03:01 PM   PM User | #2
davidjones1990
New Coder

 
Join Date: Sep 2011
Posts: 22
Thanks: 0
Thanked 3 Times in 3 Posts
davidjones1990 is an unknown quantity at this point
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.
davidjones1990 is offline   Reply With Quote
Old 10-27-2012, 03:13 PM   PM User | #3
arturxxx
New to the CF scene

 
Join Date: Oct 2012
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
arturxxx is an unknown quantity at this point
Quote:
Originally Posted by davidjones1990 View Post
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?
arturxxx is offline   Reply With Quote
Old 10-27-2012, 03:37 PM   PM User | #4
davidjones1990
New Coder

 
Join Date: Sep 2011
Posts: 22
Thanks: 0
Thanked 3 Times in 3 Posts
davidjones1990 is an unknown quantity at this point
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.
davidjones1990 is offline   Reply With Quote
Old 10-27-2012, 03:59 PM   PM User | #5
arturxxx
New to the CF scene

 
Join Date: Oct 2012
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
arturxxx is an unknown quantity at this point
Thumbs up

Quote:
Originally Posted by davidjones1990 View Post
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!
arturxxx is offline   Reply With Quote
Old 10-27-2012, 04:04 PM   PM User | #6
davidjones1990
New Coder

 
Join Date: Sep 2011
Posts: 22
Thanks: 0
Thanked 3 Times in 3 Posts
davidjones1990 is an unknown quantity at this point
No problem buddy
davidjones1990 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 02:58 AM.


Advertisement
Log in to turn off these ads.