Jump to content

jonsjava

Members
  • Posts

    1,579
  • Joined

  • Last visited

Posts posted by jonsjava

  1. try this slightly modified version of my last attempt:

       <body>
    <?php
    
    $Conn=mysql_connect("localhost","fierm","13183");
    
    if(!$Conn){ 
       echo "failed";
      } 
      else{ 
    mysql_select_db("fierm");
    
    
      $User=$_POST["user"];
      $Pass=$_POST["pass"];
      $Conf=$_POST["confirm"];
    
      	if($Pass == $Conf){ 
      		$result=mysql_query("SELECT * FROM user WHERE usr_name='$User' AND `password`='{$Pass}' LIMIT 1;") or die("It failed on the first query :".mysql_error());
      		$cou=mysql_num_rows($result);
      		if($cou == 1) 
        	{ 
        		echo "user already exists";  
      		}
      		else{ 
      			$result = mysql_query("SELECT * FROM user WHERE usr_name='{$User}' LIMIT 1;") or die("It failed on the second query :".mysql_error());
      			if (mysql_num_rows($result) != 1){
         			mysql_query("Insert into user (usr_name,pwd) Values ('$User','$Pass')");
        			echo "New User Was Added";
      			}
      		}
    	}   
    else{
        	echo "passwords do not match";
      	}	 
    }     
    ?>
    </body>   <body>
    <?php
    
    $Conn=mysql_connect("localhost","fierm","13183");
    
    if(!$Conn){ 
       echo "failed";
      } 
      else{ 
    mysql_select_db("fierm");
    
    
      $User=$_POST["user"];
      $Pass=$_POST["pass"];
      $Conf=$_POST["confirm"];
    
      	if($Pass == $Conf){ 
      		$result=mysql_query("SELECT * FROM user WHERE usr_name='$User' AND `password`='{$Pass}' LIMIT 1;") or die("It failed on the third query :".mysql_error());
      		$cou=mysql_num_rows($result);
      		if($cou == 1) 
        	{ 
        		echo "user already exists";  
      		}
      		else{ 
      			$result = mysql_query("SELECT * FROM user WHERE usr_name='{$User}' LIMIT 1;");
      			if (mysql_num_rows($result) != 1){
         			mysql_query("Insert into user (usr_name,pwd) Values ('$User','$Pass')");
        			echo "New User Was Added";
      			}
      		}
    	}   
    else{
        	echo "passwords do not match";
      	}	 
    }     
    ?>
    </body>
    

    ***EDITED to add error checking

  2.    <body>
    <?php
    
    $Conn=mysql_connect("localhost","fierm","13183");
    
    if(!$Conn){ 
       echo "failed";
      } 
      else{ 
    mysql_select_db("fierm");
    
    
      $User=$_POST["user"];
      $Pass=$_POST["pass"];
      $Conf=$_POST["confirm"];
    
      	if($Pass == $Conf){ 
      		$result=mysql_query("SELECT * FROM user WHERE usr_name='$User' AND `password`='{$Pass}' LIMIT 1;");
      		$cou=mysql_num_rows($result);
      		if($cou>0) 
        	{ 
        		echo "user already exists";  
      		}
      		else{ 
      			$result = mysql_query("SELECT * FROM user WHERE usr_name='{$User}' LIMIT 1;");
      			if (mysql_num_rows($result) != 1){
         			mysql_query("Insert into user (usr_name,pwd) Values ('$User','$Pass')");
        			echo "New User Was Added";
      			}
      		}
    	}   
    else{
        	echo "passwords do not match";
      	}	 
    }     
    ?>
    </body>
    

  3. yes, you are correct. at the head of all files, (including the login script) add:

    <?php
    session_start();
    ?>
    

    and in the login script, add this as well:

    <?php
    $_SESSION['is_valid'] = true; //change the session variable name to what you want, just remember it for all files
    $_SESSION['username'] = $row['user_name'];
    $_SESSION['user_level'] = $row['userlevel'];
    ?>
    

    and for all the files that need to know user level, or username, etc...

    <?php
    if ($_SESSION['is_valid'] == true){
    if ($_SESSION['user_level'] == 0){
    //do something for general users
    }
    if ($_SESSION['user_level'] == 1){
    //do something for admins
    }
    }
    ?>
    

    for more info, just ask, and we shall answer

  4. it asks if you want to repost the data, because it generated the previous page with a _POST

    to fix this, do something like this ("proxy page")

    for the search field:

    //search page
    <form method="POST" action="page1.php">
    //rest of stuff here
    

     

    for page1

    <?php
    $go = array();
    $go .= $_POST['variable1'];
    $go .= $_POST['variable2'];
    //keep on this style until you have it all
    $search_url = "search.php?".$go['0'];
    $count = 1;
    foreach($go as $value){
    if ($value != 0){
    $search_url .= "&var".$count."=".$value;
    $count++;
    }
    }
    header("location:".$search_url);
    ?>
    

    and the final page, the search page:

    <?php
    //Search page: do your search by parsing through the $_GET vars
    $var1 = addslashes($_GET['var1']);
    $var2 = addslashes($_GET['var2']);
    $var3 = addslashes($_GET['var3']);
    //and so on.
    //then add the $vars into your query
    ?>
    

    **EDITED to add some security into the get variables

  5. if you want/need any code checked via Zend 5.5.1, post it here, and I'll run it, and give you the errors it spits out (if you wanna fix stuff yourself, but don't have an IDE to do it in). I have an official license for the application, so I can freely offer this and not worry about someone getting me for having a cracked copy  :P

  6. I think this will do what you need *didn't error check it too thoroughly, though*:

    <?php
    
    include '../includes/db_connect.php';
    include '../includes/config_table.inc.php';
    
    
    $user_name = $_POST["user_name"];        
    $user_password = $_POST["user_password"];    
    $verify_username = strlen($user_name);
    $verify_pass = strlen($user_password);
    if ($verify_pass > 0 && $verify_username > 0)
    {
    $salt = substr($user_password, 0, 2);
    $userPswd = crypt($user_password, $salt);
    $sql = "SELECT * FROM `$user` WHERE user_name='$user_name' AND user_password='$userPswd' LIMIT 1;";
    $result = mysql_query($sql);
    if (mysql_num_rows($result) == 1){
    $row = mysql_fetch_assoc($result);
    $user_level = $row['userlevel'];
    	if ($user_level == 1) {
    		echo "Logged In Sucessfully. Please wait while you are redirected";    
    		echo "<meta http-equiv='refresh' content='2; url=setadmincookie.php?u=$username&p=$user_password'>";
    	} 
    	elseif ($user_level == 2){    
    		echo "Logged In Sucessfully. Please wait while you are redirected";    
    		echo "<meta http-equiv='refresh' content='2; url=setcookie.php?u=$username&p=$user_password'>";
    	}
    }
    else{
    	echo 'Login failed. Username and Password did not match database entries.';    
        }
    }
    
    else
    {
        echo "Form was not completed. Please go back and make sure that the form was fully completed.";    
    }
    
    
    mysql_close();
    ?>
    

    **EDIT**

    Forgot to do a couple things. give me a minute to finish this up.

    **EDIT2**

    Fixed forgotten things. should work now.

  7. Not exactly what you were expecting, but why add overhead if you don't gotta?

    <?php
    require_once 'library/db.php';
    
    if (!($conn = mysql_connect('localhost', 'root', '')))
    {
    	showError();
    }
    
    if (!(mysql_select_db('itsupport', $conn)))
    {
    	showError();
    }
    
    if (!($result = mysql_query('select * from itsupport', $conn)))
    
            {
    	showError();
    }
    
    if(!isset($cmd))
    print "<tr>
    			<td>User_ID</td>
    			<td>Problem</td>
    			<td>Problem_ID</td>
    			<td>User_email</td>
    			<td>Office_Number</td>
    			<td>Phone_Number</td>
    			<td>User_Name</td>
                                    <td> </td>
                                    <td> </td>
                                    <tr>";
    while ($row =mysql_fetch_array($result))
    {
    
    	  echo "<tr>";
    	  echo "<td>" . $row[user_ID] . "</td>
    	          <td>" . $row[Problem] . " </td>
    		  <td>" . $row[Problem_ID] . "</td>
    	          <td>" . $row[user_email] . "</td>
    		  <td>" . $row[Office_Number] . " </td>
    		  <td>" . $row[Phone_Number] . " </td>
    		  <td>" . $row[user_Name] . " </td>";
    		  			   
    	echo "<td><a href=\"selectedit.php?id=$row[user_ID]\"><img border=\"0\" src=\"images/edit.gif\"></a>";
                    echo "<td><a href=\"delete.php?id=$row[user_ID]\"><img border=\"0\" src=\"images/delete.gif\"></a>";
    	echo "</tr>";
    }
    
    mysql_close($conn);
    

  8. <html>
    <head>
    <title>Database is Updating...</title>
    </head>
    <?php
    $id = $_GET["id"];
    
    $facpr = $_GET["facpr"];
    ?>
    <body bgcolor="#FFFFFF">
    <?php
    $username = "root";
    $password = "*****"; //gotta love the fact I left the real password in there. glad it's just a test box. gotta change it now.
    $hostname = "localhost";
    $dbhandle = mysql_connect($hostname, $username, $password);
    echo "Connected to Server<br>";
    mysql_select_db("testing",$dbhandle);
    echo "Connected to Salt Lake City Database<p>";
    
    mysql_query("UPDATE training SET firstaidcpr = '$facpr' WHERE id='$id'");
    
    echo "Database has been updated. You will be returned to the training page momentarily. <meta http-equiv='refresh' content='3;URL=training.php' >"
    
    ?>
    </body>
    </html>
    

    works great for me. I had it updating a test user just fine for me.

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