PDA

View Full Version : help my code


0810
09-20-2002, 07:50 PM
script problem
Hi how are you doing? I am making a home page with php but I have a problem. I am using "User and Pass" script but When I click "submit button" my messages come same page. It can't go to next page.

I would like to do when a user click "submit button", it automatically goes to next page. How can I do it for that?

Could you explain with codes. Thank you very much for time.
My php is 4.22
Here is my code







<html>
<body>
<?php

if (isset($_POST['formSubmitted']) AND $_POST['formSubmitted'] == "yes")

// WHY NOT: if($_POST['formSubmitted'] == "yes')

{

$con = mysql_connect("localhost","itohideo","1234");

if(!$con)

{

print("Fail DB Connection<br>\n");

exit;

}



if(!mysql_select_db("itohideo"))

{

print("Fail DB Selection<br>\n");

exit;

}



$username=$_POST['username'];

$password=$_POST['password'];



$sql="SELECT * FROM kk WHERE username='$username' AND password='$password'";



$result = mysql_query($sql);

if(mysql_num_rows($result)==0)

{

echo"Username or Password is incorrect. Please try again.";

}

else

{

$row=mysql_fetch_array($result);

$username = $row["username"]; // <- CHANGED

echo ("welcome back &nbsp;<strong>".$username."</strong><br/>");

echo ("<a href=\"www.yourpage.com\">Click here to go to your home page </a>");

exit();

}



} ?>



Login:

<form action="<?php $_SERVER['PHP_SELF']; ?>" method="post">

Name: <input type="text" name="username" size="23"><br>

Pass: <input type="password" name="password" size="23"><br>

<input type="submit" value="Send" name="submit">

<input type='hidden' name='formSubmitted' value='yes'>

</form>



</body>

</html>

0810
09-20-2002, 11:01 PM
I fixed like this

but it is still not working

Do you have any idea??




<html>
<body>
<?php

if (isset($_POST['formSubmitted']) AND $_POST['formSubmitted'] == "yes")

// WHY NOT: if($_POST['formSubmitted'] == "yes')

{

$con = mysql_connect("localhost","itohideo","1234");

if(!$con)

{

print("Fail DB Connection<br>\n");

exit;

}



if(!mysql_select_db("itohideo"))

{

print("Fail DB Selection<br>\n");

exit;

}



$username=$_POST['username'];

$password=$_POST['password'];



$sql="SELECT * FROM kk WHERE username='$username' AND password='$password'";



$result = mysql_query($sql);

if(mysql_num_rows($result)==0)

{

echo"Username or Password is incorrect. Please try again.";

}

else

{

$row=mysql_fetch_array($result);

$username = $row["username"]; // <- CHANGED

header("Location:search.html");
exit();

}



} ?>



Login:

<form action="<?php $_SERVER['PHP_SELF']; ?>" method="post">

Name: <input type="text" name="username" size="23"><br>

Pass: <input type="password" name="password" size="23"><br>

<input type="submit" value="Send" name="submit">

<input type='hidden' name='formSubmitted' value='yes'>

</form>



</body>

</html>




search.html is same folder with this php script. Therefore, it should work but not

could you please help?????