hi for all the PHP experts here, i have couple of questions that keeps me feel frustrating..

first of all, may i know how to insert a link within PHP echo?
for example, i have a function which is used to validate the username, if the username is incorrect, i need to echo a link to let the user back to the login page, and if the username is admin, i will need to direct it to the admin page, if username is user, then it will be the default page i'd created in the form's action. Here is the code:

<?php
session_start();
$_SESSION['name']=$_POST['name'];
$_SESSION['password']=$_POST['password'];
$_SESSION['status']=$_POST['status'];
if($_POST['name']=="user" || $_POST['name']=="admin")
{
   // i need a link here to the pages
   echo "Your username is:  ".$_POST['name'];
}
else
{
   die('The username provided is not valid.  Please provide a correct username.');
}

if(strlen($_POST['password'])>=5 && $_POST['password']=="admin123" || $_POST['password']=="user123")
{
   echo " with password: ".$_POST['password'];
}
else
{
   die('.The password provided is not valid.  Please provide a a correct password.');
}
?>

the second question is, about the upload, i tried to upload the file using the code shown below but unsuccessfully, here is the code:

<form enctype="multipart/form-data" action="uploader.php" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="100000" >
<h1>Choose a file to upload:</h1>
<div><label><input name="uploadedfile" type="file" ><input type="submit" value="Upload File" ></label>
</div></form>

and for the uploader.php code:

<?php
$uploaddir = 'http://xxxx.xxxxxxx.com/phptryingnew_1/upload/files/';
$uploadfile = $uploaddir . basename($_FILES['userfile']['name']);
echo "<p>";
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
  echo "File is valid, and was successfully uploaded.\n";
} else {
   echo "Upload failed";
}
echo "</p>";
echo '<pre>';
echo 'Here is some more debugging info:';
print_r($_FILES);
print "</pre>";
?>

is the code correct? Thanks for helping...

Hello,
For your first question try something like this:
echo "<a href='./page_to_redirect.php'>Click here</a>";

for your second question try to use copy() function. also do you have writing permission on the server (for the folder where you try to upload)?

well, thanks for ur contribution, however

echo "<a href='./page_to_redirect.php'>Click here</a>";

doesnt help.

for part of the function shown below, i cant get the link.....

else
{
   die ('Sorry. Your username and password is invalid. Please try again.');
   echo "<a href='http://evios.freeweb7.com/phptryingnew_1/upload/index.php'>Click here back to login 

page.</a>";
}

However if the code changed to this:

else
{
   echo "Sorry. Your username and password is invalid. Please try again.";
   echo "<a href='http://evios.freeweb7.com/phptryingnew_1/upload/index.php'>Click here back to login page.</a>";
}

i can see the hyperlink, but it already direct to the next page tho the username is invalid....
any mistakes here?

die() function its similar to exit() so the code after the command it won't be executed.

well, now i knew die() means exit(), and my first problem solved. Thanks. Anyway, what is copy () function? Any clue on it? Thanks...

here are more details about the copy() function.
try to use physical path when referring to folder and also check if you have writing permission on that folder.

ok..thanks..however..does my upload code correct? or juz the server side permission?

ok..thanks..however..does my upload code correct? or juz the server side permission?

your code seems to be correct ... (except the part with $uploaddir = "http://.....")

last request....i try to use cytype for numbers validation...
because i am currently working on a form for clamming money, hence i need to validate the amount user enter, below is the code:

if (cytype_digit('$amount'))
{
    echo "This does not consist of only digits.";
}
else
{
    echo "This cosists of only digits.";
}

however i get this message:
Fatal error: Call to undefined function cytype_digit() in /www/freeweb7.com/e/v/i/evios/htdocs/phptryingnew_1/upload/claim_try.php on line 10
does it mean my web hosting doesnt include this cytype? any other method for validating numbers?? Thanks....
P/S: Any directories available for me to upload my files so that i can debug my upload.php..thanks again..

last request....i try to use cytype for numbers validation...
because i am currently working on a form for clamming money, hence i need to validate the amount user enter, below is the code:

if (cytype_digit('$amount'))
{
    echo "This does not consist of only digits.";
}
else
{
    echo "This cosists of only digits.";
}

however i get this message:
Fatal error: Call to undefined function cytype_digit() in /www/freeweb7.com/e/v/i/evios/htdocs/phptryingnew_1/upload/claim_try.php on line 10
does it mean my web hosting doesnt include this cytype? any other method for validating numbers?? Thanks....
P/S: Any directories available for me to upload my files so that i can debug my upload.php..thanks again..

i can't figure out why you get this error (unless you use a older version of php - like 3.x), but be aware that your if statement will display you "This does not consist of only digits." when its true.

i can't figure out why you get this error (unless you use a older version of php - like 3.x), but be aware that your if statement will display you "This does not consist of only digits." when its true.

well, the php version aint tht old, it is version 5.1.6 ....

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.