Jump to content

KillZoneZ

Members
  • Posts

    23
  • Joined

  • Last visited

Posts posted by KillZoneZ

  1. My code is returning Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given and i cant find out why :( Please help

    $CheckUsername = mysqli_query($conn,"SELECT Username FROM users WHERE Username='$Username'");
                $CheckEmail = mysqli_query($conn,"SELECT E-Mail FROM users WHERE E-Mail='$Email'");
                $CheckBetaKey = mysqli_query($conn,"SELECT BetaKey FROM betakey WHERE BetaKey='$BetaKey' AND E-Mail='$Email'");
                
                if ($Password != $PasswordAgain || ($CheckUsername != FALSE) || ($CheckEmail != FALSE) || (mysqli_num_rows($CheckBetaKey) != 1))
                    {
                        if ($Password != $PasswordAgain) {
                            echo "• Passwords did not match.";
                        }
                        else {}
                        if ($CheckUsername != FALSE) {
                            echo "• That Username has already been taken.";
                        }
                        else{}
                        if ($CheckEmail != FALSE) {
                            echo "• That E-Mail has already been registered.";
                        }
                        else{}
                        if (mysqli_num_rows($CheckBetaKey) != 1) {
                            echo "• Either that Beta Key has already been used or isn't for the specified e-mail address.";
                        }
                        else{}
                    }
                else {
                    $InsertUser = mysqli_query($conn,"INSERT INTO users (Username,Password,E-Mail,BetaKey) VALUES ('$Username','$Password','$E-Mail','$BetaKey')");
                    $DeleteBetaKey = mysqli_query($conn,"DELETE * FROM betakey WHERE BetaKey='$BetaKey' AND Mail='$Email'");
                    header ("Location: Index.php");
                }

    Also, the second condition:

    if ($CheckUsername != FALSE) {
                   echo "• That Username has already been taken.";
    }
                   else{}

    is returning true even though there is no User in the database.

     

    The same happens with the last one.

    if (mysqli_num_rows($CheckBetaKey) != 1) {
                            echo "• Either that Beta Key has already been used or isn't for the specified e-mail address.";
                        }
                        else{}
                    }
  2. mysqli_query will return a resource representing a resultset which you can use to access the data returned from the query. It does not return actual values. You have to use one of the assorted fetch functions to get those.

    Im not quite catching it sorry, could you give me an example?

     

    @Edit

     

    Been thinking on other ways to check if a value already exists in the database and thought this: Could i use mysqli_num_rows to check how many rows the result set has and if it was bigger than 0 it would mean that there is already a field with the same value on the database. Would that work?

     

    Thanks for the quick answer btw :)

  3. Hello,

     

    For some reason this if condition is returning true even though it is false, that is, instead of echoing the sentence should have gone forward because it was inputed correctly on the form.

     

    Here is the code:

    if($BetaKey != $result=mysqli_query($conn,"SELECT BetaKey FROM betakey WHERE BetaKey = '$BetaKey'")) {
                        echo "• Either that Beta Key has already been used or isnt for the specified e-mail.";
                    }

    Form used in the php code's code:

    <form method="post" action="RegisterCheckUp.php">
            <span id="UsernameLabel">Username:<span class="required">*</span></span>
            <br>
            <input type="text" maxlength="16" id="Username" name="username" placeholder="Username" value="" required="required"/>
            <br>
            <span id="PasswordLabel">Password:<span class="required">*</span></span>
            <br>
            <input maxlength="16" type="password" id="Password" name="password" placeholder="Password" value="" required="required"/>
            <br>
            <span id="PasswordAgainLabel">Repeat Password:<span class="required">*</span></span>
            <br>
            <input type="password" id="PasswordAgain" name="passwordagain" placeholder="Password(Again)" value="" required="required"/>
            <br>
            <span id="E-MailLabel">E-Mail:<span class="required">*</span></span>
            <br>
            <input type="email" id="E-Mail" name="email" placeholder="E-Mail" value="" required="required"/>
            <br>
            <span id="BetaKeyLabel">Beta Key:<span class="required">*</span></span>
            <br>
            <input id="BetaKey" required="required" name="betakey" type="text" maxlength="10" placeholder="Your Beta Key" />
            <span id="Warning">All fields are required</span>
            <input name="submit" type="submit" value="Sign Up" id="SignUpButton"/>
            </form>

    In the attached files there is an image of the database table.

     

    Thank You :D

     

    post-179600-0-22711500-1441059974_thumb.png

     

     

     

     

  4. You cannot mix the use of mysqli_* and MySQL_* functions. Drop the latter since they are deprecated. See the manual

     

    Thanks, i'll keep that in mind. Changed everything to the equivalent in mysqli, updating parameters and it worked perfectly.

     

    This forum is awesome ^^

  5. So, this is my code:

    <?php
    //MySQL Information
    $servername = "****";
    $username = "****";
    $password = "****";
    $dbname = "****";
    
    // Create connection
    $conn = new mysqli($servername, $username, $password, $dbname);
    
    // Check connection
    if ($conn->connect_error) {
        die("Connection failed: " . $conn->connect_error);
    } 
    
    //Define Variable Inputed by the User
    $Mail = $_POST['email'];
    
    //Inserting Mail Query
    $result = mysql_query("INSERT INTO betakey (Mail) VALUES ('$Mail')"); //This is where the error happens
    
    //Checking if the Mail is a duplicate
    if ($result === FALSE) {
    	//Checking if the error is a duplicate error or not
        if (mysql_errno() == 1022) {
            echo("That E-Mail address is already registered for the closed alpha");
        } else {
            die(mysql_error());
        }
    }
    //Redirecting if it's not a duplicate and has been inserted into the DB
    elseif ($result === TRUE) {
    	header ("Location: BetaRegistration.php");
    }
    
    ?>
    

    I am getting this error:

    Warning: mysql_query(): No connection could be made because the target machine actively refused it. in H:\root\home\offspc-001\www\joaopteixeira\EvolutionRPG\EmailCheckUp.php on line 27

    Warning: mysql_query(): A link to the server could not be established in H:\root\home\offspc-001\www\joaopteixeira\EvolutionRPG\EmailCheckUp.php on line 27

    No connection could be made because the target machine actively refused it.

     

  6. I added the quotes and it is still not working. Same error.

     

    The error refers to line 27:

        $MailInsert = $dbname->query("INSERT INTO betakey (Mail) VALUES ('$Mail')");

    And it says Call to a member function query() on a non-object

  7. I want to make it check the database for an equal value to the one inputed by the user and if so echo a sentence saying it is already registered, and if it is not, it would just insert the data into the database table.

     

    Here's my code:

    <?php
    	$servername = "***";
    	$username = "***";
    	$password = "***";
    	$dbname = "a3108948_evorpg";
    	
    	$Mail = $_POST['email'];
    
    	// Create connection
    	$conn = new mysqli($servername, $username, $password, $dbname);
    	// Check connection
    	if ($conn->connect_error) {
        die("Connection failed: " . $conn->connect_error);
    	}
    	
    	$Mail = $_POST['email'];
    	
    	$MailInsert = $dbname->query("INSERT INTO betakey (Mail) VALUES ($Mail)");
    
    	$SearchEmail = $dbname->query("SELECT (Mail) FROM betakey WHERE Mail = $Mail");
    	
    	if ($SearchEmail->num_rows > 0) {
    		echo "That Email is already registered for the closed alpha";
    	}
    	else {
    		
    	}
    	
    	$conn->close();
    	?> 
    

    This is the error i get:

    Fatal error: Call to a member function query() on a non-object in /home/a3108948/public_html/BetaRegistration.php on line 27

  8. I forgot to mention it in the topic but yeah i used it on a element and yes it was between the style tags, still not working :( I dont really understand why.

     

    Tried this:

     @font-face {
      font-family: 'Pixelated';
      font-style: normal;
      font-weight: 300;
      src: local('Pixelated'), local('Pixelated.ttf'), url(pixelated.ttf) format('ttf');
    }

    Still not working.

  9. I'm trying to add a custom font do my website, but for some reason it isn't working. This is what i've tried:

     

    Added this to the css file(Didn't work):

    @font-face {
        font-family: Pixelated;
        src: url(pixelated.ttf);
    }

    Changed to this(Also didn't work):

    @font-face {
        font-family: Pixelated;
        src: local('pixelated.ttf');
    }

    Lastly tried to add them both (one at a time) it in the php file under style, and still didn't work.

     

     

  10. Basically i want to check through php if a HTML element's attribute value is true, for example:

    <input id="example" maxlenght="10"(...)/>
    
    //This is me imagining how it could be
    
    <?php
    if(#example:maxlenght = 10) {
    echo "Good to go";
    }
    ?>
    

    I'm not sure if i'm clear.

     

    Thank You

  11. I want to make so when the user hover's the button, it fades away to a new background-image. I managed to make it change the background-image, but the time it takes to change itself is not what i want it to be. Even if i put 6s it will still change the background-image instanstly. Here's my code:

    #SignUpButton {
    	font-family:'Oxygen',sans-serif;
    	color:#F7F7F7;
    	-webkit-border-radius: 3px;
    	-moz-border-radius: 3px;
    	border-radius: 3px;
    	margin-top:3%;
    	position:relative;
    	height:40px;
    	width:40%;
    	background-image:url("http://s8.postimg.org/o723mxtdf/Button_Dark.png");
    	margin-left:30%;
    	margin-right:30%;
    	border:none;
            transition:6s;
    }
    
    #SignUpButton:hover {
    	background-image:url("http://s11.postimg.org/6bkzpzav5/Button_Main.png");
    }
    

    Thanks

  12. So, i've been trying to make a browser game, so i created a page with a email input so people can register to the closed beta. Then i created another php page to basically say "An email will be sent to (Email inputed on previous page here) if you are selected to (...)", so i came up with this:

     

    First Page (Where the Email is Inputed) Code:

    <form method="post" action="BetaRegistration.php">
    <input type="email" id="email" name="email" placeholder="Type your E-mail Address here" value="<?= isset($_POST['email']) ? htmlspecialchars($_POST['email']) : '' ?>"required="required"/>
    <input name="submit" type="submit" value="Sign Up" id="SignUpButton"/></form>

    Second Page (Where the email inputed in the previous page is displayed):

    <p id="Introduction">An email will be sent to <strong<?php if(isset($_POST['submit'])) {
      echo htmlspecialchars($_POST['email']);
    }?></strong> if you are selected to play in the Closed Alpha. Thank You!</p>

    However, it doesn't work! In the second page it doesn't display the e-mail :( I really need help i'm new to PHP

     

    Thank You!

  13. So, today i decided i would start learning PHP, i just learned how to do while loops and i wanted to get a bit out of the comfort zone of what the tutorials i've seen gave me.

     

    So i decided to create a quick "interaction" where the player receives a random amount of damage from a monster, in this case a zombie, and then displays the damage received and the current health after the damage has been taken.

     

    This is what i have:
       

    <?php
            $LostHealth = rand(1,10);
            $Health = 100;
            if ($Health == 0) {
                echo "You are dead.";
            }
            else {
                echo "You turn around and there is a zombie coming in your direction";
                while ($Health > 0) {
                    $Health = $Health - $LostHealth;
                    echo "<p>A Zombie just hit you doing <strong>$LostHealth</strong> damage!</p>";
                    echo "<p>You now have $Health HP</p>";
                }
            }
        ?>

    However, the $LostHealth is always a fixed number everytime it loops.

     

    Thanks for the help and time

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