+ Reply to Thread
Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: [PHP] Using it in forms!

  1. #1
    War of the Lands is offline x10Hosting Member War of the Lands is an unknown quantity at this point
    Join Date
    Sep 2008
    Posts
    11

    [PHP] Using it in forms!

    Well... Im trying to get my registration/login form to work and as you can guess im not having much luck thats why im here! I use very simple php I know but I want it to work before using the more advance php. What is going wrong is on my active.php it is echoing the error varriable when it should not have been set. So please someone help me! Here is the source code:

    PHP Code:
    <?php
    require_once "config.inc.php";
    $error="";
    $submit=$_POST['submit'];
    if(
    $submit) {
         
    $user=$_POST['user'];
         
    $code=$_POST['code'];
         
    $check=mysql_query("SELECT count(*) FROM 'login' WHERE (username = '$user', active = '$code')");
         }
    if(
    $check1) {
         
    $result=mysql_query("UPDATE login SET active= '1' WHERE (username = '$user')");
         
    $error="You account has now been activated, you may now login!<br>";
         }
    else {
         
    $error="You have entered incorrect information. Try again!<br>";  
         } 
    ?>
    <html>
    <head>
    <title>War of the Lands</title>
    <link type="text/css" href="style.css" rel="stylesheet">
    </head>
    <body>
    <script type="text/javascript" src="http://x10hosting.com/adserve.js?corporate"></script>
    <h1>Activation:</h1>
    <?php echo $error?>
    <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
    <table>
    <tr>
    <td>Username :</td><td><input type="text" name="user"></td>
    </tr>
    <tr>
    <td>Activation Code :</td><td><input type="text" name="code"></td>
    </tr>
    <tr>
    <td></td><td><input type="submit" name="submit" value="Activate"></td>
    </tr>
    </table>
    </form>
    <br />
    Copyright 2008 - War of the Lands
    </body>
    </html>

  2. #2
    quantum1's Avatar
    quantum1 is offline x10Hosting Member quantum1 is an unknown quantity at this point
    Join Date
    Sep 2008
    Location
    near Nashville, TN
    Posts
    68

    Re: [PHP] Using it in forms!

    Your code above will always show "activated" or "incorrect" because you are always setting the $error variable to one or the other. You are checking variable $check and either setting variable $error to one or the other because of the if / else condition. Is this the problem you are seeing?

  3. #3
    War of the Lands is offline x10Hosting Member War of the Lands is an unknown quantity at this point
    Join Date
    Sep 2008
    Posts
    11

    Re: [PHP] Using it in forms!

    Yes... you got it in one so what would be the best way to sort this out. As you can tell I'm pretty new to php. So any help would really be very helpful thanks!

  4. #4
    dickey's Avatar
    dickey is offline x10 Sophmore dickey is an unknown quantity at this point
    Join Date
    Sep 2008
    Location
    Singapore
    Posts
    128

    Re: [PHP] Using it in forms!

    Try this code.
    PHP Code:
    <?php
    require_once "config.inc.php";
    $error="";
    $submit=$_POST['submit'];
    if(
    $submit) {
         
    $user=$_POST['user'];
         
    $code=$_POST['code'];
         
    $result=mysql_query("SELECT count(*) FROM 'login' WHERE (username = '$user', active = '$code')");
         }
         
    $check=mysql_num_rows($result);
         
    mysql_free_result($result);
    if(
    $check1) {
         
    $result=mysql_query("UPDATE login SET active= '1' WHERE (username = '$user')");
         
    $error="You account has now been activated, you may now login!<br>";
         }
    else {
         
    $error="You have entered incorrect information. Try again!<br>";  
         } 
    ?>

  5. #5
    War of the Lands is offline x10Hosting Member War of the Lands is an unknown quantity at this point
    Join Date
    Sep 2008
    Posts
    11

    Re: [PHP] Using it in forms!

    That doesnt solve the issue. It still brings up the error varriable. And it is bringing up these mysql warnings:

    Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/warland/public_html/V1/active.php on line 13

    Warning: mysql_free_result(): supplied argument is not a valid MySQL result resource in /home/warland/public_html/V1/active.php on line 14

  6. #6
    natsuki's Avatar
    natsuki is offline x10 Sophmore natsuki is an unknown quantity at this point
    Join Date
    Sep 2008
    Posts
    112

    Re: [PHP] Using it in forms!

    add to it the error check... if you have the $link it would be better though..
    PHP Code:
    <?php
    require_once 'config.inc.php';
    $error '';
    $submit $_POST['submit'];
    if (
    $submit) {
         
    $user $_POST['user'];
         
    $code $_POST['code'];
         
    $result mysql_query("SELECT count(*) FROM 'login' WHERE username = '$user' AND active = '$code';");
         if (
    mysql_errno())
         {
            die(
    'Query failed: ' mysql_error());
         }
         
    $check mysql_num_rows($result);
         
    mysql_free_result($result);
    }
    if (
    $check == 1) {
         
    $result mysql_query("UPDATE login SET active = '1' WHERE username = '$user';");
         
    $error 'You account has now been activated, you may now login!<br>';
    }
    else {
         
    $error 'You have entered incorrect information. Try again!<br>';  

    ?>
    and it's easier to read code with aligned braces "{"
    Last edited by natsuki; 10-22-2008 at 10:51 AM.

  7. #7
    War of the Lands is offline x10Hosting Member War of the Lands is an unknown quantity at this point
    Join Date
    Sep 2008
    Posts
    11

    Re: [PHP] Using it in forms!

    OK I still have problems with that but I did some changes to my register.php page to make it more advanced but in trying to do that I have screwed it up! :dunno: Well here is the code and after that I shall explain what is wrong!

    PHP Code:
    <?php

    require_once "config.inc.php";

    $error="";
    $submit=$_POST['submit'];

    if(isset(
    $submit)){

    if (!
    $_POST['user'] | !$_POST['pass'] | !$_POST['email'] ) {
         
    $error="You did not complete all of the required fields";
         }
    else {
         
    $user=$_POST['user'];
         
    $pass=$_POST['pass'];
         
    $email=$_POST['email'];
         
    $result=mysql_query("SELECT username FROM 'login' WHERE username = '$user'")or mysql_error();
         
    $check mysql_num_rows($result);
         }
    if (
    $check != 0) {
         
    $error="'$user' has already been taken please try another username!";
         }
    else {
         
    $pass2=md5($pass);
         
    $active=rand(); 
         
    $resultmysql_query("INSERT INTO login (username, password, email, active) VALUES('$user', '$pass2', '$email', '$active')") or mysql_error();  
         
         
    $to=$email;
         
    $subject="Activation - War of the Lands";
         
    $message="Your username: $user \r\n";
         
    $message.="Your activation code: $active \r\n";
         
    $message.="Copy this code into the input box on this page: \r\n";
         
    $message.="http://www.warofthelands.x10hosting.com/V1/active.php";
         
    $header="From: no-reply@warofthelands.x10hosting.com";
      
         
    mail($to$subject$message$header);
         
    header('location:regConfirm.php');
         exit;
         }
         }
    ?>
    <html>
    <head>
    <title>War of the Lands</title>
    <link type="text/css" href="style.css" rel="stylesheet">
    </head>
    <body>
    <script type="text/javascript" src="http://x10hosting.com/adserve.js?corporate"></script>
    <h1>Register:</h1><br />
    <?php echo $error?>
    <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
    <table>
    <tr>
    <td>Username :</td><td><input type="text" name="user"></td>
    </tr>
    <tr>
    <td>Password :</td><td><input type="password" name="pass"></td>
    </tr>
    <tr>
    <td>Email :</td><td><input type="text" name="email"></td>
    </tr>
    <tr>
    <td></td><td><input type="submit" name="submit" value="Register"></td>
    </tr>
    </table>
    </form>
    <br />
    Copyright 2008 - War of the Lands
    </body>
    </html>
    Well my first problem is that if I click register without filling the input boxes in it is ment to bring up an error but it doesn't. When I do enter a name and it is checked to see if it exists I get this Warning:

    Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/warland/public_html/V1/register.php on line 18

    Then it says that the output has already been started to I cannot exicute the header:

    Warning: Cannot modify header information - headers already sent by (output started at /home/warland/public_html/V1/register.php:1 in /home/warland/public_html/V1/register.php on line 38

    This is really starting to annoy me now but I shall keep going if you people are willing to help. I am learning from my mistakes!

  8. #8
    xmakina's Avatar
    xmakina is offline x10 Lieutenant xmakina is an unknown quantity at this point
    Join Date
    May 2008
    Location
    England
    Posts
    265

    Re: [PHP] Using it in forms!

    Okay. Your problem is *somewhere* in your SQL statement. That means we're pretty much unable to help you because we'd need to know the layout of your database.

    So; make your app echo your SQL statement before processing. Look in the echod string for any obvious SQL errors. If you can see one, drop it into phpMyAdmin's SQL block and see what error it returns.
    IF($this->$post.content() == "SEE SIG"){
    w3Schools and Google
    }

  9. #9
    War of the Lands is offline x10Hosting Member War of the Lands is an unknown quantity at this point
    Join Date
    Sep 2008
    Posts
    11

    Re: [PHP] Using it in forms!

    Can you explain how you would do that. Would it be a simple:

    echo "'$result'";

    ?

  10. #10
    quantum1's Avatar
    quantum1 is offline x10Hosting Member quantum1 is an unknown quantity at this point
    Join Date
    Sep 2008
    Location
    near Nashville, TN
    Posts
    68

    Re: [PHP] Using it in forms!

    Well...this may be an issue...

    In your SQL statement you have:

    SELECT username FROM 'login'

    Should the 'login' be in quotes? Quotes are needed for the values in the where clause and so forth, but I don't know about the table name itself. Try removing the quotes around 'login' so that it reads:

    SELECT username FROM login

+ Reply to Thread
Page 1 of 2 12 LastLast

Similar Threads

  1. Html forms not working-cgi prob?
    By ReeRee in forum Programming Help
    Replies: 17
    Last Post: 05-18-2009, 05:16 PM
  2. Forms have borked
    By Mekryd in forum Free Hosting
    Replies: 5
    Last Post: 03-30-2008, 12:10 PM
  3. Forms not working
    By Tom Cowley in forum Free Hosting
    Replies: 4
    Last Post: 03-25-2008, 12:59 PM
  4. Tables and Forms
    By taekwondokid42 in forum Scripts & 3rd Party Apps
    Replies: 2
    Last Post: 11-04-2007, 09:22 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers