Jump to content


Photo

mysql updating help!


  • Please log in to reply
7 replies to this topic

#1 cohan1279

cohan1279
  • Members
  • PipPip
  • Member
  • 24 posts

Posted 11 September 2006 - 06:15 AM

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!

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("");
?>
 

#2 kayess2004

kayess2004
  • Members
  • PipPip
  • Member
  • 18 posts
  • LocationAustralia

Posted 11 September 2006 - 06:26 AM

Hi,

Is $playerdb a table name or the name of the database?


Chuck Norris doesn't know love. Chuck Norris only knows not kill.

#3 cohan1279

cohan1279
  • Members
  • PipPip
  • Member
  • 24 posts

Posted 11 September 2006 - 06:30 AM

$playerdb is a table, theres more code (that calls the db) i only included the problem area. ;)

#4 cohan1279

cohan1279
  • Members
  • PipPip
  • Member
  • 24 posts

Posted 11 September 2006 - 07:40 AM

mysql_query("UPDATE $playerdb SET pvote=(pvote+1) WHERE num=$member_vote;");
why does this not work?

#5 btherl

btherl
  • Staff Alumni
  • Advanced Member
  • 3,893 posts
  • LocationAustralia

Posted 11 September 2006 - 07:47 AM

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

$result = mysql_query( ... )
if ($result === false) die("Mysql error " . mysql_error());

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:

<td><select name="$member_vote" size="1">

Should that be "member_vote" instead of "$member_vote" ?

#6 cohan1279

cohan1279
  • Members
  • PipPip
  • Member
  • 24 posts

Posted 11 September 2006 - 04:34 PM

thanks for the reply ,but it hasnt helped  >:(
$result = mysql_query( ... )
if ($result === false) die("Mysql error " . mysql_error());
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
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();
?>

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

#7 cohan1279

cohan1279
  • Members
  • PipPip
  • Member
  • 24 posts

Posted 12 September 2006 - 12:36 AM

Help! lol

#8 cohan1279

cohan1279
  • Members
  • PipPip
  • Member
  • 24 posts

Posted 12 September 2006 - 03:21 AM

;D ok I got it.
<form method="post" action="<?=$config[main]?>?action=country">

needed to change to
<form method="post" action="<?=$config[main]?>?action=vote">
oops .....
I cant believe how many times i over looked that!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users