Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > PHP How-To
|
PHP How-To Post your "How do I do this with PHP?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the PHP How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 26th, 2004, 08:05 PM
Authorized User
 
Join Date: Jun 2004
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
Default error in <form action='{$_SERVER['PHP_SELF']}

Hello,
I'm confused how to send value of hidden field in form which post to itself.
I redirect from transact-article.php to upload.php with following info: redirect('upload.php?article=' . $artid);

in upload.php I have these code lines:
...
$article = $_GET['article'];
...
if (!isset($_POST['do_action'])){
echo " <form action='{$_SERVER['PHP_SELF']}' method='post' enctype='multipart/form-data'>\n",
<input type='file' name='userfile'>\n";
<input type='hidden' name='artic' value='{$article}' />\n",
</form>
...
//input file name and artcile id into db
$sql = "INSERT INTO uploads " .
"(research_data_id, filename)" .
"VALUES ('" . $_POST['artic']. "', '" . trim($file_path) . "')";

This code give an error of undefined index in line
$article = $_GET['article'];

I tried to change it to $_POST, didn't help. I need this line when I get article id from file
transact-article.php with redirect('upload.php?article=' . $artid);

Could you please help me to solve the problem with Undefined index: article?

And also, there is another big problem: when I upload second file to same article( I call upload.php again) the article id is not resent, how can I submit it to upload.php again? I though the hidden field should do the work, but, probably I don't call it properly..
Please, help

Thank you,
 
Old July 27th, 2004, 01:07 AM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 479
Thanks: 0
Thanked 3 Times in 3 Posts
Send a message via MSN to surendran Send a message via Yahoo to surendran
Default

Here i give you a small file uploading part (adding database also)
please first create a file

companyprofile.php


<script language="javascript">
<!--
function uploadfile()
{
 window.open("upload.php","win",'width=250,height=1 50')
}
//-->
</script>
<form name="form1" method="post" onsubmit="return pqr()">
<input type="text" readonly name="txtImgname" size="20" id="txtbox" value="">
<a title="Click here to upload image" href="javascript:uploadfile()">Upload</a>

</form>
-----------------------
//please create a file
-----upload.php------------

<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>''... JOHNSON STEVENS AGENCIES LIMITED ...'''</title>
<link rel="stylesheet" type="text/css" href="images/jsal.css">
</head>
<script language="javascript">
<!--
function onsubmitter()
{
if (document.form1.userfile.value!="")
{
var val=document.form1.userfile.value
arr=val.split(".")
if ((arr[1].toLowerCase()!="jpg")&& (arr[1].toLowerCase()!="gif")&&(arr[1].toLowerCase()!="bmp")&&(arr[1].toLowerCase()!="jpeg")&&(arr[1].toLowerCase()!="tif")&&(arr[1].toLowerCase()!="png") )
{
alert("Please Select Images only")
return(false);
}

}
else
{
alert("Please Select an Image")
document.form1.userfile.value=""
return(false);
}
}
function noenter()
{
   event.returnValue = false;
}
//-->
</script>
<body topmargin="0" leftmargin="0" bgcolor="#C0C0C0">
<form enctype="multipart/form-data" name="form1" action="uploadresults.php" onsubmit="return onsubmitter()" method="post">
 <input type="hidden" name="mid">
  <table border="0" class="companyprofile" width="100%">
   <tr>
    <td width="10%">&nbsp;</td>
    <td width="80%">
      <p align="center"></td>
    <td width="10%">&nbsp;</td>
  </tr>
     <tr>
    <td width="10%">&nbsp;</td>
    <td width="80%">
      <p align="center"></td>
    <td width="10%">&nbsp;</td>
  </tr>
  <tr>
    <td width="10%">&nbsp;</td>
    <td width="80%">
      <p align="center"><input type="hidden" name="MAX_FILE_SIZE" value="3000000" />
 Send this file: <input name="userfile" onkeypress="javascript:noenter()" id="txtbox" type="file" />
 <input type="submit" onclick="avascript:return onsubmitter()" id="txtbox" value="Send File" /></td>
    <td width="10%">&nbsp;</td>
  </tr>
     <tr>
    <td width="10%">&nbsp;</td>
    <td width="80%">
      <p align="center"></td>
    <td width="10%">&nbsp;</td>
  </tr>
</table>

</form>


-----create another file -----
uploadresults.php
-----------------
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>''... JOHNSON STEVENS AGENCIES LIMITED ...'''</title>
<link rel="stylesheet" type="text/css" href="images/jsal.css">
</head>
<body topmargin="0" leftmargin="0" bgcolor="#C0C0C0">
<?php
// In PHP versions earlier than 4.1.0, $HTTP_POST_FILES should be used instead
// of $_FILES.

$uploaddir = 'D:/jsal/php/sen/images/';
$uploadfile = $uploaddir . $_FILES['userfile']['name'];
print "<pre>";
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
    $msg="File Uploaded Successfully";
} else {
   $msg="File Uploaded Faild! <br>Please try again" ;
}
print "</pre>";

?>
<form name="form1">
<input type="hidden" name="imgval" value="<?echo $_FILES['userfile']['name'];?>">
<table border="0" class="companyprofile" width="100%">
   <tr>
    <td width="10%">&nbsp;</td>
    <td width="80%">
      <p align="center"></td>
    <td width="10%">&nbsp;</td>
  </tr>
  <tr>
    <td width="10%">&nbsp;</td>
    <td width="80%">
      <p align="center"></td>
    <td width="10%">&nbsp;</td>
  </tr>
     <tr>
    <td width="10%">&nbsp;</td>
    <td width="80%">
      <p align="center"></td>
    <td width="10%">&nbsp;</td>
  </tr>
     <tr>
    <td width="10%">&nbsp;</td>
    <td width="80%">
      <p align="center"><b><?echo $msg;?></b></td>
    <td width="10%">&nbsp;</td>
  </tr>
   <tr>
    <td width="10%">&nbsp;</td>
    <td width="80%">
      <p align="center"></td>
    <td width="10%">&nbsp;</td>
  </tr>
     <tr>
    <td width="10%">&nbsp;</td>
    <td width="80%" align="center"> <input type="button" id="txtbox" onclick="window.close()" name="btnclose" value="Close">
      <p align="center"></td>
    <td width="10%">&nbsp;</td>
  </tr>
   <tr>
    <td width="10%">&nbsp;</td>
    <td width="80%">
      <p align="center"></td>
    <td width="10%">&nbsp;</td>
  </tr>
</table>
<script LANGUAGE="javascript">
        window.opener.document.form1.txtimgname.value=docu ment.form1.imgval.value
</script>
</form>
</body>


after that you can add your details in your database...

lanita... if you need any information please send me a mail i'll help you.

surendran
(Anything is Possible)





Similar Threads
Thread Thread Starter Forum Replies Last Post
<jsp:useBean> action problem austinf JSP Basics 1 August 21st, 2006 04:23 PM
Ch_6 $_SERVER["REQUEST_URI'] causes error Nobska BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0 1 January 26th, 2006 09:47 AM
error HREF=$PHP_SELF?action broccolo PHP Databases 5 December 26th, 2004 10:07 AM
error in PHP_SELF?action= broccolo PHP Databases 1 November 23rd, 2004 10:47 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.