hello friendz..

jst a small query..

i made simple userinput form as userform.php....
after submit the form..values are passed to adduser.php for inserting to database... i have a serverside validation tht username cant be same...!!

if(username is laready exist)
{
[B]header('location:userform.php?error=1');[/B]//user send back to userinput form..
}
else
{
[B]header('location:login.php');[/B]//user logged in
}

i jst want to know, is header only solution... is there any alternative to it..?? what if i dont want to send 'error=1' through url...!!! then how can i send back the error msg..???

Waiting for positive reply..!!

Recommended Answers

All 8 Replies

How about process the form on the same page. Why does it need to be submitted to another page?

hello friendz..

jst a small query..

i made simple userinput form as userform.php....
after submit the form..values are passed to adduser.php for inserting to database... i have a serverside validation tht username cant be same...!!

if(username is laready exist)
{
[B]header('location:userform.php?error=1');[/B]//user send back to userinput form..
}
else
{
[B]header('location:login.php');[/B]//user logged in
}

i jst want to know, is header only solution... is there any alternative to it..?? what if i dont want to send 'error=1' through url...!!! then how can i send back the error msg..???

Waiting for positive reply..!!

There's also the get method. page.php?error=2

You could also use .htaccess to hide this given error in the url so it would apear like; page.php

There's also the get method. page.php?error=2

You could also use .htaccess to hide this given error in the url so it would apear like; page.php

i think get method is used with forms..!!! but here no forms r used..!!

.htaccess ..!! this is something new to me..!! can u tell me somthing more about...i would appreciate that..!! :D

actually i dont want to send msg through url...!!

i use header to jump from one to another with caring some msg..!!
like

if(condition false)
{
header('location:index.php?rr=1');
}
else
{
header('location:login.php?rr=1');
}

i dont to pass error msg through url... is there anyone way..?

Well you could always force a HTTP error. If thats what you mean.

Or you could always include an error page, there are many ways to do this but it's all about what will work best for you.

Well if you post your page and what the error is you're trying to give and then I could give you a solution.

Well you could always force a HTTP error. If thats what you mean.

Or you could always include an error page, there are many ways to do this but it's all about what will work best for you.

Well if you post your page and what the error is you're trying to give and then I could give you a solution.

Well my Style is Quiet Simple as i m a Fresher..!!! Here is my set of code...how do i work...!!

//index.php

<? if($_GET['error']==1) echo"user already exit"; ?>
<form action="adduser.php" method="post">
<p>Username</p>
<p><input type="text" name="username"</p>
<p><input type="submit">
</form>

//adduser.php
<?php
//Database connection and select database

$query = "select * from table where username = $username";
$result = mysql_query($query);
$count = mysql_num_rows($result);

if($count > 0)
{
  header("Location: index.php?error=1");
}
else
{
   header("location: login.php"); // login page
}
?>

this is jst a rough code.. but i hope got an Idea what i want..!!!
I jst dont want to use header to jump from one page to another...!! or if header is only solution than i dont want to pass values through URL..!!! :)

I hope You will reply with Solution..!! :)

Thanks.!!

Yuo could just include a page containign the error?

Also could you not just build the code into the block where you are redirecting.

Or if you would like to use shortcode then create a function like return_error(1);
and have a list of all different error codes etc. This could just echo out an error message or an entire page...

The other alternative is using .htaccess's RewriteMod to tidy the url so the user doesn't realise it is in the title.

yeah i made a different page which contains only errors...but still to get error msg, i have to use URL...!!!
.
.
can you write a small code about function..how can i use it in place of headers..!!
or
Give more details or any LINK which provide more information about .htaccess cleaning the URL..

that will be a gr8 help..!!!! :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.