Jump to content

[SOLVED] hmmm...wonder where i went wrong


HoTDaWg

Recommended Posts

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]
<?php
define('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
Share on other sites

wait wait, i think i made this mistake before. strange, i changed the script too:
[code]
<?php
define('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]
<?php
if (!defined('inStereo'))
{
exit;
}else{
$conn = mysql_connect("localhost","XXXXX","XXXXXX") or die(mysql_error());

mysql_select_db("XXXXX");
}
?>
[/config][/code]
Link to comment
Share on other sites

[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]
<?php
define('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
Share on other sites

[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 then
select count(ip) as count from table where ip=ip
then 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
Share on other sites

[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
Share on other sites

dang, im still getting the error message.
tthe code is now:
[code]
<?php
define('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
Share on other sites

try this:

[code]
<?php
define('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
Share on other sites

[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 10

Warning: 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 27

Warning: 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
Share on other sites

i dont understand. i reorganized the script so that it is now:
[code]
<?php
error_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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

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

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

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.