Jump to content

[SOLVED] Inserting into MYSQL


cdog5000

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";
}
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.