HELP !!!
IGNOU MCA Students Forum


Posting in IMSF:

To Subscribe to Free SMS Alerts from IMSF, Click the Green SMS Button on the toolbar or SMS ON IMSF-IGNOU to 9870807070

  
 
Reply to this topicStart new topicStart Poll

> html & php help !, how to resolve script error?
pratikatpc
Posted: February 05, 2010 05:56 pm Posted since your last visit
Quote Post


Enrolled
Group Icon

Group: ACTIVE Members
Posts: 27
Member No.: 9,904
Joined: February 24, 2009

IGNOU:

MCA Joining Year: Not Applicable
Study Centre:



Hello "SANTANU" Thank you very much for your guidlines. Actually the problem was of read - write permission on server. [Chmode ]. Now it's working fine. THANK YOU ONCE AGAIN :thumbsup:
PMEmail Poster
Top
IMSF
Sponsored Links Posted since your last visit


Tech for GenY


Group: Bot




IGNOU:

MCA Joining Year:
Study Centre:





Top
santanu
Posted: February 05, 2010 07:04 am Posted since your last visit
Quote Post


Administrator
Group Icon

Group: Admin
Posts: 7,337
Member No.: 1
Joined: November 22, 2005

IGNOU:

MCA Joining Year: 2006
Study Centre:St. Xavier's College, Kolkata (2802)



The code is quite big...so its quite difficult to understand what is happening where. The  error is being handled in the program in the following code

CODE

//write to the file
           $fp = fopen("formTest.csv","a"); // $fp is now the file pointer to file $filename
           if($fp) {
               fwrite($fp,$cvsData);    //    Write information to the file
               fclose($fp);  //    Close the file
               //echo "File saved successfully";
......
......

} else {
//echo "Error saving file!";
               $message = 'Error saving file! ' . ' ' . 'Fill in areas in red!';


..meaning that first name, last name and email has not been filled up (although I don't see any problem in filling up) and hence file ws not saved.

QUOTE
$fp = fopen("formTest.csv","a");


Here fopen is being used to write a new file. The question is, whether you have enough write permissions in the server?

To test whether you can upload a file in your server, use this code:

1. In your PC, create a file called form.html and write the following within it
CODE

<html><head><body>
<form enctype="multipart/form-data" action="upload.php" method="POST">
Please choose a file: <input name="uploaded" type="file" /><br />
<input type="submit" value="Upload" />
</form>
</body>
</head>
</html>

2. Then create another file named upload.php and write the following in it
CODE

<?php
$target = "tmp/";
$target = $target . basename( $_FILES['uploaded']['name']);
$ok=1;

//This is our size condition
if ($uploaded_size > 350000)
{
echo "Your file is too large.<br>";
$ok=0;
}

//This is our limit file type condition
if ($uploaded_type =="text/php")
{
echo "No PHP files<br>";
$ok=0;
}

//Here we check that $ok was not set to 0 by an error
if ($ok==0)
{
Echo "Sorry your file was not uploaded";
}

//If everything is ok we try to upload it
else
{
if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target))
{
echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded";
}
else
{
echo "Sorry, there was a problem uploading your file.";
}
}
?>


3. Upload both form.html and upload.php in the same folder of the server. Then open form.html by typing http://yourdomain/yourfolder/form.html and select an existing .csv file in your PC and upload it. Pls. check if the file is uploaded and stored properly in your server.

4. If upload succeeds, you can simply try to create a file in your server from PHP. Create a php file filewrite.php and write the following code in it and upload and execute in server

CODE

<?php
$ourFileName = "formTest.csv";
$ourFileHandle = fopen($ourFileName, 'a') or die("can't open file");
fclose($ourFileHandle);
?>


Then check whether a blank file with name formtest.csv is being created. Try this in the same folder where you are trying to run your previous program.
PMEmail PosterUsers WebsiteYahooMSN
Top
Anubhav
Posted: February 04, 2010 11:36 pm Posted since your last visit
Quote Post


M.Tech
Group Icon

Group: Moderator
Posts: 613
Member No.: 188
Joined: April 03, 2006

IGNOU:

MCA Joining Year: 2007
Study Centre:BIT Bangalore



hi it seems u are using php short tags. are these enabled on ur php.ini file.
PMEmail Poster
Top
pratikatpc
Posted: February 04, 2010 10:26 pm Posted since your last visit
Quote Post


Enrolled
Group Icon

Group: ACTIVE Members
Posts: 27
Member No.: 9,904
Joined: February 24, 2009

IGNOU:

MCA Joining Year: Not Applicable
Study Centre:



Hello ,

  i have uploaded a web page http://examreg.freetzi.com/ at where one can fill out his details in the form & when he click submit button php script will run and validate input data and then generate a CSV [comma separated value] file & store it on server which can be viewed in excel.

but when i click on submit button php script also run but give same error every time. & say [as message defined in php] "error in saving file". here is the coding for html and php.

  I am not good at php  :(

CODE


<form id="form1" name="form1" method="post" action="contactFrm.php">
<table class="formatTblClass">
<tr>
<th colspan="6"><?=$message;?></th>
</tr>
<tr>
<td width="68"><span>First Name</span></td>
<td width="215"><input class="<?=$aClass;?>" type="text" name="fn" id="fn" /></td>
<td width="62"><span>Last Name</span></td>
<td colspan="3"><input class="<?=$aClass;?>" name="ln" type="text" id="ln" size="50" /></td>
</tr>
<tr>
<td colspan="6"><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="71">Address</td>
<td width="721"><input class="<?=$aClass;?>" name="address" type="text" id="address" size="100" /></td>
</tr>
</table></td>
</tr>
<tr>
<td><span>City</span></td>
<td><input class="<?=$aClass;?>" type="text" name="city" id="city" /></td>
<td><span>State</span></td>
<td width="148"><input class="<?=$aClass;?>" type="text" name="state" id="state" /></td>
<td width="24"><span>ZIP</span></td>
<td width="255"><input class="<?=$aClass;?>" type="text" name="zip" id="zip" /></td>
</tr>
<tr>
<td><span>Phone</span></td>
<td><input class="<?=$aClass;?>" type="text" name="phone" id="phone" /></td>
<td><span>Email</span></td>
<td><input class="<?=$aClass;?>" type="text" name="email" id="email" /></td>
<td><input name="emailMe" type="checkbox" id="emailMe" value="Yes" checked="checked" /></td>
<td>Please send me email</td>
</tr>
<tr>
<td colspan="6"><span>Comments
<textarea name="comments" id="comments" cols="45" rows="5"></textarea>
</span>
<div align="center">
<input type="submit" name="Submit" id="Submit" value="Submit" />
<input type="reset" name="Reset" id="button" value="Reset" />
</div></td>
</tr>
</table>
</form>

[COLOR=red]php  start here:[COLOR=red]

<?php
session_start();
function checkEmailAddress($orgEmail) {
    // First, we check that there's one @ symbol, and that the lengths are right
    if (!ereg("^[^@]{1,64}@[^@]{1,255}$", $orgEmail)) {
    // Email invalid because wrong number of characters in one section, or wrong number of @ symbols.
    return false;
    }
    // Split it into sections to make life easier
    $email_array = explode("@", $orgEmail);
    $local_array = explode(".", $email_array[0]);
    for ($i = 0; $i < sizeof($local_array); $i++) {
    if (!ereg("^(([A-Za-z0-9!#$%&'*+/=?^_`{|}~-][A-Za-z0-9!#$%&'*+/=?^_`{|}~\.-]{0,63})|(\"[^(\\|\")]{0,62}\"))$", $local_array[$i])) {
    return false;
    }
    }
    if (!ereg("^\[?[0-9\.]+\]?$", $email_array[1])) { // Check if domain is IP. If not, it should be valid domain name
    $domain_array = explode(".", $email_array[1]);
    if (sizeof($domain_array) < 2) {
    return false; // Not enough parts to domain
    }
    for ($i = 0; $i < sizeof($domain_array); $i++) {
    if (!ereg("^(([A-Za-z0-9][A-Za-z0-9-]{0,61}[A-Za-z0-9])|([A-Za-z0-9]+))$", $domain_array[$i])) {
    return false;
    }
    }
    }
    return true;
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style>
body{font-family:Arial, Helvetica, sans-serif;font-size:12px;}
table.formatTblClass{border-collapse:collapse;width:800px;border:1px solid #cccccc;background-color:#f1f1f1;}
table.formatTblClass th{background-color:#999999;color:#FFFFFF;}
.normFrmClass{}
.errorClass{border:1px solid #FF0000;color:#FF0000;}
</style>
</head>

<body>
<?php
if(!isset($_POST['Submit'])){
    $message = 'Fill out the form';
    $aClass = 'normFrmClass';
?>
<form id="form1" name="form1" method="post" action="contactFrm.php">
  <table class="formatTblClass">
                <tr>
                  <th colspan="6"><?=$message;?></th>
                </tr>
                <tr>
                  <td width="68"><span>First Name</span></td>
                  <td width="215"><input class="<?=$aClass;?>" type="text" name="fn" id="fn" /></td>
                  <td width="62"><span>Last Name</span></td>
                  <td colspan="3"><input class="<?=$aClass;?>" name="ln" type="text" id="ln" size="50" /></td>
                </tr>
                <tr>
                  <td colspan="6"><table width="100%" border="0" cellspacing="0" cellpadding="0">
                      <tr>
                        <td width="71">Address</td>
                        <td width="721"><input name="address" type="text" id="address" size="100" /></td>
                      </tr>
                    </table></td>
                </tr>
                <tr>
                  <td><span>City</span></td>
                  <td><input type="text" name="city" id="city" /></td>
                  <td><span>State</span></td>
                  <td width="148"><input type="text" name="state" id="state" /></td>
                  <td width="24"><span>ZIP</span></td>
                  <td width="255"><input type="text" name="zip" id="zip" /></td>
                </tr>
                <tr>
                  <td><span>Phone</span></td>
                  <td><input type="text" name="phone" id="phone" /></td>
                  <td><span>Email</span></td>
                  <td><input class="<?=$aClass;?>" type="text" name="email" id="email" /></td>
                  <td><input name="emailMe" type="checkbox" id="emailMe" value="Yes" checked="checked" /></td>
                  <td>Please send me email</td>
                </tr>
                <tr>
                  <td colspan="6"><span>Comments
                    <textarea name="comments" id="comments" cols="45" rows="5"></textarea>
                  </span>
                    <div align="center">
                    <input type="submit" name="Submit" id="Submit" value="Submit" />
                    <input type="reset" name="Reset" id="button" value="Reset" />
                  </div></td>
                </tr>
              </table>
</form>
<?php
}else{
    $fn = $_POST['fn'];
    $ln = $_POST['ln'];
    $address = $_POST['address'];
    $city = $_POST['city'];
    $state = $_POST['state'];
    $zip = $_POST['zip'];
    $phone = $_POST['phone'];
    $email = $_POST['email'];
    $emailMe = (isset($_POST['emailMe'])) ? $_POST['emailMe'] : 'No';
    $comments = $_POST['comments'];
    if(empty($fn) || empty($ln) || empty($email)){//show the form
        $message = 'Fill in areas in red!';
        $aClass = 'errorClass';
    ?>
    <form id="form1" name="form1" method="post" action="contactFrm.php">
      <table class="formatTblClass">
                <tr>
                  <th colspan="6"><?=$message;?></th>
                </tr>
                <tr>
                  <td width="68"><span>First Name</span></td>
                  <td width="215"><input class="<?=$aClass;?>" type="text" name="fn" id="fn" /></td>
                  <td width="62"><span>Last Name</span></td>
                  <td colspan="3"><input class="<?=$aClass;?>" name="ln" type="text" id="ln" size="50" /></td>
                </tr>
                <tr>
                  <td colspan="6"><table width="100%" border="0" cellspacing="0" cellpadding="0">
                      <tr>
                        <td width="71">Address</td>
                        <td width="721"><input name="address" type="text" id="address" size="100" /></td>
                      </tr>
                    </table></td>
                </tr>
                <tr>
                  <td><span>City</span></td>
                  <td><input type="text" name="city" id="city" /></td>
                  <td><span>State</span></td>
                  <td width="148"><input type="text" name="state" id="state" /></td>
                  <td width="24"><span>ZIP</span></td>
                  <td width="255"><input type="text" name="zip" id="zip" /></td>
                </tr>
                <tr>
                  <td><span>Phone</span></td>
                  <td><input type="text" name="phone" id="phone" /></td>
                  <td><span>Email</span></td>
                  <td><input class="<?=$aClass;?>" type="text" name="email" id="email" /></td>
                  <td><input name="emailMe" type="checkbox" id="emailMe" value="Yes" checked="checked" /></td>
                  <td>Please send me email</td>
                </tr>
                <tr>
                  <td colspan="6"><span>Comments
                    <textarea name="comments" id="comments" cols="45" rows="5"></textarea>
                  </span>
                    <div align="center">
                    <input type="submit" name="Submit" id="Submit" value="Submit" />
                    <input type="reset" name="Reset" id="button" value="Reset" />
                  </div></td>
                </tr>
              </table>
    </form>
    <?php
        }elseif(!checkEmailAddress($email)){
            $message = 'Bad Email Address!';
            $aClass = 'errorClass';
    ?>
        <form id="form1" name="form1" method="post" action="contactFrm.php">
                  <table class="formatTblClass">
                <tr>
                  <th colspan="6"><?=$message;?></th>
                </tr>
                <tr>
                  <td width="68"><span>First Name</span></td>
                  <td width="215"><input class="<?=$aClass;?>" type="text" name="fn" id="fn" /></td>
                  <td width="62"><span>Last Name</span></td>
                  <td colspan="3"><input class="<?=$aClass;?>" name="ln" type="text" id="ln" size="50" /></td>
                </tr>
                <tr>
                  <td colspan="6"><table width="100%" border="0" cellspacing="0" cellpadding="0">
                      <tr>
                        <td width="71">Address</td>
                        <td width="721"><input name="address" type="text" id="address" size="100" /></td>
                      </tr>
                    </table></td>
                </tr>
                <tr>
                  <td><span>City</span></td>
                  <td><input type="text" name="city" id="city" /></td>
                  <td><span>State</span></td>
                  <td width="148"><input type="text" name="state" id="state" /></td>
                  <td width="24"><span>ZIP</span></td>
                  <td width="255"><input type="text" name="zip" id="zip" /></td>
                </tr>
                <tr>
                  <td><span>Phone</span></td>
                  <td><input type="text" name="phone" id="phone" /></td>
                  <td><span>Email</span></td>
                  <td><input class="<?=$aClass;?>" type="text" name="email" id="email" /></td>
                  <td><input name="emailMe" type="checkbox" id="emailMe" value="Yes" checked="checked" /></td>
                  <td>Please send me email</td>
                </tr>
                <tr>
                  <td colspan="6"><span>Comments
                    <textarea name="comments" id="comments" cols="45" rows="5"></textarea>
                  </span>
                    <div align="center">
                    <input type="submit" name="Submit" id="Submit" value="Submit" />
                    <input type="reset" name="Reset" id="button" value="Reset" />
                  </div></td>
                </tr>
              </table>
                </form>
    <?php
        }else{
            //this is where the creating of the csv takes place
            $cvsData = $fn . "," . $ln . "," . $address . "," . $city . "," . $state . "," . $zip . "," . $phone . "," . $email . "," .$emailMe . "," . $comments ."\n";
            //write to the file
            $fp = fopen("formTest.csv","a"); // $fp is now the file pointer to file $filename
            if($fp){
                fwrite($fp,$cvsData);    //    Write information to the file
                fclose($fp);  //    Close the file
                //echo "File saved successfully";
                $message = 'Submission successfull. Thank you!';
                $aClass = 'normFrmClass';
                ?>
                <form id="form1" name="form1" method="post" action="contactFrm.php">
                  <table class="formatTblClass">
                <tr>
                  <th colspan="6"><?=$message;?></th>
                </tr>
                <tr>
                  <td width="68"><span>First Name</span></td>
                  <td width="215"><input class="<?=$aClass;?>" type="text" name="fn" id="fn" /></td>
                  <td width="62"><span>Last Name</span></td>
                  <td colspan="3"><input class="<?=$aClass;?>" name="ln" type="text" id="ln" size="50" /></td>
                </tr>
                <tr>
                  <td colspan="6"><table width="100%" border="0" cellspacing="0" cellpadding="0">
                      <tr>
                        <td width="71">Address</td>
                        <td width="721"><input name="address" type="text" id="address" size="100" /></td>
                      </tr>
                    </table></td>
                </tr>
                <tr>
                  <td><span>City</span></td>
                  <td><input type="text" name="city" id="city" /></td>
                  <td><span>State</span></td>
                  <td width="148"><input type="text" name="state" id="state" /></td>
                  <td width="24"><span>ZIP</span></td>
                  <td width="255"><input type="text" name="zip" id="zip" /></td>
                </tr>
                <tr>
                  <td><span>Phone</span></td>
                  <td><input type="text" name="phone" id="phone" /></td>
                  <td><span>Email</span></td>
                  <td><input class="<?=$aClass;?>" type="text" name="email" id="email" /></td>
                  <td><input name="emailMe" type="checkbox" id="emailMe" value="Yes" checked="checked" /></td>
                  <td>Please send me email</td>
                </tr>
                <tr>
                  <td colspan="6"><span>Comments
                    <textarea name="comments" id="comments" cols="45" rows="5"></textarea>
                  </span>
                    <div align="center">
                    <input type="submit" name="Submit" id="Submit" value="Submit" />
                    <input type="reset" name="Reset" id="button" value="Reset" />
                  </div></td>
                </tr>
              </table>
                </form>
                <?php
            } else {
                //echo "Error saving file!";
                $message = 'Error saving file! ' . ' ' . 'Fill in areas in red!';
                $aClass = 'errorClass';
            ?>
                <form id="form1" name="form1" method="post" action="contactFrm.php">
                  <table class="formatTblClass">
                <tr>
                  <th colspan="6"><?=$message;?></th>
                </tr>
                <tr>
                  <td width="68"><span>First Name</span></td>
                  <td width="215"><input class="<?=$aClass;?>" type="text" name="fn" id="fn" /></td>
                  <td width="62"><span>Last Name</span></td>
                  <td colspan="3"><input class="<?=$aClass;?>" name="ln" type="text" id="ln" size="50" /></td>
                </tr>
                <tr>
                  <td colspan="6"><table width="100%" border="0" cellspacing="0" cellpadding="0">
                      <tr>
                        <td width="71">Address</td>
                        <td width="721"><input name="address" type="text" id="address" size="100" /></td>
                      </tr>
                    </table></td>
                </tr>
                <tr>
                  <td><span>City</span></td>
                  <td><input type="text" name="city" id="city" /></td>
                  <td><span>State</span></td>
                  <td width="148"><input type="text" name="state" id="state" /></td>
                  <td width="24"><span>ZIP</span></td>
                  <td width="255"><input type="text" name="zip" id="zip" /></td>
                </tr>
                <tr>
                  <td><span>Phone</span></td>
                  <td><input type="text" name="phone" id="phone" /></td>
                  <td><span>Email</span></td>
                  <td><input class="<?=$aClass;?>" type="text" name="email" id="email" /></td>
                  <td><input name="emailMe" type="checkbox" id="emailMe" value="Yes" checked="checked" /></td>
                  <td>Please send me email</td>
                </tr>
                <tr>
                  <td colspan="6"><span>Comments
                    <textarea name="comments" id="comments" cols="45" rows="5"></textarea>
                  </span>
                    <div align="center">
                    <input type="submit" name="Submit" id="Submit" value="Submit" />
                    <input type="reset" name="Reset" id="button" value="Reset" />
                  </div></td>
                </tr>
              </table>
                </form>
            <?php
            }
        }//end if
}//end if
?>
</body>
</html>
PMEmail Poster
Top

Topic Options Reply to this topic Fast ReplyStart new topicStart Poll



 



[ Script Execution time: 0.1280 ]   [ 16 queries used ]   [ GZIP Enabled ]   [ Server Load: 2.57 ]






Skin arobase par alphega@ipb-skins.org 2005 (original)

Privacy Policy