Jump to content

Recommended Posts

ok.. hard to explain.... i have a MYSQL database and a table named "FlaxerAuthAndSig" and i have 6 varibles.. the varible's are as follow 'username, password, id, amountOfFlax, amountOfFlaxPerHour,TotalHoursUsed' in that same order... but what i need it to do is get the 'TotalHoursUsed' of a user i select and add 1 hour but i cant seem to do that! best i came to was this.

<?php
mysql_connect('nothingtoseehere', 'nothing', 'thisisntapassword') or die(mysql_error
    ());
mysql_select_db('nothing') or die(mysql_error());

$user = $_GET['user'];
$hours = $_GET['hours'];
function getValues()
{
    $sql = "SELECT TotalHoursUsed FROM FlaxerAuthAndSig WHERE username = '$user'";
    return mysql_query($sql);
}
$tree = getValues();
mysql_query("INSERT INTO FlaxerAuthAndSig (TotalHoursUsed) VALUES('$tree') WHERE username = '$user'")
?>

Link to comment
https://forums.phpfreaks.com/topic/112284-solved-inserting-into-mysql/
Share on other sites

So you want to change the TotalHoursUsed to +1 more than it already is?

 

update table set FlaxerAuthAndSig TotalHoursUsed = TotalHoursUsed+1 where username = '$user'

ok... now i have this:

<?php
mysql_connect('fdb1.runhosting.com', '126745_cdog', 'sports') or die(mysql_error
    ());
mysql_select_db('126745_cdog') or die(mysql_error());

$user = $_GET['user'];
$hours = $_GET['hours'];
if($user != null and $hours != null){
mysql_query("UPDATE TABLE SET FlaxerAuthAndSig TotalHoursUsed = TotalHoursUsed+1 WHERE username = '$user'");
echo "added time";
}
?>

and dosent seem to add to totalHoursUsed

Assuming that your previous die(..) statements didn't echo any errors:

 

- Add a die to your mysql_query see if it is returning an error for some reason.

- Make sure table and column names are spelled right. 

- Echo out $user make sure it has what you expect it to have. 

- Make sure that there is indeed a username in the table called $user

- Check your table in phpmyadmin or command line or w/e to see if it's updated there (because I don't see any code there that displays anything relevant)

omg! still won't work!!!!

here:

<?php
mysql_connect('fdb1.runhosting.com', '126745_cdog', 'sports') or die(mysql_error
    ());
mysql_select_db('126745_cdog') or die(mysql_error());

$user = $_GET['user'];
$hours = $_GET['hours'];
if($user != null and $hours != null){
echo $user;
$current_Hours = mysql_query("SELECT TotalHoursUsed FROM FlaxerAuthAndSig WHERE username = '$user'");
mysql_query("UPDATE TABLE SET FlaxerAuthAndSig TotalHoursUsed = '$current_Hours'+1 WHERE username = '$user'");
echo "/n added time";
}
?>

Okay first off, Blade is right, the actual table name needs to be there instead of TABLE. But 2nd, you don't need 2 separate queries to do that.  You just need the update query.  I mean think about it.  You're selecting totalhoursused where username = '$user' and assigning it to a variable (which btw you did wrong: you just assigned a result source to $current_hours).  Then you turn around and take that current number and update the row, adding 1 to that variable where username still equals $user.  So take out the select query, you don't need it.

<?php
mysql_connect('fdb1.runhosting.com', '126745_cdog', 'sports') or die(mysql_error
    ());
mysql_select_db('126745_cdog') or die(mysql_error());

$user = $_GET['user'];
$hours = $_GET['hours'];
if($user != null and $hours != null){
echo $user;
mysql_query("UPDATE FlaxerAuthAndSig SET TotalHoursUsed = TotalHoursUsed+1 WHERE username = '$user'");
echo "/n added time";
}
?>

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.