Jump to content

mysql updating help!


cohan1279

Recommended Posts

hi, i need a little help please! In this code all but on thing is working.
----mysql_query("UPDATE $playerdb SET pvote=(pvote+1) WHERE num=$member_vote;");-----
all the rest is working fine. but i cant seem to figure this one out  >:(
im still very new to this so please help, sadly, ive been trying to figure this out for days!

[code]if ($do_vote)
{
 
global $users;
    mysql_query("UPDATE $playerdb SET pvote=(pvote+1) WHERE num=$member_vote;");
mysql_query("UPDATE $playerdb SET pvoted=(1) WHERE num=$users[num];");
TheEnd("You have now voted for <b>$listcountry[empire]for your President.</b>.");

}
?>

</table><br>
Vote for your President.<br><br>
<form method="post" action="<?=$config[main]?>?action=country">
<table class="inputtable">

<tr><th class="acenter">Vote For: <a href=countrys.html></a></th>
    <td><select name="$member_vote" size="1">
<?
$pvotes = mysql_query("select num,empire from $playerdb WHERE country=$ucountry[id];");
while ($pvote = mysql_fetch_array($pvotes))
{
?>
    <option value="<?=$pvote[num]?>"<?if ($pvote[num] == 1) print " selected";?>><?=$pvote[empire]?></option>
<?
}
?>
    </select></td></tr>
<tr><td colspan="2">&nbsp;</td></tr>
<tr><td><input type="submit" name="do_vote" value="Vote"></td>
   
</table>
</form>
<?
}

TheEnd("");
?>[/code] 
Link to comment
https://forums.phpfreaks.com/topic/20360-mysql-updating-help/
Share on other sites

First, you need to check for errors from mysql_query().  For example:

[code]$result = mysql_query( ... )
if ($result === false) die("Mysql error " . mysql_error());[/code]

Second, if you aren't already you should check the values of $playerdb and $member_vote to make sure they are valid.

Then post back here if you are still having trouble :)

I think it's likely your problem is here:

[code]<td><select name="$member_vote" size="1">[/code]

Should that be "member_vote" instead of "$member_vote" ?
Link to comment
https://forums.phpfreaks.com/topic/20360-mysql-updating-help/#findComment-89678
Share on other sites

thanks for the reply ,but it hasnt helped  >:(
[code]
$result = mysql_query( ... )
if ($result === false) die("Mysql error " . mysql_error());[/code]
fisrt i tried this, and got an error. wouldnt load my page.

also $member_vote is not a table in my db, just the name of the selection to my dropdown selection box.
now i could very well be wrong,as im just now learning php, but using this this way has worked before as in this code with $signup_country
[code]
if ($do_signup)
{
mysql_query("INSERT INTO $playerdb (num) VALUES (NULL);");
$users = loadUser(mysql_insert_id());
$users[country] = $signup_country;
<?
EndNow("");
}

?>
<form method="post" action="<?=$config[main]?>?action=signup">
<table class="inputtable">
<tr><th class="aright">Your Country: <a href=countrys.html>Help</a></th>
    <td><select name="signup_country" size="1">
<?
$countrys = mysql_query("select id,name from $countrydb;");
while ($country = mysql_fetch_array($countrys))
{
?>
    <option value="<?=$country[id]?>"<?if ($country[id] == 1) print " selected";?>><?=$country[name]?></option>
<?
}
?>
    </select></td></tr>
<tr><td colspan="2">&nbsp;</td></tr>
<tr><td><input type="submit" name="do_signup" value="Sign Me Up!"></td>
    <td class="aright"><input type="reset" value="Reset Form!"</td></tr>
</table>
</form>
<?
HTMLendcompact();
?>
[/code]

and as far as checking the values of $playerdb and $member_vote to make sure they are valid.??? well i know the $playerdb values and the dropdown box is loading the correct users from $playerdb to the page so $member_vote value should be right, its just not updating the $playerdb. as it should be adding 1 to pvote  in $playerdb ( -- SET pvote=(pvote+1) -- ) the query should be doing this in the  $playerdb where num value in $playerdb matches the num value of $member_vote. how can i check the value of $member_vote as its not really in the db,well not under that name anyway.

so i ask agian, any idea why this is not working????
Link to comment
https://forums.phpfreaks.com/topic/20360-mysql-updating-help/#findComment-89878
Share on other sites

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.