Welcome! Log In Create A New Profile

Advanced

problem with my website

Posted by 46296433 - Julia 
Announcements Last Post
Announcement SoC Curricula 09/30/2017 01:08PM
Announcement Demarcation or scoping of examinations and assessment 02/13/2017 07:59AM
Announcement School of Computing Short Learning Programmes 11/24/2014 08:37AM
Announcement Unisa contact information 07/28/2011 01:28PM
problem with my website
October 11, 2013 09:29AM
Morning!
I have uploaded my application on orgfree.com,i also created the databases directly and changed my connect.php page to reflect the new database name.
Now the problem is that i can't log in.It keeps redirecting me to the index page instead of the page with links to view players,fixtures...Even with a username that doesn't exist,i don't have any error message.
I can login on the local server but not on the free webhosting server.
Any idea what could be the problem?Please help!!!
Re: problem with my website
October 11, 2013 10:59AM
there are many possible reasons... I would suggest that you start by uploading your site to another free hosting service... it could be that your provider has disabled error reporting...

if that's not the issue then start debugging...

use echo for all your conditional statements to see at which point your data output is not as expected
Re: problem with my website
October 11, 2013 12:04PM
Agree with OngeskikteVeldmuis .
Echoing your variable to check data is great place to start...

another thing to think about is your case when using variables....

if your site works 100% on local and not on the server their is a big chance that you did not use strict naming convention
in windows MyVariaBle is the same as Myvariable and MyVariable

in Linux its 3 diffrent variables
might not be the case...
but just something to think about
Re: problem with my website
October 11, 2013 12:16PM
Thanx.
I will try what you guys suggested and will get back to you.It is so frustrating!!!
Re: problem with my website
October 14, 2013 11:08AM
OK,
Now i really start to panic,it still doesn't work on the web hosting server.I can access the fixtures_public page from the index page and go to the page where i should enter the username and password but once this is done,even when the password is incorrect,it still redirect me to the index page instead of the logged in page.
I tried to modify the name of the database in my code,just to see if the connection is done and yes,i have an error stating that the database doesn't exist.This means that the connection is actually done but why can't i logged in?and if there was an error,it should have indicated it while i'm typing a wrong username!!!!
i've been trying to register for another site but can't success,don't know why,it seems like as my email adress is already use for this website i can't have another one.
Time is running and i'm writing next month.What should i do?Please help
This is the part of my code that should redirect to the logged in page.
Language: PHP
if ($num_rows <= 0){ echo "Sorry, there is no username $username with the specified password."; echo "Try again"; echo "<a href = ';index.php';>Back</a>"; exit; } else { $_SESSION[';user';]= $_POST["username"]; header("location:logged.php");// This is the page where we will be redirect after loging in } }
This code works perfectly on the local server.
avatar Re: problem with my website
October 14, 2013 11:44AM
Quote

even when the password is incorrect,it still redirect me to the index page instead of the logged in page

Surely that is what it is supposed to do if the password is incorrect ?


Have you checked the capitalization of all variables and field names - they must be EXACTLY the same on a Linux server.

I think you are looking in the wrong place, the problem is more likely to be with your SQL query, than in the above code.
It appears that it does not return any results, irrespective of the input.

PS: Have you checked that $_SESSION and $_POST are set before trying to extract values from them ?
Re: problem with my website
October 14, 2013 03:21PM
Hi bigron11!
When the password is wrong,it is supposed to give me an error message as it does on the local server.
I have also check on the variable,they are exactly the same.
My problem is why is it working perfectly on local and not on the web hosting?I can't pick exactly what is the problem and correct it without knowing what is going on.
avatar Re: problem with my website
October 14, 2013 04:19PM
Two possibilities -

1) php.ini settings on your computer / server are different.

2) Windows / Linux - Linux is case-sensitive - Windows is not.


Try putting in a temporary echo statement to echo the output of your SQL query, to make sure it returns the expected result.


PS: By field names I mean the names of the fields as created in your SQL table on the server. The names / capitalization must match your SQL query exactly.
Re: problem with my website
October 15, 2013 04:38PM
Hey bigron11!

I spent hours and hours trying to fix things but i can't.
How can i check if my php.ini is the same as the one of the server?
The variables are the same,didn't change a thing.
When i type directly the url for the other pages,i can work on my site without problem,the only problem is i can't log in with my code.
Here is my code,is there something that i'm doing wrong?the fields names are exactly the same as in my database and in the query.
Language: PHP
<?php //This is the login page.A username is matched with the corresponding password before loging in //   $username = "root";// Mysql username $password = "";// Mysql password $database = "userlogin"; // Database name $server = "127.0.0.1"; // Server name // Connect to server and select database. $db = mysql_connect($server,$username,$password) or DIE("oops,something went wrong"); mysql_select_db($database,$db) or DIE("oops,something went wrong"); //Starting a session session_start(); if($_SERVER ["REQUEST_METHOD"] == "POST") { $username = $_POST["username"]; //username is stored in $username variable. $password = $_POST["password"]; //password is stored in $password variable.   $match = "select id from login where username = ';".$_POST[';username';]."';and password = ';".$_POST[';password';]."';;"; $qry = mysql_query($match); $num_rows = mysql_num_rows($qry);   //Check if $num_rows variable is true if ($num_rows <= 0){ echo "Sorry, there is no username $username with the specified password."; echo "Try again"; echo "<a href = ';index.php';>Back</a>"; exit; } else { $_SESSION[';user';]= $_POST["username"]; header("location:logged.php");// This is the page where we will be redirect after loging in } }       echo"<body bgcolor=';#E0FFFF';>"; echo"<p>Please enter your username and your password or <a href=';index.php';>click here</a> to go back to the index page</p>"; echo"<form action = '; '; method = ';post';>"; echo"<label>Username:</label>"; echo"<input type = ';text'; name = ';username';/><br/>"; echo"<label>Password:</label>"; echo"<input type = ';password'; name = ';password';/><br/>"; echo"<input type = ';submit'; value = ';Login';/><br/>"; echo"</form>"; echo"</body>";   ?>
i don't know where to check for the php.ini of the host server,should i do it manually or?
avatar Re: problem with my website
October 15, 2013 05:20PM
Language: PHP
if($_SERVER ["REQUEST_METHOD"] == "POST") // Rather change this as below. { $username = $_POST["username"]; //username is stored in $username variable. // Why do you store these values in variables, and then not use the variables ??? $password = $_POST["password"]; //password is stored in $password variable.


Language: PHP
if (isset($_POST[';submit';]) // Add name="submit" to the form input submit. {


You should not try to extract values from superglobals unless you have checked that they actually exist.

Put a temporary echo statement after this line -

Language: PHP
$num_rows = mysql_num_rows($qry);
to check if it gives the expected results.


You can check the php.ini settings on your server by running this script -

<?php
phpinfo();
?>

Delete it immediately after use.
avatar Re: problem with my website
October 15, 2013 05:36PM
This is a bit messy -

Language: PHP
$match = "select id from login where username = ';".$_POST[';username';]."';and password = ';".$_POST[';password';]."';;";


Language: PHP
$match = "SELECT id FROM login WHERE username = ';$username'; AND password = ';$password'; ";
Re: problem with my website
October 15, 2013 07:28PM
I've tried to fix what you suggested but still nothing happens,it still redirect me to the index page.
The echo that i've added does not work either.Don't know which step to take now.It looks like i'm the only one experiencing this problem
avatar Re: problem with my website
October 15, 2013 08:20PM
Some debugging -

Change your "or die" messages to something more relevant, and add the following to them -


Language: PHP
or die("SQL query error: ".mysql_error());

Comment out this line -

Language: PHP
$num_rows = mysql_num_rows($qry);

and add this line just after it -

Language: PHP
$num_rows = 1;

Should help identify where the problem is.

It seems that the problem is that there is an error somewhere with the SQL, which causes the script to die, and the server is set to automatically load the default index file. (To prevent users from getting access to your directory contents).
You should not in fact use "or die", or "exit" on a live website, but use more robust error trapping - eg: try, catch, finally etc.
Re: problem with my website
October 16, 2013 10:04AM
Hi bigron!
I did what you suggested but nothing is happening!
I've been thinking about renting a space on a pay web hosting area,do you think i will have the same problem?i'm starting to panic now.I already failed once,don't want to fail againconfused smiley
avatar Re: problem with my website
October 16, 2013 10:46AM
Another method -

Remove all the "or die" parts of the script. (I think they are the cause of the problem).

Put something like this after each statement that uses SQL / database -

Language: PHP
if (mysql_error()) { echo "SQL error: ". mysql_error(); // Putting in <br> would improve layout echo "Line number: ".mysql_errno(); } else { echo "Something to identify the SQL statement"; echo "No SQL error occurred"; }


You should also comment out the rest of the script using /* comment */, to prevent any other resulting errors from occurring.
ie: Progressively test your script from the top, moving the opening /* further down as you successfully test each part.

Do this for each SQL statement in turn, until you are sure that each one works without error.
A bit tedious - but should find the problem.

You may also want to check your tables again - all fields names correct / capitalization etc.

Changing ISPs probably won't help, their APACHE / PHP settings are likely to be very similar.

PS: Using a try...catch... finally construct, and redirecting to an error page would be the correct method, but is probably too big a step right now.

Debugging is a major part of development - get used to it.
Re: problem with my website
October 16, 2013 11:36AM
Once more,i tried but nothing is working.
I can see that it connect to the database because it displays the echo that i put if there is no error,but when i move the echo to the other sql statements,nothing happen,only redirect to index page.
I read in the home and learn tutorial something about cookies,now i don't know what to think anymore
avatar Re: problem with my website
October 16, 2013 11:58AM
Try and comment out the "session_start();" line, it uses a session cookie.
You don't use the session until much further into the script, after all the SQL., so that part should be commented out as well.

If you are using the method I suggested above, you must delete, or comment out, all the "or die()" parts.
You must also comment out all of the php part of the script, before the form, below the part you are testing, using /* .... */. (But make sure all opening and closing brackets still match.)
Otherwise, if the problem is further down, it will redirect before you get a chance to read the echoed output.

Basically, you need to step through your script, and make sure each part is working as expected, until you reach the part where the problem is.
Re: problem with my website
October 16, 2013 12:26PM
That is exactly what i did,i even removed completely the session just to see what i will have next.
I completely started my code from the scratch,echoing every query and tried what you suggested about error messages but it still doesn't work on the webhosting.
I checked my variables,i delete the database and created a new one just to make sure that i do not make mistakes.It still doesn't work on the web hosting server but works perfectly on local even with all the modification i've madeconfused smiley
avatar Re: problem with my website
October 16, 2013 01:27PM
Are you doing this ? -

Language: PHP
// Connect to server and select database. $db = mysql_connect($server,$username,$password) or DIE("oops,something went wrong");   /* // Comment out the rest of the PHP script.   mysql_select_db($database,$db) or DIE("oops,something went wrong");   // When you have checked that the above works, move the opening comment tag here.   //Starting a session session_start(); // Comment this out. if($_SERVER ["REQUEST_METHOD"] == "POST") { $username = $_POST["username"]; //username is stored in $username variable. $password = $_POST["password"]; //password is stored in $password variable.   $match = "select id from login where username = ';".$_POST[';username';]."';and password = ';".$_POST[';password';]."';;";   // When above works, move opening comment tag here. Add a closing bracket before the comment tag. Move comment tag and test each of following SQL when above ones work.   $qry = mysql_query($match); $num_rows = mysql_num_rows($qry);   //Check if $num_rows variable is true if ($num_rows <= 0){ echo "Sorry, there is no username $username with the specified password."; echo "Try again"; echo "<a href = ';index.php';>Back</a>"; exit; } else { $_SESSION[';user';]= $_POST["username"]; header("location:logged.php");// This is the page where we will be redirect after loging in } } */ // Closing comment tag

Add the previous error reporting code where appropriate.
Re: problem with my website
October 16, 2013 02:59PM
I've done exactly that before and i'm just finishing to do the same again.
At each query,i have the message that i echo when everything is fine,like no error.
Removed the session but still,the page redirect to the index page.
Re: problem with my website
October 21, 2013 06:53AM
lol this is funny. dude go to godaddy get yourself some paid hosting and it should work providing there are no problems with your code. avoid free hosting like the plague
Sorry, only registered users may post in this forum.

Click here to login