HoTDaWg Posted January 1, 2007 Share Posted January 1, 2007 hi, i keep on getting an error at the wrong time. the statement issued is:[code]Our records show that you have already voted once before. As much as we hate to say it, access denied.[/code]The code for my script is:[code]<?phpdefine('inStereo',true);$ip = $_SERVER["REMOTE_ADDR"];include"config.php";$limit="3";$request = "SELECT * FROM users WHERE ip='".$ip."' && voted='".$limit."'";$results = mysql_query($request,$conn);if($request){echo "Our records show that you have already voted once before. As much as we hate to say it, access denied.";}else{$request2 = "SELECT * FROM users WHERE ip='".$ip."'"; if($request2){session_start();$_SESSION['morethanonce'] = $ip;echo '<form name="request" action="r_morethanonce.php">Artist Name:<input type="text" name="artist1">song name:<input type="text" name="song1"><br><br>Artist Name:<input type="text" name="artist2">song name:<input type="text" name="song2"><br><br>Artist Name:<input type="text" name="artist3">song name:<input type="text" name="song3"><br><br><input type="submit" value="Submit!"></form>';}else{session_start();$_SESSION['firsttime'] = $ip;echo '<form name="request" action="request.php">Artist Name:<input type="text" name="artist1">song name:<input type="text" name="song1"><br><br>Artist Name:<input type="text" name="artist2">song name:<input type="text" name="song2"><br><br>Artist Name:<input type="text" name="artist3">song name:<input type="text" name="song3"><br><br><input type="submit" value="Submit!"></form>';}}?>[/code] Link to comment https://forums.phpfreaks.com/topic/32492-solved-hmmmwonder-where-i-went-wrong/ Share on other sites More sharing options...
HoTDaWg Posted January 1, 2007 Author Share Posted January 1, 2007 wait wait, i think i made this mistake before. strange, i changed the script too:[code]<?phpdefine('inStereo',true);$ip = $_SERVER["REMOTE_ADDR"];include"config.php";$limit="3";$request = "SELECT * FROM users WHERE ip=$ip && voted=$limit";$results = mysql_query($request,$conn);if($request){echo "Our records show that you have already voted once before. As much as we hate to say it, access denied.";}else{$request2 = "SELECT * FROM users WHERE ip=$ip"; if($request2){session_start();$_SESSION['morethanonce'] = $ip;echo '<form name="request" action="r_morethanonce.php">Artist Name:<input type="text" name="artist1">song name:<input type="text" name="song1"><br><br>Artist Name:<input type="text" name="artist2">song name:<input type="text" name="song2"><br><br>Artist Name:<input type="text" name="artist3">song name:<input type="text" name="song3"><br><br><input type="submit" value="Submit!"></form>';}else{session_start();$_SESSION['firsttime'] = $ip;echo '<form name="request" action="request.php">Artist Name:<input type="text" name="artist1">song name:<input type="text" name="song1"><br><br>Artist Name:<input type="text" name="artist2">song name:<input type="text" name="song2"><br><br>Artist Name:<input type="text" name="artist3">song name:<input type="text" name="song3"><br><br><input type="submit" value="Submit!"></form>';}}?>[/code]but it still does not work >:( any ideas? ???also,[code]-- -- Table structure for table `users`-- CREATE TABLE `users` ( `id` int(11) NOT NULL auto_increment, `ip` varchar(255) default NULL, `voted` varchar(32) NOT NULL default '', PRIMARY KEY (`id`)) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;-- -- Dumping data for table `users`-- [/code]and config.php[code]<?phpif (!defined('inStereo')){ exit;}else{$conn = mysql_connect("localhost","XXXXX","XXXXXX") or die(mysql_error());mysql_select_db("XXXXX");}?>[/config][/code] Link to comment https://forums.phpfreaks.com/topic/32492-solved-hmmmwonder-where-i-went-wrong/#findComment-150971 Share on other sites More sharing options...
JasonLewis Posted January 1, 2007 Share Posted January 1, 2007 [code=php:0]if($request){[/code]if you were checking that then this is what your if would look like:if("SELECT * FROM users WHERE ip='".$ip."' && voted='".$limit."'"){i dont think thats what your wanting to do there. Link to comment https://forums.phpfreaks.com/topic/32492-solved-hmmmwonder-where-i-went-wrong/#findComment-150977 Share on other sites More sharing options...
HoTDaWg Posted January 1, 2007 Author Share Posted January 1, 2007 [quote author=ProjectFear link=topic=120606.msg494828#msg494828 date=1167688620][code=php:0]if($request){[/code]if you were checking that then this is what your if would look like:if("SELECT * FROM users WHERE ip='".$ip."' && voted='".$limit."'"){i dont think thats what your wanting to do there.[/quote]still giving me the same error. the code is now:[code]<?phpdefine('inStereo',true);$ip = $_SERVER["REMOTE_ADDR"];include"config.php";$limit="3";if("SELECT * FROM users WHERE ip='".$ip."' && voted='".$limit."'"){echo "Our records show that you have already voted once before. As much as we hate to say it, access denied.";}else{if("SELECT * FROM users WHERE ip='".$ip."'"){session_start();$_SESSION['morethanonce'] = $ip;echo '<form name="request" action="r_morethanonce.php">Artist Name:<input type="text" name="artist1">song name:<input type="text" name="song1"><br><br>Artist Name:<input type="text" name="artist2">song name:<input type="text" name="song2"><br><br>Artist Name:<input type="text" name="artist3">song name:<input type="text" name="song3"><br><br><input type="submit" value="Submit!"></form>';}else{session_start();$_SESSION['firsttime'] = $ip;echo '<form name="request" action="request.php">Artist Name:<input type="text" name="artist1">song name:<input type="text" name="song1"><br><br>Artist Name:<input type="text" name="artist2">song name:<input type="text" name="song2"><br><br>Artist Name:<input type="text" name="artist3">song name:<input type="text" name="song3"><br><br><input type="submit" value="Submit!"></form>';}}?>[/code] Link to comment https://forums.phpfreaks.com/topic/32492-solved-hmmmwonder-where-i-went-wrong/#findComment-150980 Share on other sites More sharing options...
AV1611 Posted January 1, 2007 Share Posted January 1, 2007 are they allowed to vote up to 3 times?if so, you need to just let them vote three times thenselect count(ip) as count from table where ip=ipthen do if($row[0]>=3){deny}else{accept vote}also, can you do && in mysql instead of AND ??? Link to comment https://forums.phpfreaks.com/topic/32492-solved-hmmmwonder-where-i-went-wrong/#findComment-150983 Share on other sites More sharing options...
HoTDaWg Posted January 1, 2007 Author Share Posted January 1, 2007 [quote author=AV1611 link=topic=120606.msg494834#msg494834 date=1167688977]are they allowed to vote up to 3 times?if so, you need to just let them vote three times thenselect count(ip) as count from table where ip=ipthen do if($row[0]>=3){deny}else{accept vote}also, can you do && in mysql instead of AND ???[/quote]k lemme modify the code, thanks for help so far everyone! Link to comment https://forums.phpfreaks.com/topic/32492-solved-hmmmwonder-where-i-went-wrong/#findComment-150984 Share on other sites More sharing options...
JasonLewis Posted January 1, 2007 Share Posted January 1, 2007 no no no no no man... :) i was saying in my post that the IF statement WOULD look like what you have no with the way you had it. change it back to whatever it was before except replace $request with $result.:) Link to comment https://forums.phpfreaks.com/topic/32492-solved-hmmmwonder-where-i-went-wrong/#findComment-150985 Share on other sites More sharing options...
HoTDaWg Posted January 1, 2007 Author Share Posted January 1, 2007 [quote author=ProjectFear link=topic=120606.msg494836#msg494836 date=1167689148]no no no no no man... :) i was saying in my post that the IF statement WOULD look like what you have no with the way you had it. change it back to whatever it was before except replace $request with $result.:)[/quote]ohhh, sorry for the misunderstanding.k lemme modify it again. Link to comment https://forums.phpfreaks.com/topic/32492-solved-hmmmwonder-where-i-went-wrong/#findComment-150989 Share on other sites More sharing options...
HoTDaWg Posted January 1, 2007 Author Share Posted January 1, 2007 dang, im still getting the error message.tthe code is now:[code]<?phpdefine('inStereo',true);$ip = $_SERVER["REMOTE_ADDR"];include"config.php";$limit="3";$request = "SELECT * FROM users WHERE ip='".$ip."' && voted='".$limit."'";$results = mysql_query($request,$conn);if($results){echo "Our records show that you have already voted once before. As much as we hate to say it, access denied.";}else{$request2 = "SELECT * FROM users WHERE ip='".$ip."'";$results2 = mysql_query($request,$conn); if($results2){session_start();$_SESSION['morethanonce'] = $ip;echo '<form name="request" action="r_morethanonce.php">Artist Name:<input type="text" name="artist1">song name:<input type="text" name="song1"><br><br>Artist Name:<input type="text" name="artist2">song name:<input type="text" name="song2"><br><br>Artist Name:<input type="text" name="artist3">song name:<input type="text" name="song3"><br><br><input type="submit" value="Submit!"></form>';}else{session_start();$_SESSION['firsttime'] = $ip;echo '<form name="request" action="request.php">Artist Name:<input type="text" name="artist1">song name:<input type="text" name="song1"><br><br>Artist Name:<input type="text" name="artist2">song name:<input type="text" name="song2"><br><br>Artist Name:<input type="text" name="artist3">song name:<input type="text" name="song3"><br><br><input type="submit" value="Submit!"></form>';}}?>[/code] Link to comment https://forums.phpfreaks.com/topic/32492-solved-hmmmwonder-where-i-went-wrong/#findComment-150992 Share on other sites More sharing options...
JasonLewis Posted January 1, 2007 Share Posted January 1, 2007 try this:[code]<?phpdefine('inStereo',true);$ip = $_SERVER["REMOTE_ADDR"];include"config.php";$limit="3";$user_voted = mysql_result(mysql_query("SELECT `voted` FROM users WHERE ip='".$ip."'"),0);if($user_voted > $limit){echo "Our records show that you have already voted once before. As much as we hate to say it, access denied.";}else{$request2 = "SELECT * FROM users WHERE ip='".$ip."'";$results2 = mysql_query($request,$conn); if($results2){session_start();$_SESSION['morethanonce'] = $ip;echo '<form name="request" action="r_morethanonce.php">Artist Name:<input type="text" name="artist1">song name:<input type="text" name="song1"><br><br>Artist Name:<input type="text" name="artist2">song name:<input type="text" name="song2"><br><br>Artist Name:<input type="text" name="artist3">song name:<input type="text" name="song3"><br><br><input type="submit" value="Submit!"></form>';}else{session_start();$_SESSION['firsttime'] = $ip;echo '<form name="request" action="request.php">Artist Name:<input type="text" name="artist1">song name:<input type="text" name="song1"><br><br>Artist Name:<input type="text" name="artist2">song name:<input type="text" name="song2"><br><br>Artist Name:<input type="text" name="artist3">song name:<input type="text" name="song3"><br><br><input type="submit" value="Submit!"></form>';}}?>[/code]should work. :) Link to comment https://forums.phpfreaks.com/topic/32492-solved-hmmmwonder-where-i-went-wrong/#findComment-150993 Share on other sites More sharing options...
AV1611 Posted January 1, 2007 Share Posted January 1, 2007 My point was that I think using sessions in this case makes things more complicated than they have to be... just my opinion... Link to comment https://forums.phpfreaks.com/topic/32492-solved-hmmmwonder-where-i-went-wrong/#findComment-150994 Share on other sites More sharing options...
HoTDaWg Posted January 1, 2007 Author Share Posted January 1, 2007 [quote author=AV1611 link=topic=120606.msg494845#msg494845 date=1167689541]My point was that I think using sessions in this case makes things more complicated than they have to be... just my opinion...[/quote]and you are right check out these errors im getting.[code]Warning: mysql_result() [function.mysql-result]: Unable to jump to row 0 on MySQL result index 4 in /home/mediacir/public_html/djscript/index.php on line 10Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /home/mediacir/public_html/djscript/index.php:10) in /home/mediacir/public_html/djscript/index.php on line 27Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/mediacir/public_html/djscript/index.php:10) in /home/mediacir/public_html/djscript/index.php on line 27[/code]but its cool, i just gotta reorganize the script thanks for the help guys! Topic closed. wait, any ideas what this means?[code]Warning: mysql_result() [function.mysql-result]: Unable to jump to row 0 on MySQL result index 4 in /home/mediacir/public_html/djscript/index.php on line 10[/code] Link to comment https://forums.phpfreaks.com/topic/32492-solved-hmmmwonder-where-i-went-wrong/#findComment-151000 Share on other sites More sharing options...
JasonLewis Posted January 1, 2007 Share Posted January 1, 2007 well it might be that there IP isnt in the table yet, so I would add in an if checking if there ip is there, if it is then run the query to check how many votes they have had. if there IP isnt there then add it and set $user_votes to 0. Link to comment https://forums.phpfreaks.com/topic/32492-solved-hmmmwonder-where-i-went-wrong/#findComment-151002 Share on other sites More sharing options...
HoTDaWg Posted January 1, 2007 Author Share Posted January 1, 2007 k ill work on it. thanks dude. Link to comment https://forums.phpfreaks.com/topic/32492-solved-hmmmwonder-where-i-went-wrong/#findComment-151004 Share on other sites More sharing options...
HoTDaWg Posted January 1, 2007 Author Share Posted January 1, 2007 i dont understand. i reorganized the script so that it is now:[code]<?phperror_reporting(E_ALL);define('inStereo',true);$ip = $_SERVER["REMOTE_ADDR"];include"config.php";$limit="3";$request = "SELECT * FROM users WHERE ip='".$ip."'";$results = mysql_query($request,$conn);if($results){$user_voted = mysql_result(mysql_query("SELECT `voted` FROM users WHERE ip='".$ip."'"),0);if($user_voted > $limit){echo "Our records show that you have already voted three times. As much as we hate to say it, access denied.";}else{define('morethanonce',true);echo 'You have voted before.<form name="request" action="request.php">Artist Name:<input type="text" name="artist">song name:<input type="text" name="song"><br><br><br><br><input type="submit" value="Submit!"></form>';}}else{define('firsttime',true);echo 'this is your first time voting.<form name="request" action="request.php">Artist Name:<input type="text" name="artist">song name:<input type="text" name="song"><br><br><input type="submit" value="Submit!"></form>';}?>[/code]but it does not echo the stuff i want if ur ip is not in the database. it also gives an error.[code]Warning: mysql_result() [function.mysql-result]: Unable to jump to row 0 on MySQL result index 5 in /home/mediacir/public_html/djscript/index.php on line 15[/code]also, in case you are wondering, i want to insert the users ip in the request.php document rather than this one. Link to comment https://forums.phpfreaks.com/topic/32492-solved-hmmmwonder-where-i-went-wrong/#findComment-151045 Share on other sites More sharing options...
HoTDaWg Posted January 2, 2007 Author Share Posted January 2, 2007 any ideas? Link to comment https://forums.phpfreaks.com/topic/32492-solved-hmmmwonder-where-i-went-wrong/#findComment-151072 Share on other sites More sharing options...
HoTDaWg Posted January 2, 2007 Author Share Posted January 2, 2007 i dont mean to be ungrateful, pushy, or impatient; but i have been waiting for a couple of hours now. if anyone, i mean anyone can help me, your assistance would be greatly appreciated. Link to comment https://forums.phpfreaks.com/topic/32492-solved-hmmmwonder-where-i-went-wrong/#findComment-151102 Share on other sites More sharing options...
trq Posted January 2, 2007 Share Posted January 2, 2007 Sorry, your code is pretty hard to follow with its lack of formatting and all. This should (I think) come close to what you want providing that the [i]voted[/i] field has default of 0.[code]<?php error_reporting(E_ALL); define('inStereo',true); $ip = $_SERVER["REMOTE_ADDR"]; include "config.php"; $limit = 3; $sql = "SELECT * FROM users WHERE ip='$ip'"; if ($result = mysql_query($sql)) { if (mysql_num_rows($result) > 0) { $row = mysql_fetch_assoc($result); if ($row['voted'] > $limit) { echo "Our records show that you have already voted three times. As much as we hate to say it, access denied."; } elseif ($row['voted'] == 0) { define('firsttime',true); echo 'this is your first time voting.<form name="request" action="request.php"> Artist Name:<input type="text" name="artist">song name:<input type="text" name="song"><br><br> <input type="submit" value="Submit!"></form>'; } else { define('morethanonce',true); echo 'You have voted before.<form name="request" action="request.php"> Artist Name:<input type="text" name="artist">song name:<input type="text" name="song"><br><br> <br><br><input type="submit" value="Submit!"></form>'; } } } ?>[/code] Link to comment https://forums.phpfreaks.com/topic/32492-solved-hmmmwonder-where-i-went-wrong/#findComment-151124 Share on other sites More sharing options...
corbin Posted January 2, 2007 Share Posted January 2, 2007 $user_voted = mysql_result(mysql_query("SELECT `voted` FROM users WHERE ip='".$ip."'"),0,'voted');Try that, although I dont think thts the problem. Link to comment https://forums.phpfreaks.com/topic/32492-solved-hmmmwonder-where-i-went-wrong/#findComment-151131 Share on other sites More sharing options...
JasonLewis Posted January 2, 2007 Share Posted January 2, 2007 i copied all of your code HoTDaWg and it worked fine for me. what IS really the problem? Link to comment https://forums.phpfreaks.com/topic/32492-solved-hmmmwonder-where-i-went-wrong/#findComment-151133 Share on other sites More sharing options...
HoTDaWg Posted January 2, 2007 Author Share Posted January 2, 2007 hey guys thanks for the help so far, i had to give my brother the computer, but my terribly coded script still has problems :(. First, it showed a completely blank page so, going by my gut, i made the whole code into a function and then recalled that function after. But, for some reason it now gives me this error: [code]Notice: Undefined variable: ip in /home/idanc48d/public_html/index.php on line 13[/code]here is the script again:[code]<?php error_reporting(E_ALL); define('inStereo',true); $ip = $_SERVER["REMOTE_ADDR"]; echo $ip; include "config.php"; $limit = 3; function beginthework(){ $sql = "SELECT * FROM users WHERE ip='$ip'"; if ($result = mysql_query($sql)) { if (mysql_num_rows($result) > 0) { $row = mysql_fetch_assoc($result); if ($row['voted'] > $limit) { echo "Our records show that you have already voted three times. As much as we hate to say it, access denied."; } elseif ($row['voted'] == 0) { define('firsttime',true); echo 'this is your first time voting.<form name="request" action="request.php"> Artist Name:<input type="text" name="artist">song name:<input type="text" name="song"><br><br> <input type="submit" value="Submit!"></form>'; } else { define('morethanonce',true); echo 'You have voted before.<form name="request" action="request.php"> Artist Name:<input type="text" name="artist">song name:<input type="text" name="song"><br><br> <br><br><input type="submit" value="Submit!"></form>'; } } } }beginthework();?>[/code]i wanna take the time to thank everyone who has helped me out, and ProjectFear especially for his interest and consistency. But one more question, i understand how completely unorganized my code appears, is there some kind of feature in DzSoft Php editor or dreamweaver that automatically indents the code? thanks again.HoTDaWg Link to comment https://forums.phpfreaks.com/topic/32492-solved-hmmmwonder-where-i-went-wrong/#findComment-151767 Share on other sites More sharing options...
JasonLewis Posted January 2, 2007 Share Posted January 2, 2007 the reason your getting the undefined variables is because your calling a variable which was defined outside of the function.try adding this just below the function beginthework(){ and above the $sql variable.[code=php:0]global $ip, $limit;[/code] Link to comment https://forums.phpfreaks.com/topic/32492-solved-hmmmwonder-where-i-went-wrong/#findComment-151775 Share on other sites More sharing options...
HoTDaWg Posted January 2, 2007 Author Share Posted January 2, 2007 i see, thanks ProjectFear, but why did the page not show up before? Link to comment https://forums.phpfreaks.com/topic/32492-solved-hmmmwonder-where-i-went-wrong/#findComment-151780 Share on other sites More sharing options...
HoTDaWg Posted January 2, 2007 Author Share Posted January 2, 2007 wait a minute, its still not showing up :( Link to comment https://forums.phpfreaks.com/topic/32492-solved-hmmmwonder-where-i-went-wrong/#findComment-151781 Share on other sites More sharing options...
Philip Posted January 2, 2007 Share Posted January 2, 2007 It's not even showing your IP? Link to comment https://forums.phpfreaks.com/topic/32492-solved-hmmmwonder-where-i-went-wrong/#findComment-151791 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.