mercredi 22 juin 2016

PHP + MySQL giving blank page with no errors

I am currently in the process of creating a website with PHP and MySQL for the login/signup system. However, when trying to log in, I get redirected to a blank page (where MySQL would normally put an error) and cannot log in. The weird thing is -- this doesn't happen when signing up. I can sign up as normal, and I am redirected to the "dashboard" (the place I set to direct after a successful signup). I'm not completely sure what happened and how the login system broke, since I don't remember changing anything with it since it worked before.

This was marked as a duplicate of another question, however when removing die(mysqli_error()); from my code, the white screen goes away and I just get an error message telling me my credentials are incorrect (not a PHP/MySQL error message, the $error message I defined).

My code is below.

login.php

<?php

        include("connection.php");
        session_start();

        if ($_GET["logout"]==1 AND $_SESSION['id']) {
            session_destroy();
            // $message="You have been logged out. Have a nice day!";
            session_start();
        }

        if(isset($_SESSION['id'])){ // if id in session is set
            header("Location: /developer/dashboard");
        }

        if ($_POST['submit']=="Sign Up") {

            if (!$_POST['username']) $error.="<br />Please enter a username";

            if (!$_POST['email']) $error.="<br />Please enter your email";
                else if (!filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) $error.="<br />Please enter a valid email";

        if (!$_POST['password']) $error.="<br />Please enter your password";
        else {

            if (strlen($_POST['password'])<8) $error.="<br />Please enter at least 8 characters";

            if(!preg_match('/[A-Z]/', $_POST['password'])) $error.= "<br />Please include at least 1 capital letter";
        }
            if ($error) $error = "Your account could not be created due to the following:".$error;

            else {

            $query= "SELECT * FROM `users` WHERE email ='".mysqli_real_escape_string($link, $_POST['email'])."'";

            $result = mysqli_query($link, $query); 
            $results = mysqli_num_rows($result);

            if ($results) $error = "That email is already registered. Did you mean to log in?";
            else {
            $query = "INSERT INTO `users` (`username`, `email`, `password`) VALUES ('".mysqli_real_escape_string($link, $_POST['username'])."', '".mysqli_real_escape_string($link, $_POST['email'])."', '".md5(md5($_POST['username']).$_POST['password'])."')";

            mysqli_query($link, $query);
            $success="Successfully signed up.";
            $_SESSION['id']= mysqli_insert_id($link);
            header("Location:../dashboard");
            }  
        }
    }

    if ($_POST['submit'] == "Log In") {
        $query = "SELECT * FROM users WHERE email='".mysqli_real_escape_string($link, $_POST['loginemail'])."'AND
        password='" .md5(md5($_POST['loginemail']) .$_POST['loginpassword']). "'LIMIT 1";
        $result = mysqli_query($link, $query);
        $row = mysqli_fetch_array($result);
        if($row){
            $_SESSION['id']=$row['id'];
            header("Location:../dashboard");
        } else {
            $error = "That email and password combination did not return any results. Please try again.";
die(mysqli_error());
        }
    }

loginpage.php (the login page HTML)

<body>
    <div class="container">
      <form class="form-signin" method="post">
        <h3 class="form-signin-heading">Welcome back!</h3>
        <label for="inputEmail" class="sr-only">Email address</label>
        <input type="email" name="loginemail" id="inputEmail" placeholder="Email address" class="form-control" value="<?php echo addslashes($_POST['loginemail']); ?>" required autofocus />
        <label for="inputPassword" class="sr-only">Password</label>
        <input type="password" name="loginpassword" id="inputPassword" placeholder="Password" class="form-control" value="<?php echo addslashes($_POST['loginpassword']); ?>" required />
        <button class="btn btn-lg btn-primary btn-block" type="submit" name="submit" value="Log In">Log In</button>
        <br />
        <div class="alternateAcc" style="font-weight:lighter;"><p>Don't have an account? <a href="../create">Register</a></p>
        <a href="/developer/">&laquo; Back</a></div>
      </form>
    </div> <!-- /container -->

signuppage.php (the signup page HTML)

<body>

    <div class="container">
      <form class="form-signin" method="post">
        <h3 class="form-signin-heading">Create an Account</h3>
        <label for="inputUsername" class="sr-only">Username</label>
        <input type="username" name="username" id="inputUsername" class="form-control" placeholder="Username" value="<? echo addslashes($_POST['username']); ?>" required autofocus />
        <label for="inputEmail" class="sr-only">Email address</label>
        <input type="email" name="email" id="inputEmail" class="form-control" placeholder="Email address" value="<? echo addslashes($_POST['email']); ?>" required />
        <label for="inputPassword" class="sr-only">Password</label>
        <input type="password" name="password" id="inputPassword" class="form-control" placeholder="Password" value="<? echo addslashes($_POST['password']); ?>" required />
        <button class="btn btn-lg btn-primary btn-block" type="submit" name="submit" value="Sign Up">Continue</button>
        <br />
        <div class="alternateAcc" style="font-weight:lighter;"><p>Already have an account? <a href="../login">Log In</a></p>
        <a href="/developer/">&laquo; Back</a></div>
      </form>
    </div> <!-- /container -->

Does anyone have any pointers on how to potentially fix this? Thank you very much!

SQL Server hierarchy with parent id and child id

Click here for results image

I would like to generate the 'hierarchy id' values which is denoted in red. The value is the lowest level of id in the hierarchy. The highest level of hierarchy is 'ALL Service Groups' and the lowest level is 'LL800_GB05'. They are related with Parent ID and ID. The attached image is only a sample set.

Update-- I have formed a relationship and lineage. Now i know the highest member of Hierarchy.I want to associate the lowest childID for each row in a new column. I tired doing an inner join on Parentid and ID but didnot workout completely. I tried a crossjoin but didnot workout. Below is the data for insertion

CREATE TABLE CO1 (
    PARENTID INT,
    ID INT,
    CID VARCHAR(38) ,
    Depth INT,
    Lineage VARCHAR(28) 
);
INSERT INTO CO1 VALUES (1105,48039,'All Service Groups',0,'/');
INSERT INTO CO1 VALUES (48039,48100,'Ovhd Service Groups',1,'/48039/');
INSERT INTO CO1 VALUES (48039,133686,'Network Services',1,'/48039/');
INSERT INTO CO1 VALUES (48039,133689,'Shared Services',1,'/48039/');
INSERT INTO CO1 VALUES (48039,133692,'SW Security K-12 Monitoring',1,'/48039/');
INSERT INTO CO1 VALUES (48039,133695,'Print Services Group',1,'/48039/');
INSERT INTO CO1 VALUES (48039,138170,'Miscellaneous Service Groups',1,'/48039/');
INSERT INTO CO1 VALUES (48039,48109,'Total Shared Services Security',1,'/48039/');
INSERT INTO CO1 VALUES (48100,140656,'K909_GB00',2,'/48039/48100/');
INSERT INTO CO1 VALUES (48100,140631,'K909_GG00',2,'/48039/48100/');
INSERT INTO CO1 VALUES (48100,140634,'K909_GA02',2,'/48039/48100/');
INSERT INTO CO1 VALUES (48100,48045,'G0000002',2,'/48039/48100/');
INSERT INTO CO1 VALUES (48109,48089,'GH010001',2,'/48039/48109/');
INSERT INTO CO1 VALUES (48109,48090,'GH010002',2,'/48039/48109/');
INSERT INTO CO1 VALUES (48109,48091,'GH010003',2,'/48039/48109/');
INSERT INTO CO1 VALUES (48109,48092,'GH010004',2,'/48039/48109/');
INSERT INTO CO1 VALUES (48109,48093,'GH010005',2,'/48039/48109/');
INSERT INTO CO1 VALUES (48109,48094,'GH010006',2,'/48039/48109/');
INSERT INTO CO1 VALUES (133686,133647,'Network Voice Services',2,'/48039/133686/');
INSERT INTO CO1 VALUES (133686,48106,'Network Data Services',2,'/48039/133686/');
INSERT INTO CO1 VALUES (133689,133634,'Server Hosting Services',2,'/48039/133689/');
INSERT INTO CO1 VALUES (133689,48105,'Mainframe Services',2,'/48039/133689/');
INSERT INTO CO1 VALUES (133689,133640,'Desktop Support & Application Services',2,'/48039/133689/');
INSERT INTO CO1 VALUES (133692,133682,'K12 Monitoring',2,'/48039/133692/');
INSERT INTO CO1 VALUES (133695,48108,'Total Print Services',2,'/48039/133695/');
INSERT INTO CO1 VALUES (133695,140641,'K909_GZ00',2,'/48039/133695/');
INSERT INTO CO1 VALUES (138170,138165,'Help Desk',2,'/48039/138170/');
INSERT INTO CO1 VALUES (138170,138166,'DS',2,'/48039/138170/');
INSERT INTO CO1 VALUES (138170,138167,'SCS',2,'/48039/138170/');
INSERT INTO CO1 VALUES (138170,138168,'IT Plan and Admin',2,'/48039/138170/');
INSERT INTO CO1 VALUES (138170,138162,'K909XGA01',2,'/48039/138170/');
INSERT INTO CO1 VALUES (138170,138163,'Surplus',2,'/48039/138170/');
INSERT INTO CO1 VALUES (133682,133681,'K909_GM00',3,'/48039/133692/133682/');
INSERT INTO CO1 VALUES (133682,133683,'K909_GM01',3,'/48039/133692/133682/');
INSERT INTO CO1 VALUES (133682,133684,'K909XGM01',3,'/48039/133692/133682/');
INSERT INTO CO1 VALUES (133647,133657,'Telecom Project Management',3,'/48039/133686/133647/');
INSERT INTO CO1 VALUES (133647,133660,'Telecom Wiring',3,'/48039/133686/133647/');
INSERT INTO CO1 VALUES (133647,133663,'Shared CENTREX',3,'/48039/133686/133647/');
INSERT INTO CO1 VALUES (133647,133649,'Total VoiP',3,'/48039/133686/133647/');
INSERT INTO CO1 VALUES (133647,133651,'Local Services Telco',3,'/48039/133686/133647/');
INSERT INTO CO1 VALUES (133647,133654,'Long Distance Telco',3,'/48039/133686/133647/');
INSERT INTO CO1 VALUES (133634,48076,'K909_GG40',3,'/48039/133689/133634/');
INSERT INTO CO1 VALUES (133634,48077,'K909_GG41',3,'/48039/133689/133634/');
INSERT INTO CO1 VALUES (133634,48078,'K909_GG42',3,'/48039/133689/133634/');
INSERT INTO CO1 VALUES (133634,48079,'K909_GG43',3,'/48039/133689/133634/');
INSERT INTO CO1 VALUES (133634,48080,'K909_GG44',3,'/48039/133689/133634/');
INSERT INTO CO1 VALUES (133634,48081,'K909_GG45',3,'/48039/133689/133634/');
INSERT INTO CO1 VALUES (133634,48082,'K909_GG46',3,'/48039/133689/133634/');
INSERT INTO CO1 VALUES (133634,48083,'K909_GG47',3,'/48039/133689/133634/');
INSERT INTO CO1 VALUES (133634,133638,'K909_GG48',3,'/48039/133689/133634/');
INSERT INTO CO1 VALUES (133634,133679,'K909_GG49',3,'/48039/133689/133634/');
INSERT INTO CO1 VALUES (133634,133680,'K909_GG07',3,'/48039/133689/133634/');
INSERT INTO CO1 VALUES (133634,138164,'K909_GG04',3,'/48039/133689/133634/');
INSERT INTO CO1 VALUES (133640,133642,'Application Services',3,'/48039/133689/133640/');
INSERT INTO CO1 VALUES (133640,133644,'Total Desktop Support',3,'/48039/133689/133640/');
INSERT INTO CO1 VALUES (48105,48067,'K909_GG11',3,'/48039/133689/48105/');
INSERT INTO CO1 VALUES (48105,48068,'K909_GG12',3,'/48039/133689/48105/');
INSERT INTO CO1 VALUES (48105,48069,'K909_GG13',3,'/48039/133689/48105/');
INSERT INTO CO1 VALUES (48105,48070,'K909_GG14',3,'/48039/133689/48105/');
INSERT INTO CO1 VALUES (48105,48071,'K909_GG10',3,'/48039/133689/48105/');
INSERT INTO CO1 VALUES (48106,133667,'Total DTO Internet',3,'/48039/133686/48106/');
INSERT INTO CO1 VALUES (48106,133670,'MetroNet',3,'/48039/133686/48106/');
INSERT INTO CO1 VALUES (48106,133673,'Router Management',3,'/48039/133686/48106/');
INSERT INTO CO1 VALUES (48106,133676,'Firll / VN Management',3,'/48039/133686/48106/');
INSERT INTO CO1 VALUES (48106,48103,'Total WAN',3,'/48039/133686/48106/');
INSERT INTO CO1 VALUES (48108,48095,'K909_GK00',3,'/48039/133695/48108/');
INSERT INTO CO1 VALUES (48103,48066,'K909_GD05',4,'/48039/133686/48106/48103/');
INSERT INTO CO1 VALUES (133642,48074,'K909_GG30',4,'/48039/133689/133640/133642/');
INSERT INTO CO1 VALUES (133644,133678,'K909_GG21',4,'/48039/133689/133640/133644/');
INSERT INTO CO1 VALUES (133644,48072,'K909_GG20',4,'/48039/133689/133640/133644/');
INSERT INTO CO1 VALUES (133649,48053,'K909_GB05',4,'/48039/133686/133647/133649/');
INSERT INTO CO1 VALUES (133651,48054,'K909_GB06',4,'/48039/133686/133647/133651/');
INSERT INTO CO1 VALUES (133654,48055,'K909_GB07',4,'/48039/133686/133647/133654/');
INSERT INTO CO1 VALUES (133657,48049,'K909_GB01',4,'/48039/133686/133647/133657/');
INSERT INTO CO1 VALUES (133657,133656,'K909_GB08',4,'/48039/133686/133647/133657/');
INSERT INTO CO1 VALUES (133660,133659,'K909_GB09',4,'/48039/133686/133647/133660/');
INSERT INTO CO1 VALUES (133660,48050,'K909_GB02',4,'/48039/133686/133647/133660/');
INSERT INTO CO1 VALUES (133663,48051,'K909_GB03',4,'/48039/133686/133647/133663/');
INSERT INTO CO1 VALUES (133663,48052,'K909_GB10',4,'/48039/133686/133647/133663/');
INSERT INTO CO1 VALUES (133667,48056,'K909_GD01',4,'/48039/133686/48106/133667/');
INSERT INTO CO1 VALUES (133667,48057,'K909_GD07',4,'/48039/133686/48106/133667/');
INSERT INTO CO1 VALUES (133670,48058,'K909_GD02',4,'/48039/133686/48106/133670/');
INSERT INTO CO1 VALUES (133673,48060,'K909_GD03',4,'/48039/133686/48106/133673/');
INSERT INTO CO1 VALUES (133676,48061,'K909_GD04',4,'/48039/133686/48106/133676/');
INSERT INTO CO1 VALUES (133676,48062,'K909_GD06',4,'/48039/133686/48106/133676/');

and SQL statements i tried are below

SELECT A.[PARENTID]
      ,A.[ID]
      ,A.[CID]
      ,A.[Depth]
      ,A.[Lineage],B.ID as HierID
  FROM [dbo].[CO1new] A

  inner join  [dbo].[CO1new] as B on (A.ID =B.PARENTID)

where A.PARENTID in ( 1105,133686,133647,133657,133660,133663,133649,133651,133654)

  order by 5

Any inputs please

Thanks

Convert nvarchar scientific notation value into number in Sql Server 2014

I have a column loaded into sql with below nvarchar values -

ColumnName

6.19e+014

6.19e+014

Now, what would be the easiest way to convert this value into number again. Kindly suggest. Thanks!!

In the following pl sql program what is the error ? Is it a compilation error?

Declare
 a VARCHAR2(10);
 b NUMBER;
BEGIN 
 a:=&empname;
 b:=&empno;
 DBMS_OUTPUT.PUT_LINE('WELCOME'a||','||b||);
END;

When I am running it on oracle sql developer, it is showing some some which I can not able to figure out.

Retrieving data from different servers and databases

I have two servers 10.10.7.10 and 10.10.2.10. 10.10.7.10 has the dev database with dbo as owner of a table named vendor. On 10.10.2.10 I have the same table in a database name prod. How do I retrieve data from both servers logging into 10.10.7.10 as a remote connection and using sql management studio to create and run my queries/

How to read data from Excel sheet using Sql statement in SSIS Package

I have a excel sheet which has the data starting from 17th row.

There are two columns 
A16 Name     B16 Value
A17    A     B17   1
A18    B     B18   2
A19    C     B19   3

How to write the SQL Statement to read the data from these two colums from A17 to A19?

Thanks for the help.

mardi 21 juin 2016

modify format of multiple database columns at once

I have imported a csv table into sql db using phpmyadmin. I guess the default format is decimal(8,5), or at least that is how it comes out. Seems overkill and I thought I could reduce to 4,1. Problem is there are around 470 fields. I know how to change one at a time but this would take a long time. Is there a faster way?