php - trouble with code

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
yupp
Forum Newbie
Posts: 3
Joined: Mon Mar 15, 2004 2:59 pm

php - trouble with code

Post by yupp »

I know it's bad to post code but i've really tried to figure out what's wrong with it..... i'll leave it to the experts...

ok this piece of code is the validation procedure which checks the login information, and i can't get it to work. I have created the database and table specified in the code and my server is working good. im using apache 2 with some php version dunno, the latest i think. When i enter my login information on my other login php file(which is working) and gets transferred to this validation page the browser is blanc and does not show any life signs at all. wots wrong?
so here's the code:

<?php require('\www\webroot\yuppolotion\_inc\top.inc'); ?>



<?php //skapar användarsession för inloggad användare.....
session_start();
session_register("ppuser");
session_register("pppass");
@$ppuser = $_POST["username"];
@$pppass = $_POST["password"];
?>
<?php
if ($_POST["nummer"] = 1)
{
$username = $_POST["username"];

$d = mysql_connect("localhost", "root", "ussr");
$sql = mysql_db_query("ppusers","SELECT * FROM users WHERE username = '$username'", $d);
$rad = mysql_fetch_array($sql);
}
else
{
$haha = "tyvärr";
echo ("$haha");
}
if($_POST["username"] == $rad["username"] & $_POST["password"] == $rad["password"])
{


$username = $_POST["username"];
$antalbesok = $rad["antalbesok"] + 1;
$senast = date("y-m-d");
$oppna = mysql_connect("localhost", "root", "ussr");
$sqlq = mysql_db_query("ppusers", "UPDATE users SET senast = '$senast', antalbesok = '$antalbesok' WHERE username = '$username'", $open);
mysql_close($oppna);

echo("<p>du är inloggad. Du förflyttas till startsidan.</p>");
echo("<script language=javascript>");
echo("self.location.replace('http://localhost/inloggad.php')");
echo("</script>");
}
else
{ ?>
<?php
echo("<p>Inloggningsförsöket misslyckades. Kontrolera användarnamn och lösenord och försök på nytt. </p><a href='http://localhost/start sida.php'>återgå</a>");
}
mysql_close($d);
}
?>

<?php require('\www\webroot\yuppolotion\_inc\bottom.inc'); ?>
TheBentinel.com
Forum Contributor
Posts: 282
Joined: Wed Mar 10, 2004 1:52 pm
Location: Columbus, Ohio

Re: php - trouble with code

Post by TheBentinel.com »

Is the require'd file accessible at that location?

To get a feel for where the script is dying, you can put some print()'s in it to see how far it's getting:

Code: Select all

<?php require('\www\webroot\yuppolotion\_inc\top.inc'); ?> 

<?php //skapar användarsession för inloggad användare..... 
session_start(); 
session_register("ppuser"); 
session_register("pppass"); 
@$ppuser = $_POST["username"]; 
@$pppass = $_POST["password"]; 

print ("GOT HERE 1");
?> 
<?php 
print ("GOT HERE 2");
if ($_POST["nummer"] = 1) 
{ 
print ("GOT HERE 3");
$username = $_POST["username"]; 

$d = mysql_connect("localhost", "root", "ussr"); 
$sql = mysql_db_query("ppusers","SELECT * FROM users WHERE username = '$username'", $d); 
$rad = mysql_fetch_array($sql); 
} 
else 
{ 
print ("GOT HERE 3");
$haha = "tyvärr"; 
echo ("$haha"); 
}
If you add those three messages and don't see anything at all, then I'd remove the include call at the beginning and the session code and try it again. The idea isn't to try to live without that code but to see where the breakdown is occurring.
yupp
Forum Newbie
Posts: 3
Joined: Mon Mar 15, 2004 2:59 pm

thanks

Post by yupp »

thanks, im trying it right now, thats a good strategy.
if the required file isn't there, then will it die at the very beginning? cause im not really sure (i've gotta check that). That might be a simple solution.

Nice forum by the way!!
TheBentinel.com
Forum Contributor
Posts: 282
Joined: Wed Mar 10, 2004 1:52 pm
Location: Columbus, Ohio

Re: thanks

Post by TheBentinel.com »

yupp wrote:thanks, im trying it right now, thats a good strategy.
if the required file isn't there, then will it die at the very beginning? cause im not really sure (i've gotta check that). That might be a simple solution.

Nice forum by the way!!
Here's the docs on require:

http://us2.php.net/require

It's supposed to generate a fatal error, but from what I've heard there are various levels of error reporting in PHP so it's possible for something to error off and not tell you about it.
yupp
Forum Newbie
Posts: 3
Joined: Mon Mar 15, 2004 2:59 pm

hi again

Post by yupp »

Hi again, i tried what you said about the print mesages , but non of them worked, So i followed our advise and removed the user session and require code. I also added an echo in the beginning of the code to se if it at all starts to read the code. When i compile it the screen goes blanc as ususal....
Shouldn't the compiler at least produce the "hi" at the top of the screen?
heres the code:


<?php
echo ("<p>hi<p>");
?>
<?php

if ($_POST["nummer"] = 1)
{
$username = $_POST["username"];

$d = mysql_connect("localhost", "root", "ussr");
$sql = mysql_db_query("ppusers","SELECT * FROM users WHERE username = '$username'", $d);
$rad = mysql_fetch_array($sql);
}
else
{
$haha = "tyvärr";
echo "$haha";
}
if($_POST["username"] == $rad["username"] & $_POST["password"] == $rad["password"])
{


$username = $_POST["username"];
$antalbesok = $rad["antalbesok"] + 1;
$senast = date("y-m-d");
$oppna = mysql_connect("localhost", "root", "ussr");
$sqlq = mysql_db_query("ppusers", "UPDATE users SET senast = '$senast', antalbesok = '$antalbesok' WHERE username = '$username'", $open);
mysql_close($oppna);

echo("<p>du är inloggad. Du förflyttas till startsidan.</p>");
echo("<script language=javascript>");
echo("self.location.replace('http://localhost/inloggad.php')");
echo("</script>");
}
else
{ ?>
<?php
echo("<p>Inloggningsförsöket misslyckades. Kontrolera användarnamn och lösenord och försök på nytt. </p><a href='http://localhost/start sida.php'>återgå</a>");
}
mysql_close($d);
}
?>
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

Try this modified version instead, see if throws anything out.

Code: Select all

<?php
error_reporting(E_ALL);
echo '<p>hi<p>';

$d = mysql_connect('localhost', 'root', 'ussr') or die(mysql_error());
mysql_select_db('ppusers') or die(mysql_error());
if ($_POST['nummer'] == 1)
{
  $username = $_POST['username'];
  $sql = mysql_query("SELECT * FROM users WHERE username = '$username'") or die(mysql_error());
  $rad = mysql_fetch_array($sql);
} else {
  $haha = 'tyvärr';
  echo $haha;
}
if($_POST['username'] == $rad['username'] && $_POST['password'] == $rad['password']) {
  $username = $_POST['username'];
  $antalbesok = $rad['antalbesok'] + 1;
  $senast = date('y-m-d');
  $sqlq = mysql_query("UPDATE users SET senast = '$senast', antalbesok = '$antalbesok' WHERE username = '$username'") or die(mysql_error());
  echo '<p>du är inloggad. Du förflyttas till startsidan.</p>';
  echo '<script language=javascript>';
  echo "self.location.replace('http://localhost/inloggad.php')";
  echo '</script>';
} else {
  echo '<p>Inloggningsförsöket misslyckades. Kontrolera användarnamn och lösenord och försök på nytt. </p><a href='http://localhost/start sida.php'>återgå</a>';
}
mysql_close($d);
?>
Post Reply