2011-07-10 78 views
-5

我收到此錯誤 警告:fopen()函數預計至少2個參數,1 C中給出:\ WAMP \ WWW \ fileFormProcess.php第19行錯誤在PHP不知道我做錯了

警告:FEOF():提供的參數是不是在C有效的流資源:\瓦帕\ WWW \ fileFormProcess.php上線29

警告:與fgets():提供的參數是不是在C的有效流資源:\ wamp \ www \ fileFormProcess.php on line 30

警告:錯誤的參數數量在線31上的C:\ wamp \ www \ fileFormProcess.php中的explode()

我一直在看文件,看不到我做錯了什麼。 這裏是我的代碼:

<?php 

if($_POST['firstName']==""|| $_POST['lastName']==""|| $_POST['address']==""||  $_POST['city']==""|| $_POST['state']==""|| $_POST['zip']==""){ 
header("Location:fileInsert.php?status=2"); 
} 
else{ 
$newRecord="\n"; 
$newRecord.=$_POST['lastName']."|".$_POST['firstName']."|".$_POST['address']."|".$_POST['city']."|".$_POST['state']."|".$_POST['zip']; 

$myFile="records.txt"; 
$fp = fopen($myFile, "a"); 

//Write the data to the file 
fwrite($fp, $newRecord); 

//Close the file 
fclose($fp); 
if (file_exists($myFile)) { 
$file = fopen($myFile.'r'); 
$rowcount=0; 
echo "<html>\n"; 
echo " <head>\n"; 
echo " <title>Sucess!</title>\n"; 
echo " <link href=\"contact1.css\" type=\"text/css\" rel=\'stlesheet\">"; 
echo " </head>\n"; 
echo " <body>"; 
echo " <table width=\"75%\" cellpadding=\"2\" cellspacing=\"2\" border=\"1\">\n"; 
echo " <tr>\n"; 
while (!feof($file)) { 
$line = fgets($file); 
$aryData=explode("|",$line); 
$firstname=$aryData[1]; 
$lastname=$aryData[0]; 
$address=$aryData[2]; 
$city=$aryData[3]; 
$state=$aryData[4]; 
$zip=$aryData[5]; 
echo "<td align=\"center\">"; 
echo $firstname."".lastname; 
echo "<br>".$address; 
echo "<br>".$city.".".$state."".$zip; 
echo "</td>\n"; 
$rowcount++; 
if ($rowcount!=0 && $rowcount%3==0){ 
    echo " </tr>\n"; 
    echo " <tr>\n"; 
    } 

} 
while($rowcount%3!=0){ 
echo "<td>&nbsp;</td>\n"; 
$rowcount++; 
} 
echo "</table>\n"; 
} 
} 
echo "</body>\n"; 
echo " </html>\n"; 

<?php 
if ($_GET['status']==2){ 
    $strMessage="<strong>All fields are required!</strong>"; 
} 
elseif($_GET['status']==1){ 
    $strMessage="<strong>Your information has been added.</strong>"; 
} 
else{ 
$strMessage=""; 
} 
?> 
<html> 
<head> 
<link href="contact1.css" type="text/css" rel="stylesheet"> 
<title>Write to a file</title> 
<style type="text/css"> 
fieldset{ 
width:50%; 

} 
</style> 

</head> 
<body> 
<?php echo $strMessage; ?> 
<p> 
<form name='myForm' method='post' action="fileFormProcess.php"> 
    <fildset><legand><i>All Fields are Required</i></legand> 

    <table id='form' border='0' cellpadding='6'> 
    <tr> 
<td>First Name:</td> 
<td><input type='text' name='firstName'></td> 
    </tr> 
    <tr> 
<td>Last Name:</td> 
<td> 
<input type='text' name='lastName'></td> 
    </tr> 
    <tr> 
<td>Street Address:</td> 
<td><input type='text' name='address'></td> 
    </tr> 
    <tr> 
<td>City:</td> 
<td><input type='text' name='city'></td> 
    </tr> 
    <tr> 
<td>State:</td> 
<td><input type='text' name='state'></td> 
    </tr> 
    <tr> 
<td>Zip:</td> 
<td><input type='text' name='zip'></td> 
    </tr> 
    <tr> 
<td><input type='reset' value='Reset Form' name='reset'></td> 
<td><input type='submit' value='Submit Form' name='submit'></td> 
</tr> 
    </table> 
    </fieldset> 
    </form> 
    </p> 
    </body> 
    </html> 

,這是它想拉從

Scott|Michael|23 Guist Rd|Scranton|PA|12345 
    Beesly|Pam|4359 Justin Ave|Pittsburg|PA|44709 
    Halpert|Jim|450 Sawdust Lane|Chicago|IL|55830 
    Braff|Zach|33082 Buckthorn Rd|Dalton|OH|40988 
    Keenan|Maynard|89 Treeview Blvd|Page Springs|AZ|85377 
    Hedburg|Mitch|9000 Beerbohm Dr|Cadiz|OH|43990 
    Cook|Dane|23 River Rd|Krabill|OR|66264 
    Griffin|Lois|123 Our Street|Quahog|RI|48756 

現在我沒有保存record.txt的record.txt文件在我的www wamp文件下,我只是不知道我做錯了什麼?

回答

3

$file = fopen($myFile.'r');應該是$file = fopen($myFile,'r');

2

我收到此錯誤Warning: fopen() expects at least 2 parameters, 1 given in C:\wamp\www\fileFormProcess.php on line 19

那麼,什麼是第19行?

$file = fopen($myFile.'r'); 

它說它期望兩個參數,但只得到一個。參數用逗號分隔,但這一行沒有逗號,所以你只給它一個參數。據推測,你的意思是輸入,,但輸入.,導致錯誤。更換線

$file = fopen($myFile,'r'); 

是你所需要做的。

2
$myFile.'r' 

錯字......應該是一個逗號,我想;-)

2

此:

fopen($myFile.'r') 

應該是這樣的:

fopen($myFile, 'r') 
相關問題