Jump to content

blueman378

Members
  • Posts

    888
  • Joined

  • Last visited

    Never

Posts posted by blueman378

  1. Hi guys, im just curious as to how much information you can get from a users (involuntarily) with a combination of php and javascript,

     

    eg i know you can get:

     

    a users OS

    a users IP

    a users Browser

    a users Locale

     

    but what else can you grab?

  2. oh sorry mate,

     

    um here you go

     

    </html>
    <head>
    
    <title>myform</title>
    
    </head>
    
    <body>
    
      <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
    
        Name: <br />
        
          <input type="text" name="name" size="30" value="<?php if(!empty($_SESSION['name'])) { echo $_SESSION['name']; } ?>" /><br />
          <?php if(!empty($_SESSION['nameerror'])){ echo "The name field cannot be left empty!"; } ?>
        
        Email: <br />
          <input type="text" name="email" size="30" value="<?php if(!empty($_SESSION['email'])) { echo $_SESSION['email']; } ?>" /><br />
          <?php if(!empty($_SESSION['emailerror'])){ echo "The email field cannot be left empty!"; } ?>
          <input type="submit" value="Submit" />
       
      </form>
    
    </body>
    </html>
    <?php 
    $_SESSION['emailerror'] = ''; 
    $_SESSION['nameerror'] = ''; 
    $_SESSION['email'] = '';
    $_SESSION['name'] = '';  
    
    if($_POST['submit'])
    {
     if(empty($_POST['email']) && empty($_POST['name']))
    {
     	$_SESSION['emailerror'] = '1';
     	$_SESSION['nameerror'] = '1';
     	header("location: $_SERVER[php_SELF]");
    }
    elseif(empty($_POST['email']))
    {
    	$_SESSION['emailerror'] = '1';
    	$_SESSION['name'] = $_POST['name'];
     	header("location: $_SERVER[php_SELF]");	
    }
    elseif(empty($_POST['name']))
    {
    	$_SESSION['nameerror'] = '1';
    	$_SESSION['email'] = $_POST['email'];
     	header("location: $_SERVER[php_SELF]");	
    }
    
    $databasename='week3'; // Name of the database
    $tablename='email'; // Name of the table
    $mysqladd='localhost'; // Address to the MySQL Server - Usually localhost or an IP address
    $mysqluser='root'; // Your MySQL UserName
    $mysqlpass=''; // Your MySQL Password
    @$name = addslashes($_POST['name']);
    @$email = addslashes($_POST['email']);
    
    ///CONNECT TO MYSQL working
    $link=mysql_connect($mysqladd,$mysqluser,$mysqlpass) or die('Database Error: ' . mysql_error());
    
    
    //CONNECT TO DATABASE working
    mysql_select_db($databasename, $link) or die('Could not connect to table: ' . mysql_error());
    
    //Get data from Text, Post data to database working
    $strQuery = "INSERT INTO `email`(`name`,`email`)VALUES (\"$name\",\"$email\")" ;
    $result = mysql_query($strQuery);
    if (!$result) 
    {
    	die('Invalid query: ' . mysql_error());
    }
    
    // print data table from database
    
    $result = mysql_query("SELECT * FROM email");
    
    while($row = mysql_fetch_array($result))
      	{
      
      		echo $row['name'];
      		echo $row['email'];
      		echo "<hr />";
        }
      	// this doesn't return all the data in the table. It is only returning what I just entered.
    }
    ?>
    

     

    youll nitoce i changed test.php to the php server variable PHP_SELF, this basically says use this file as the action

  3. also i might point out i learnt php without a single book, i simply thought of a project i wanted to do 9in my case a forum) broke it down into each part i will need to learn and started googling.

     

    matt

  4. Sure,

     

    the basics of what i changed was

    see how everything after the

    $_SESSION['emailerror'] = ''; 
    $_SESSION['nameerror'] = ''; 
    $_SESSION['email'] = '';
    $_SESSION['name'] = ''; 
    

     

    is encased in the

    if(isset($_POST['submit'])) { }

     

    youll notice your submit button is called submit so basically its saying only run the code if $_POST['submit'] is set.

    which the only way this can get set is via pressing the submit button.

     

    as for the error handling thats jsut an extra i added in.

    basically you'll see that i have put

    <?php if(!empty($_SESSION['nameerror'])){ echo "The name field cannot be left empty!"; } ?>

    with the name changed for email). that basically says if the error session is NOT(!) empty then display the message.

     

    These only get set if they are empty.

    this is so that your users dont get confused as to why it is not submitting there details.

     

    not youll notice ive added

    value="<?php if(!empty($_SESSION['name'])) { echo $_SESSION['name']; } ?>"

    (with the name changed for email again)

    this is simply saying if the value is set the echo it there.

     

    this means that if your user puts in the email but not the name then they will get the message saying they cant leave name blank, and email will already be filled out for them.

     

    this part here

    $_SESSION['emailerror'] = ''; 
    $_SESSION['nameerror'] = ''; 
    $_SESSION['email'] = '';
    $_SESSION['name'] = ''; 
    

    is after the form. because the values get shown in the form we cant clear it above the form.

     

    and we have to clear it above the if statements because the value in the if statements will not get set.

     

    any other questions just ask.

     

    btw good on you for asking to get it explained, alot of people simply go ive got working code i dont need to know how it works and thats wrong, because then we end up with those same poeple asking the same questions again.

     

    Matt

     

     

  5. i jsut showed you up there

     

     <?php //some php code here ?>

     

    anyway this is proborably what you want i also added in some error handling for you.

     

    </html>
    <head>
    
    <title>myform</title>
    
    </head>
    
    <body>
    
      <form method="post" action="test.php">
    
        Name: <br />
        
          <input type="text" name="name" size="30" value="<?php if(!empty($_SESSION['name'])) { echo $_SESSION['name']; } ?>" /><br />
          <?php if(!empty($_SESSION['nameerror'])){ echo "The name field cannot be left empty!"; } ?>
        
        Email: <br />
          <input type="text" name="email" size="30" value="<?php if(!empty($_SESSION['email'])) { echo $_SESSION['email']; } ?>" /><br />
          <?php if(!empty($_SESSION['emailerror'])){ echo "The email field cannot be left empty!"; } ?>
          <input type="submit" value="Submit" />
       
      </form>
    
    </body>
    </html>
    <?php 
    $_SESSION['emailerror'] = ''; 
    $_SESSION['nameerror'] = ''; 
    $_SESSION['email'] = '';
    $_SESSION['name'] = '';  
    
    if($_POST['submit'])
    {
     if(empty($_POST['email']) && empty($_POST['name']))
    {
     	$_SESSION['emailerror'] = '1';
     	$_SESSION['nameerror'] = '1';
     	header("location: $_SERVER[php_SELF]");
    }
    elseif(empty($_POST['email']))
    {
    	$_SESSION['emailerror'] = '1';
    	$_SESSION['name'] = $_POST['name'];
     	header("location: $_SERVER[php_SELF]");	
    }
    elseif(empty($_POST['name']))
    {
    	$_SESSION['nameerror'] = '1';
    	$_SESSION['email'] = $_POST['email'];
     	header("location: $_SERVER[php_SELF]");	
    }
    
    $databasename='week3'; // Name of the database
    $tablename='email'; // Name of the table
    $mysqladd='localhost'; // Address to the MySQL Server - Usually localhost or an IP address
    $mysqluser='root'; // Your MySQL UserName
    $mysqlpass=''; // Your MySQL Password
    @$name = addslashes($_POST['name']);
    @$email = addslashes($_POST['email']);
    
    ///CONNECT TO MYSQL working
    $link=mysql_connect($mysqladd,$mysqluser,$mysqlpass) or die('Database Error: ' . mysql_error());
    
    
    //CONNECT TO DATABASE working
    mysql_select_db($databasename, $link) or die('Could not connect to table: ' . mysql_error());
    
    //Get data from Text, Post data to database working
    $strQuery = "INSERT INTO `email`(`name`,`email`)VALUES (\"$name\",\"$email\")" ;
    $result = mysql_query($strQuery);
    if (!$result) 
    {
    	die('Invalid query: ' . mysql_error());
    }
    
    // print data table from database
    
    $result = mysql_query("SELECT * FROM email");
    
    while($row = mysql_fetch_array($result))
      	{
      
      		echo $row['name'];
      		echo $row['email'];
      		echo "<hr />";
        }
      	// this doesn't return all the data in the table. It is only returning what I just entered.
    }
    ?>
    

  6. can you please do us a favor and use

    
    

    tags?

     

    </html>
    <head>
    
    <title>myform</title>
    
    </head>
    
    <body>
    
      <form method="post" action="test.php">
    
        Name: <br />
        
          <input type="text" name="name" size="30" /><br />
        
        Email: <br />
          <input type="text" name="email" size="30" /><br />
          
          <input type="submit" value="Submit" />
       
      </form>
    
    </body>
    </html>
    <?php 
    $databasename='week3'; // Name of the database
    $tablename='email'; // Name of the table
    $mysqladd='localhost'; // Address to the MySQL Server - Usually localhost or an IP address
    $mysqluser='root'; // Your MySQL UserName
    $mysqlpass=''; // Your MySQL Password
    @$name = addslashes($_POST['name']);
    @$email = addslashes($_POST['email']);
    
    ///CONNECT TO MYSQL working
    $link=mysql_connect($mysqladd,$mysqluser,$mysqlpass) or die('Database Error: ' . mysql_error());
    
    
    //CONNECT TO DATABASE working
    mysql_select_db($databasename, $link) or die('Could not connect to table: ' . mysql_error());
    
    //Get data from Text, Post data to database working
    $strQuery = "INSERT INTO `email`(`name`,`email`)VALUES (\"$name\",\"$email\")" ;
    $result = mysql_query($strQuery);
    if (!$result) { die('Invalid query: ' . mysql_error());
    }
    
    // print data table from database
    
    $result = mysql_query("SELECT * FROM email");
    
    if($row = mysql_fetch_array($result))
      {
      
      echo $row['name'];
      echo $row['email'];
      echo "<br />";
        }
      // this doesn't return all the data in the table. It is only returning what I just entered.
    
    ?>
    

  7. try this

    mysql_select_db($database_users, $users) or die(mysql_error());
    $query_users = "SELECT * FROM users";
    $users = mysql_query($query_users, $users) or die(mysql_error());
    $row_users = mysql_fetch_assoc($users);
    $totalRows_users = mysql_num_rows($users) or die(mysql_error());
    

  8. hi mate,

     

    try adding or die(mysql_error()); 

     

    after your querys

     

    so basically

     

    mysql_select_db($database_users, $users) or die(mysql_error());

     

      $LoginRS__query=sprintf("SELECT `user`, password FROM users WHERE `user`=%s AND password=%s",

        GetSQLValueString($loginUsername, "-1"), GetSQLValueString($password, "text"));

     

     

     

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