| | |
hyperlink and upload in PHP
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Mar 2008
Posts: 22
Reputation:
Solved Threads: 0
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:
the second question is, about the upload, i tried to upload the file using the code shown below but unsuccessfully, here is the code:
and for the uploader.php code:
is the code correct? Thanks for helping...
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 Syntax (Toggle Plain Text)
<?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:
PHP Syntax (Toggle Plain Text)
<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 Syntax (Toggle Plain Text)
<?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...
Last edited by eparse; Mar 4th, 2008 at 4:50 am.
•
•
Join Date: Apr 2006
Posts: 66
Reputation:
Solved Threads: 11
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)?
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)?
•
•
Join Date: Mar 2008
Posts: 22
Reputation:
Solved Threads: 0
well, thanks for ur contribution, however
doesnt help.
for part of the function shown below, i cant get the link.....
However if the code changed to this:
i can see the hyperlink, but it already direct to the next page tho the username is invalid....
any mistakes here?
PHP Syntax (Toggle Plain Text)
echo "<a href='./page_to_redirect.php'>Click here</a>";
doesnt help.
for part of the function shown below, i cant get the link.....
PHP Syntax (Toggle Plain Text)
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:
PHP Syntax (Toggle Plain Text)
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?
•
•
Join Date: Apr 2006
Posts: 66
Reputation:
Solved Threads: 11
die() function its similar to exit() so the code after the command it won't be executed.
•
•
Join Date: Apr 2006
Posts: 66
Reputation:
Solved Threads: 11
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.
try to use physical path when referring to folder and also check if you have writing permission on that folder.
Last edited by silviuks; Mar 4th, 2008 at 6:04 am.
•
•
Join Date: Mar 2008
Posts: 22
Reputation:
Solved Threads: 0
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:
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..
because i am currently working on a form for clamming money, hence i need to validate the amount user enter, below is the code:
PHP Syntax (Toggle Plain Text)
if (cytype_digit('$amount')) { echo "This does not consist of only digits."; } else { echo "This cosists of only digits."; }
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..
•
•
Join Date: Apr 2006
Posts: 66
Reputation:
Solved Threads: 11
•
•
•
•
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:
however i get this message:PHP Syntax (Toggle Plain Text)
if (cytype_digit('$amount')) { echo "This does not consist of only digits."; } else { echo "This cosists of only digits."; }
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..
![]() |
Other Threads in the PHP Forum
- Previous Thread: I think this error is very simple..Pls help me..
- Next Thread: 3 lines of code not working
| Thread Tools | Search this Thread |
.htaccess ajax alerts apache api array autocomplete beginner binary broken cakephp checkbox class cms code convert cron curl database date directory display dynamic echo email emptydisplayvalue error explodefunction file files folder form forms function functions google hack href htaccess html htmlspecialchars image include insert integration ip java javascript joomla keywords limit link login loop mail menu methods mlm mod_rewrite multiple mysql network object oop paypal pdf php problem query radio random recursion redirect regex remote replace script search securephp server sessions sms soap source space sql syntax system table tutorial update upload url validation validator variable video web xml youtube





