Jump to content
MakeWebGames

Not posting to database


newttster

Recommended Posts

Why is this not posting to the database?

I have verified that all the names in the table and the table name itself are correct. Default for "grosetonesone" is 0.

Type is tinyint-2.

 

function tonestage_one()
{
global $db,$ir,$c,$userid,$h;
$q=$db->query("SELECT grosetonesone FROM stagetable WHERE userid = {$ir['userid']}");
$r=$db->fetch_row($q);
if ($r['grosetonesone']==0)
{
echo "Yada yada yada blah blah blah.<br />
<a href='explore.php'>Back to town<a/><br />";
$db->query("UPDATE `stagetable` SET `grosetonesone`= '1' WHERE `userid`='{$ir['userid']}'", $c);
}
else
{
echo"Why are you here? You have already done this.";
}
}
Link to comment
Share on other sites

$db->query('UPDATE `stagetable` WHERE `grosetonesone` = 1 WHERE `userid` = '.$ir['userid']);

That wouldn't work

Try

$db->query("UPDATE `stagetable` SET `grosetonesone`= '1' WHERE `userid`= '".$ir['userid']."'", $c) or die(mysql_error());

 

If you get an error from using the above then post it here.

Link to comment
Share on other sites

@iExze & Newttster - I'd like to question both of your methods, this time I used your advice ;)

You have the following

[...]WHERE `userid`= '".$ir['userid']."'"[..]

 

So, My question. Why encase a numerical value in apostrophes ( ' ) thus making the program treat it as a string?

Here's how I would do it;

$db->query("UPDATE `stagetable` SET `grosetonesone`= '1' WHERE `userid`=". $userid, $c) or die(mysql_error());

I would, after confirmation that it works, remove the or die(mysql_error()) as it won't be needed.

Link to comment
Share on other sites

@iExze & Newttster - I'd like to question both of your methods, this time I used your advice ;)

You have the following

[...]WHERE `userid`= '".$ir['userid']."'"[..]

 

So, My question. Why encase a numerical value in apostrophes ( ' ) thus making the program treat it as a string?

Here's how I would do it;

$db->query("UPDATE `stagetable` SET `grosetonesone`= '1' WHERE `userid`=". $userid, $c) or die(mysql_error());

I would, after confirmation that it works, remove the or die(mysql_error()) as it won't be needed.

I encase everything like that, whether a number or string, it's habbit really.

Link to comment
Share on other sites

Okay everyone ... I have tried all of your suggestions and it still will not post to the db.

It does not give me an error message.

@ruler - I did as you suggested and all it is doing is printing out is a 1 after the <a href='explore.php'>Back to town<a/>";

@sniko - I encase the values because every once in a while the query that I am attempting to do will not recognize it without the quotes. So as a fail safe, I always do this now. *shrugs*

I have thought of doing an INSERT INTO ... the problem with that is there will come a time when the table itself will have too many rows to make this feasible ... which is why I am trying to get the UPDATE to work.

EDIT: On reflection, with the INSERT INTO after the userid value the rest would just be 0 or 1. This does work as I have tested it ... it's just that after a certain point doing the INSERT with all the 1's and 0's will get annoying which is why I was trying to get the UPDATE to work.

Which would you use?

Edited by newttster
Link to comment
Share on other sites

Thought about doing an INSERT. So the table your trying to update does not have the info? you cannot update something that does not exist you do realize that dont you.

*facepalms* I do now. Grr! So as long as I do one INSERT query to start that contains the users ID ... after that I can simply do an UPDATE from then on?

My apologies ... that completely got by me all together. Colour me embarassed.

Link to comment
Share on other sites

That wouldn't work

Try

$db->query("UPDATE `stagetable` SET `grosetonesone`= '1' WHERE `userid`= '".$ir['userid']."'", $c) or die(mysql_error());

 

If you get an error from using the above then post it here.

Please don't quote my work. Putting quote's around numerical value's? Shame. Test my code, fool

Link to comment
Share on other sites

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.   Paste as plain text instead

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