Jump to content

Pokebert

Members
  • Posts

    18
  • Joined

  • Last visited

Posts posted by Pokebert

  1. String values like "compose" and "delete" should be enclosed in quotes (as I did), unless you have defined them as constants, but no sign of that. And where is $action variable's value defined?

     

    try adding

    var_dump($action);

    and see what it contains

     

    Where should I insert var_dump? I'm new to PHP...

  2. Code is now:

    
    <?PHP
    
    INCLUDE("dbconn.php");
    $result1=MYSQL_QUERY("select * from users WHERE username='$username'") or DIE ("cant do it");
    $row100 = MYSQL_FETCH_ARRAY($result1);
    
    ini_set('display_errors',1);
    error_reporting(E_ALL);
    ?>
    <html>
    <head>
    <title>
    NintendoVille - Mail
    </title>
    <meta name='viewport' content='width=320'>
    <style>
    body
    {
    background-color:#FFFFFF;
    padding: 0px;
    margin: 0px;
    }
    #topscreen
    {
    width: 320px;
    height: 218px;
    background-color:#FFFFFF;
    }
    #bottomscreen
    {
    width: 320px;
    height: 400px;
    background-color:#C8C8C8;
    }
    #marquee
    {
    width: 320px;
    height: 20px;
    background-color:#B0B0B0;
    border-radius: 7px;
    }
    #credits
    {
    width: 320px;
    height: 20px;
    background-color:#B0B0B0;
    border-radius: 7px;
    }
    #infos
    {
    width: 320px;
    height: 60px;
    background-color:#B0B0B0;
    border-radius: 7px;
    }
    #text
    {
    width: 320px;
    height: 20px;
    background-color:#B0B0B0;
    border-radius: 7px;
    }
    </style>
    </head>
    <body>
    <div id='topscreen'>
    <img src="../NintendoVilleLogoBeta.jpg.jpg" width=320px height=217px>
    </div>
    <div id='bottomscreen'>
    <br>
    <center>| <a href="mail.php?action=compose">Compose</a> | <a href="mail.php?action=inbox">Inbox</a> | </center>
    <table cellpadding="1" cellspacing="1" height="300" width="320">
    <tr><td align=center valign=top>
    <?PHP
    IF($action=='compose') {
    ECHO "<form action=mail.php?action=compose2 method=post>";
    ECHO "<table>";
    ECHO "<tr><td>Subject:</td><td><input type=text name=subject size=20 value=$subject></td></tr>";
    ECHO "<tr><td>To:</td><td><input type=text name=to size=20 value=$to></td></tr>";
    ECHO "<tr><td>Message:</td><td><textarea rows=16 cols=45 name=message></text></td></tr>";
    ECHO "<tr><td><button type=submit>Send Mail!</button></td></tr>";
    ECHO "</table>";
    ECHO "</form>";
    }
    IF($action=='compose2') {
    $subject or DIE("Subject Blank");
    $message or DIE("Message Black");
    $to or DIE("To blank");
    $date = DATE(YmdHis);
    
    
    
    $create = "INSERT INTO mail (UserTo, UserFrom, Subject, Message, SentDate, status)
    VALUES ('$to','$username','$subject','$message','$date','unread')";
    $create2 = MYSQL_QUERY($create) or DIE("A letter could not be sent to $to!");
    ECHO("Message Sent to $to!");
    
    }
    IF($action=='inbox') {
    $result=MYSQL_QUERY("select * from mail where UserTo='$username' ORDER BY SentDate DESC") or DIE ("cant do it");
    ECHO "<table cellpadding=2 cellspacing=1 width=500 valign=top>";
    WHILE ($row=MYSQL_FETCH_ARRAY($result)) {
    ECHO "<tr><td width=30>Mail:</td><td><a href=mail.php?action=veiw&mail_id=$row[mail_id]>$row[subject]</a></td><td width=50> <a href=mail.php?action=delete&id=$row[mail_id]><center>Delete</a><br></td></tr>";
    }
    ECHO "</table>";
    }
    IF($action=='veiw') {
    $result=MYSQL_QUERY("select * from mail where UserTo='$username' and mail_id=$mail_id") or DIE ("cant do it");
    $row=MYSQL_FETCH_ARRAY($result);
    IF($row[userTo]==$username) {
    } ELSE {
    ECHO "<font face=verdana><b>This isn't your mail!";
    EXIT;
    }
    $query="UPDATE mail SET status='read' WHERE UserTo='$username' AND mail_id='$row[mail_id]'";
    $query or DIE("An error occurred resulting that this message has not been marked read.");
    ECHO "<table border = 1 bordercolor = black width = 50% align=center><tr><td>$row[subject]</td><td>$row[userFrom]</td></tr><tr><td colspan='2'>$row[Message]<br><a href=mail.php?action=compose&to=$row[userFrom]&subject=RE:$row[subject]>Reply</a></td></tr></table>";
    $rs = MYSQL_QUERY("UPDATE mail SET status='read' WHERE mail_id='$mail_id'");
    }
    IF($action=='delete') {
    $query = MYSQL_QUERY("DELETE FROM mail WHERE mail_id='$id' LIMIT 1");
    IF($query) {
    ECHO "<font face=verdana>Message Deleted.</font>";
    } ELSE {
    ECHO "The message wasnt deleted.";
    }
    }
    ?>
    <br>
    </div>
    </body>
    </html>
    

     

    And i fixed undefined constants but still get:

    Notice: Undefined variable: action in/home/u253096179/public_html/Member System/mail.php on line 75

     

    Notice: Undefined variable: action in/home/u253096179/public_html/Member System/mail.php on line 86

     

    Notice: Undefined variable: action in/home/u253096179/public_html/Member System/mail.php on line 101

     

    Notice: Undefined variable: action in/home/u253096179/public_html/Member System/mail.php on line 110

     

    Notice: Undefined variable: action in/home/u253096179/public_html/Member System/mail.php on line 124

     

     

    So how should I fix this? And since I'm very new to PHP could I get an example piece of coding?

  3. I can't get to get this code to display anything other than " |Compose | Inbox | and I can't seem to fins the issue in the code. Can someone help me with this? An example of this mail system can be seen at http://nintendoville.3owl.com/Member%20System/mail.php

     

    <?PHP 
    
    INCLUDE("dbconn.php"); 
    $result1=MYSQL_QUERY("select * from users WHERE username='$username'") or DIE ("cant do it"); 
    $row100 = MYSQL_FETCH_ARRAY($result1); 
    ?> 
    <html>
    <head>
    <title>
    NintendoVille - Mail
    </title>
    <meta name='viewport' content='width=320'>
    <style>
    body
    {
    background-color:#FFFFFF;
    padding: 0px;
    margin: 0px;
    }
    #topscreen
    {
    width: 320px;
    height: 218px;
    background-color:#FFFFFF;
    }
    #bottomscreen
    {
    width: 320px;
    height: 400px;
    background-color:#C8C8C8;
    }
    #marquee
    {
    width: 320px;
    height: 20px;
    background-color:#B0B0B0;
    border-radius: 7px;
    }
    #credits
    {
    width: 320px;
    height: 20px;
    background-color:#B0B0B0;
    border-radius: 7px;
    }
    #infos
    {
    width: 320px;
    height: 60px;
    background-color:#B0B0B0;
    border-radius: 7px;
    }
    #text
    {
    width: 320px;
    height: 20px;
    background-color:#B0B0B0;
    border-radius: 7px;
    }
    </style>
    </head>
    <body>
    <div id='topscreen'>
    <img src="../NintendoVilleLogoBeta.jpg.jpg" width=320px height=217px>
    </div>
    <div id='bottomscreen'>
    <br>
    <center>| <a href="mail.php?action=compose">Compose</a> | <a href="mail.php?action=inbox">Inbox</a> | </center>
    <table cellpadding="1" cellspacing="1" height="300" width="320"> 
    <tr><td align=center valign=top> 
    <?PHP 
    IF($action==compose) { 
    ECHO "<form action=mail.php?action=compose2 method=post>"; 
    ECHO "<table>"; 
    ECHO "<tr><td>Subject:</td><td><input type=text name=subject size=20 value=$subject></td></tr>"; 
    ECHO "<tr><td>To:</td><td><input type=text name=to size=20 value=$to></td></tr>"; 
    ECHO "<tr><td>Message:</td><td><textarea rows=16 cols=45 name=message></text></td></tr>"; 
    ECHO "<tr><td><button type=submit>Send Mail!</button></td></tr>"; 
    ECHO "</table>"; 
    ECHO "</form>"; 
    } 
    IF($action==compose2) { 
    $subject or DIE("Subject Blank"); 
    $message or DIE("Message Black"); 
    $to or DIE("To blank"); 
    $date = DATE(YmdHis); 
    
    
    $create = "INSERT INTO mail (UserTo, UserFrom, Subject, Message, SentDate, status) 
    VALUES ('$to','$username','$subject','$message','$date','unread')"; 
    $create2 = MYSQL_QUERY($create) or DIE("A letter could not be sent to $to!"); 
    ECHO("Message Sent to $to!"); 
    
    } 
    IF($action==inbox) { 
    $result=MYSQL_QUERY("select * from mail where UserTo='$username' ORDER BY SentDate DESC") or DIE ("cant do it"); 
    ECHO "<table cellpadding=2 cellspacing=1 width=500 valign=top>"; 
    WHILE ($row=MYSQL_FETCH_ARRAY($result)) { 
    ECHO "<tr><td width=30>Mail:</td><td><a href=mail.php?action=veiw&mail_id=$row[mail_id]>$row[subject]</a></td><td width=50> <a href=mail.php?action=delete&id=$row[mail_id]><center>Delete</a><br></td></tr>"; 
    } 
    ECHO "</table>"; 
    } 
    IF($action==veiw) { 
    $result=MYSQL_QUERY("select * from mail where UserTo='$username' and mail_id=$mail_id") or DIE ("cant do it"); 
    $row=MYSQL_FETCH_ARRAY($result); 
    IF($row[userTo]==$username) { 
    } ELSE { 
    ECHO "<font face=verdana><b>This isn't your mail!"; 
    EXIT; 
    } 
    $query="UPDATE mail SET status='read' WHERE UserTo='$username' AND mail_id='$row[mail_id]'"; 
    $query or DIE("An error occurred resulting that this message has not been marked read."); 
    ECHO "<table border = 1 bordercolor = black width = 50% align=center><tr><td>$row[subject]</td><td>$row[userFrom]</td></tr><tr><td colspan='2'>$row[Message]<br><a href=mail.php?action=compose&to=$row[userFrom]&subject=RE:$row[subject]>Reply</a></td></tr></table>"; 
    $rs = MYSQL_QUERY("UPDATE mail SET status='read' WHERE mail_id='$mail_id'"); 
    } 
    IF($action==delete) { 
    $query = MYSQL_QUERY("DELETE FROM mail WHERE mail_id='$id' LIMIT 1"); 
    IF($query) { 
    ECHO "<font face=verdana>Message Deleted.</font>"; 
    } ELSE { 
    ECHO "The message wasnt deleted."; 
    } 
    } 
    ?> 
    <br>
    </div>
    </body>
    </html>
    

  4. Headers are data describing the document that is about to be sent. For example, the encoding of the document, the document filename, the creation date etc. You can also send a header that forces the browser to redirect to a different page (as you are doing in your script).

     

    The thing is, all headers have to be sent before any output is sent to the browser, because they describe the document to follow. When you get these errors, it means the script has sent some data to the browser, and then after that data has been sent, the script has tried to set a header. Well it can't set a header, because the headers have already been sent to the browser, before the data that was sent to the browser.

     

    Now you are probably thinking you haven't sent any data to the browser, because you haven't used 'echo' or 'print' before the headers. Look at the error messages:

     

    headers already sent by (output started at /home/u253096179/public_html/login.php:1)

    headers already sent by (output started at /home/u253096179/public_html/members.php:1)

     

    The message is telling you that the headers have already been sent to the browser, and the location where this happened. In your case, the first error is one line 1 of login.php, and in the second case at line 1 of members.php.

     

    I'd bet a dollar to a donut that you have your opening php tag on the second line of your document. Either that, or you have a space before your opening php tag on the first line. Either way, because PHP has not been opened, this line is sent to the browser, and then your script is executed.

     

    There is one other possibility as well however, if neither of the above is true. You may be sending a BOM (a type of invisible character) automatically due to the settings in your editor. To test this, you will have to look through the documentation of your editor and see if you can turn this option off.

     

    ... there was a space behind the headers. :l

  5. Great. Now I just found out my other script is having header issues too.

     

    Warning: Cannot modify header information - headers already sent by (output started at /home/u253096179/public_html/members.php:1) in /home/u253096179/public_html/members.php on line 64

     

    
    <?php
    
    // Connects to your Database
    
    mysql_connect("***", "***", "***") or die(mysql_error());
    
    mysql_select_db("***") or die(mysql_error());
    
    
    //checks cookies to make sure they are logged in
    
    if(isset($_COOKIE['ID_my_site']))
    
    {
    
     $username = $_COOKIE['ID_my_site'];
    
     $pass = $_COOKIE['Key_my_site'];
    
    $check = mysql_query("SELECT * FROM users WHERE username = '$username'")or die(mysql_error());
    
     while($info = mysql_fetch_array( $check ))  
    
     {
    
    
    
    //if the cookie has the wrong password, they are taken to the login page
    
     if ($pass != $info['password'])
    
     {  header("Location: login.php");
    
     }
    
    
    
    //otherwise they are shown the admin area
    
     else
    
     {
    
      echo "Admin Area<p>";
    
    echo "Your Content<p>";
    
    echo "<a href=logout.php>Logout</a>";
    
     }
    
     }
    
     }
    
    else
    
    
    
    //if the cookie does not exist, they are taken to the login screen
    
    {
    
    header("Location: login.php");
    
    }
    
    ?>
    

  6. Yes, I know the sticky'd topic said how to fix it, but I'm new to PHP (I just began to learn) and didn't quite understand how to fix this script. I get these three errors:

    Warning: Cannot modify header information - headers already sent by (output started at /home/u253096179/public_html/login.php:1) in /home/u253096179/public_html/login.php on line 117

     

    Warning: Cannot modify header information - headers already sent by (output started at /home/u253096179/public_html/login.php:1) in /home/u253096179/public_html/login.php on line 119

     

    Warning: Cannot modify header information - headers already sent by (output started at /home/u253096179/public_html/login.php:1) in /home/u253096179/public_html/login.php on line 125

     

    My code is:

     

    My code is:

    
    <?php 
    
    // Connects to your Database 
    
    mysql_connect("***********", "**********", "************") or die(mysql_error()); 
    
    mysql_select_db("**************") or die(mysql_error()); 
    
    
    //Checks if there is a login cookie
    
    if(isset($_COOKIE['ID_my_site']))
    
    
    //if there is, it logs you in and directes you to the members page
    
    { 
     $username = $_COOKIE['ID_my_site']; 
    
     $pass = $_COOKIE['Key_my_site'];
    
       $check = mysql_query("SELECT * FROM users WHERE username = '$username'")or die(mysql_error());
    
     while($info = mysql_fetch_array( $check ))  
    
     {
    
     if ($pass != $info['password']) 
    
     {
    
       }
    
     else
    
     {
    
     header("Location: members.php");
    
    
    
     }
    
     }
    
    }
    
    
    //if the login form is submitted 
    
    if (isset($_POST['submit'])) { // if form has been submitted
    
    
    
    // makes sure they filled it in
    
     if(!$_POST['username'] | !$_POST['pass']) {
    
     die('You did not fill in a required field.');
    
     }
    
     // checks it against the database
    
    
    
     if (!get_magic_quotes_gpc()) {
    
     $_POST['email'] = addslashes($_POST['email']);
    
     }
    
     $check = mysql_query("SELECT * FROM users WHERE username = '".$_POST['username']."'")or die(mysql_error());
    
    
    
    //Gives error if user dosen't exist
    
    $check2 = mysql_num_rows($check);
    
    if ($check2 == 0) {
    
     die('That user does not exist in our database. <a href=register.php>Click Here to Register</a>');
    
     }
    
    while($info = mysql_fetch_array( $check ))  
    
    {
    
    $_POST['pass'] = stripslashes($_POST['pass']);
    
     $info['password'] = stripslashes($info['password']);
    
     $_POST['pass'] = md5($_POST['pass']);
    
    
    
    //gives error if the password is wrong
    
     if ($_POST['pass'] != $info['password']) {
    
     die('Incorrect password, please try again.');
    
     }
    else 
    
    { 
    
    
    // if login is ok then we add a cookie 
    
      $_POST['username'] = stripslashes($_POST['username']); 
    
      $hour = time() + 3600; 
    
    setcookie(ID_my_site, $_POST['username'], $hour); 
    
    setcookie(Key_my_site, $_POST['pass'], $hour); 
    
    
    
    //then redirect them to the members area 
    
    header("Location: members.php"); 
    
    } 
    
    } 
    
    } 
    
    else 
    
    { 
    
    
    
    // if they are not logged in 
    
    ?> 
    <html>
    <head>
    <title>
    NintendoVille - Login
    </title>
    <meta name='viewport' content='width=320'>
    <style>
    body
    {
    padding: 0px;
    margin: 0px;
    }
    #topscreen
    {
    width: 320px;
    height: 218px;
    background-color:#FFFFFF;
    }
    #bottomscreen
    {
    width: 320px;
    height: 212px;
    background-color:#C8C8C8;
    }
    #marquee
    {
    width: 320px;
    height: 20px;
    background-color:#B0B0B0;
    border-radius: 25px;
    }
    #credits
    {
    width: 320px;
    height: 20px;
    background-color:#B0B0B0;
    border-radius: 25px;
    }
    </style>
    </head>
    <body>
    <div id='topscreen'>
    <img src="NintendoVilleLogoBeta.jpg.jpg" width=320px height=217px>
    </div>
    <div id='bottomscreen'>
    <center>
    <form action="<?php echo $_SERVER['PHP_SELF']?>" method="post"> 
    
    <table border="0"> 
    
    <tr><td colspan=2><h1>Login</h1></td></tr> 
    
    <tr><td>Username:</td><td> 
    
    <input type="text" name="username" maxlength="40"> 
    
    </td></tr> 
    
    <tr><td>Password:</td><td> 
    
    <input type="password" name="pass" maxlength="50"> 
    
    </td></tr> 
    
    <tr><td colspan="2" align="right"> 
    
    <input type="submit" name="submit" value="Login"> 
    
    </td></tr> 
    
    </table> 
    
    </form> 
    </center>
    <br>
    <div id="credits">
    <center> Copyright 2012 - NintendoVille</center>
    </div>
    </div>
    
    <?php 
    
    } 
    
    
    
    ?> 
    

  7. Edited the code:

    
    
    
    
    <?php
    
    session_start();
    //CREDITS TO MODERNSONIC FROM 3DSPLAZA-3DSPAINT-SOMELUIGI.COM-3DSMEGUSTA-DSISTARZ for this chat script!
    //CREDITS TO MARIOERMANDO FOR THE TABLE CREATOR
    //CREDITS TO JUNAID FOR THE AUTO REFRESH...THAT WILL ONLY WORKS IF YOU SEPARATE THE MESSAGE FILE.
    ?>
    
    
    
    
    
    <?
    //AUTO TABLE CREATOR BY MARIOERMANDO
    //http://3DSFun.heliohost.org/
    //http://marioermando.tumblr.com
    //database infos
    $con = mysql_connect("mysql10.000webhost.com","a6743732_pokeb",**********");
    if (!$con)
    {
    die('Could not connect: ' . mysql_error());
    }
    
    mysql_select_db("a6743732_pokeb", $con);
    ?>
    
    
    
    
    
    
    
    
    
    
    
    <script type='text/javascript'>
    function updateChat()
    {
    var xmlhttp;
    if (window.XMLHttpRequest)
    {// code for IE7+, Firefox, Chrome, Opera, Safari
    xmlhttp = new XMLHttpRequest();
    }
    else
    {// code for IE6, IE5
    xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.onreadystatechange = function()
    {
    if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
    {
    document.getElementById("").innerHTML = xmlhttp.responseText;
    }
    }
    xmlhttp.open("GET",".php?error=",true);
    xmlhttp.send();
    }
    </script>
    <body onload="setInterval('updateChat()',2000);">
    
    <div id="chat" style="witdth:320px height:200px; overflow:auto;">
    <?php
    
    
    
    
    $user = $_SESSION['username'];
    
    
    
    $result = mysql_query($sql) or die(mysql_error());
    
    
    
    
    if ($_POST['submit'])
    {
    $_POST['message'] = mysql_real_escape_string(htmlentities($_POST['message']));
    
    
    
    
    
    $sql = "INSERT INTO chat (user, message) VALUES ('$user', '$_POST[message]')";
    $result = mysql_query($sql) or die();
    
    
    }
    
    
    
    session_start();
    
    if (!empty($_SESSION['username'])) // he got it.
    {
    echo "";
    }
    else // bad info.
    {
    header('Location: connexion.php');
    }
    //db connect
    
    $user = $_SESSION['username'];
    
    
    
    $con = mysql_connect("mysql10.000webhost.com","a6743732_pokeb","***********");
    if (!$con)
    {
    die('Could not connect: ' . mysql_error());
    }
    
    mysql_select_db("a6743732_pokeb", $con);
    //max messages
    $result = mysql_query("SELECT * FROM chat ORDER BY id DESC LIMIT 0, 15");
    while($row = mysql_fetch_array($result))
    {
    //smilies
    $smIn=array("R:");
    $smOut=array("EPIC FACE URL");
    
    $o_user = $row['user'];
    $message = $row['message'];
    $message = str_replace($smIn, $smOut, $message);
    
    
    echo '<u>'. $o_user . '</u>: '. $message . '</font>'. '</font>'. '</b>' ;
    echo "<br>";
    }
    
    
    ?>
    </div>
    <style>
    #chat
    {
    background-color:green;
    width:320px;
    height:200px;
    overflow:auto;
    }
    </style>
    <form action="chat.php" method="POST">
    <input type="text" name="message"><input type="submit" value="Chat" name="submit">
    </form>
    <meta name="viewport" content="width=320">
    <br>
    <a href="index.php"><img src="http://png-2.findicons.com/files/icons/1572/minicons/48/refresh.png"></a>refresh
    <br>
    Chat!
    
    </body>
    
    

     

    Now i simply get:

    "Query was empty"

  8. I keep getting error:

     

     

     

    PHP Error Message

    Warning: mysql_query() [function.mysql-query]: Access denied for user 'a6743732'@'localhost' (using password: NO) in /home/a6743732/public_html/chat.php on line 25

     

     

     

    PHP Error Message

    Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in /home/a6743732/public_html/chat.php on line 25

     

     

     

    Access denied for user 'a6743732'@'localhost' (using password: NO)

     

    
    
    
    
    <?php
    
    session_start();
    //CREDITS TO MODERNSONIC FROM 3DSPLAZA-3DSPAINT-SOMELUIGI.COM-3DSMEGUSTA-DSISTARZ for this chat script!
    //CREDITS TO MARIOERMANDO FOR THE TABLE CREATOR
    //CREDITS TO JUNAID FOR THE AUTO REFRESH...THAT WILL ONLY WORKS IF YOU SEPARATE THE MESSAGE FILE.
    ?>
    
    
    
    
    
    <?
    //AUTO TABLE CREATOR BY MARIOERMANDO
    //http://3DSFun.heliohost.org/
    //http://marioermando.tumblr.com
    $sql = "CREATE TABLE chat(
    id INT NOT NULL AUTO_INCREMENT,
    PRIMARY KEY(id),
    user TEXT(30),
    message TEXT(40))";
    $result = mysql_query($sql) or die(mysql_error());
    ?>
    
    
    
    
    
    
    
    
    
    
    
    <script type='text/javascript'>
    function updateChat()
    {
    var xmlhttp;
    if (window.XMLHttpRequest)
    {// code for IE7+, Firefox, Chrome, Opera, Safari
    xmlhttp = new XMLHttpRequest();
    }
    else
    {// code for IE6, IE5
    xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.onreadystatechange = function()
    {
    if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
    {
    document.getElementById("").innerHTML = xmlhttp.responseText;
    }
    }
    xmlhttp.open("GET",".php?error=",true);
    xmlhttp.send();
    }
    </script>
    <body onload="setInterval('updateChat()',2000);">
    
    <div id="chat" style="witdth:320px height:200px; overflow:auto;">
    <?php
    
    
    
    
    $user = $_SESSION['username'];
    
    
    //database infos
    $con = mysql_connect("mysql10.000webhost.com","a6743732_pokeb","***********");
    if (!$con)
    {
    die('Could not connect: ' . mysql_error());
    }
    
    mysql_select_db("a6743732_pokeb", $con);
    
    
    
    
    if ($_POST['submit'])
    {
    $_POST['message'] = mysql_real_escape_string(htmlentities($_POST['message']));
    
    
    
    
    
    $sql = "INSERT INTO chat (user, message) VALUES ('$user', '$_POST[message]')";
    $result = mysql_query($sql) or die();
    
    
    }
    
    
    
    session_start();
    
    if (!empty($_SESSION['username'])) // he got it.
    {
    echo "";
    }
    else // bad info.
    {
    header('Location: connexion.php');
    }
    //db connect
    
    $user = $_SESSION['username'];
    
    
    
    $con = mysql_connect("mysql10.000webhost.com","a6743732_pokeb","***********");
    if (!$con)
    {
    die('Could not connect: ' . mysql_error());
    }
    
    mysql_select_db("a6743732_pokeb", $con);
    //max messages
    $result = mysql_query("SELECT * FROM chat ORDER BY id DESC LIMIT 0, 15");
    while($row = mysql_fetch_array($result))
    {
    //smilies
    $smIn=array("R:");
    $smOut=array("EPIC FACE URL");
    
    $o_user = $row['user'];
    $message = $row['message'];
    $message = str_replace($smIn, $smOut, $message);
    
    
    echo '<u>'. $o_user . '</u>: '. $message . '</font>'. '</font>'. '</b>' ;
    echo "<br>";
    }
    
    
    ?>
    </div>
    <style>
    #chat
    {
    background-color:green;
    width:320px;
    height:200px;
    overflow:auto;
    }
    </style>
    <form action="chat.php" method="POST">
    <input type="text" name="message"><input type="submit" value="Chat" name="submit">
    </form>
    <meta name="viewport" content="width=320">
    <br>
    <a href="index.php"><img src="[url="http://png-2.findicons.com/files/icons/1572/minicons/48/refresh.png%22></a>refresh"]http://png-2.findico...ng"></a>refresh[/url]
    <br>
    Chat!
    
    </body>
    
    

  9. I am getting error "Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/a6743732/public_html/sign_up.php on line 46" and "Query was empty". Code is:

     

    <?php

    include('config.php');

    ?>

    <!DOCTYPE html>

    <html>

    <meta name="viewport" content="width=device-width">

    <link rel="stylesheet" type="text/css" href="style.css">

    <head>

    <title>PokeVille</title>

    </head>

    <body>

    <div id="header">

    <center><img src="http://s13.postimage.org/citvl9c9f/Poke_Ville_Index_Sprite.png" alt="PokeVille Logo" width="240" height="100"></center>

    <center><a href="sign_up.php">Register</a> |

    <a href="connexion.php">Login</a></center>

    </div>

    <br>

    <?php

    //We check if the form has been sent

    if(isset($_POST['username'], $_POST['password'], $_POST['passverif'], $_POST['email'], $_POST['avatar']) and $_POST['username']!='')

    {

    //We remove slashes depending on the configuration

    if(get_magic_quotes_gpc())

    {

    $_POST['username'] = stripslashes($_POST['username']);

    $_POST['password'] = stripslashes($_POST['password']);

    $_POST['passverif'] = stripslashes($_POST['passverif']);

    $_POST['email'] = stripslashes($_POST['email']);

    $_POST['avatar'] = stripslashes($_POST['avatar']);

    }

    //We check if the two passwords are identical

    if($_POST['password']==$_POST['passverif'])

    {

    //We check if the password has 6 or more characters

    if(strlen($_POST['password'])>=6)

    {

    //We check if the email form is valid

    if(preg_match('#^(([a-z0-9!\#$%&\\\'*+/=?^_`{|}~-]+\.?)*[a-z0-9!\#$%&\\\'*+/=?^_`{|}~-]+)@(([a-z0-9-_]+\.?)*[a-z0-9-_]+)\.[a-z]{2,}$#i',$_POST['email']))

    {

    //We protect the variables

    $username = mysql_real_escape_string($_POST['username']);

    $password = mysql_real_escape_string($_POST['password']);

    $email = mysql_real_escape_string($_POST['email']);

    $avatar = mysql_real_escape_string($_POST['avatar']);

    //We check if there is no other user using the same username

    $dn = mysql_num_rows(mysql_query('select id from users where username="'.$username.'"'));

    $ret = mysql_query($query) or die(mysql_error());

    if($dn==0)

    {

    //We count the number of users to give an ID to this one

    $dn2 = mysql_num_rows(mysql_query('select id from users'));

    $id = $dn2+1;

    //We save the informations to the databse

    if(mysql_query('insert into users(id, username, password, email, avatar, signup_date) values ('.$id.', "'.$username.'", "'.$password.'", "'.$email.'", "'.$avatar.'", "'.time().'")'))

    {

    //We dont display the form

    $form = false;

    ?>

    <div class="message">You have successfuly been signed up. You can log in.<br />

    <a href="connexion.php">Log in</a></div>

    <?php

    }

    else

    {

    //Otherwise, we say that an error occured

    $form = true;

    $message = 'An error occurred while signing up.';

    }

    }

    else

    {

    //Otherwise, we say the username is not available

    $form = true;

    $message = 'The username you want to use is not available, please choose another one.';

    }

    }

    else

    {

    //Otherwise, we say the email is not valid

    $form = true;

    $message = 'The email you entered is not valid.';

    }

    }

    else

    {

    //Otherwise, we say the password is too short

    $form = true;

    $message = 'Your password must contain at least 6 characters.';

    }

    }

    else

    {

    //Otherwise, we say the passwords are not identical

    $form = true;

    $message = 'The passwords you entered are not identical.';

    }

    }

    else

    {

    $form = true;

    }

    if($form)

    {

    //We display a message if necessary

    if(isset($message))

    {

    echo '<div class="message">'.$message.'</div>';

    }

    //We display the form

    ?>

    <div class="content">

    <form action="sign_up.php" method="post">

    Please fill the following form to sign up:<br />

    <div class="center">

    <label for="username">Username</label><input type="text" name="username" value="<?php if(isset($_POST['username'])){echo htmlentities($_POST['username'], ENT_QUOTES, 'UTF-8');} ?>" /><br />

    <label for="password">Password<span class="small">(6 characters min.)</span></label><input type="password" name="password" /><br />

    <label for="passverif">Password<span class="small">(verification)</span></label><input type="password" name="passverif" /><br />

    <label for="email">Email</label><input type="text" name="email" value="<?php if(isset($_POST['email'])){echo htmlentities($_POST['email'], ENT_QUOTES, 'UTF-8');} ?>" /><br />

    <label for="avatar">Avatar<span class="small">(optional)</span></label><input type="text" name="avatar" value="<?php if(isset($_POST['avatar'])){echo htmlentities($_POST['avatar'], ENT_QUOTES, 'UTF-8');} ?>" /><br />

    <input type="submit" value="Sign up" />

    </div>

    </form>

    </div>

    <?php

    }

    ?>

    <div class="foot"><a href="<?php echo $url_home; ?>">Go Home</a> - <a href="http://www.webestools.com/">Webestools</a></div>

    </body>

    </html>

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