Jump to content

Recommended Posts

I've been taking this PHP class for 7 weeks now and I am so lost.  The book doesn't do a good job explaining the workload and I am in desperate need of some good help.  I'm going to post my assignment below and hopefully get some guidance.  I'm not looking for the answers but for a better understanding of what I'm supposed to do and some guidance that will make this classa little more enjoyable.  Any help isgreatly appreciated

 

The purpose of this web application is to provide the head of the household with a report on the status of the family checking account. The application will simulate the process of looking up the account balance from the database, then it will place that balance in a predefined location within the web page.

 

Create an ordinary text file named solution06.txt. In that file, enter the text required to create a web page which will display information about the balance contained in a family's account.

NOTE: This text will eventually be inserted into the XHTML portion of your PHP script, so include HTML tags to format the text in an appropriate way. However, do not include the header tags - treat the text in this document as the body of the page, rather than the entire thing.

Within the web page, use the special text string [ACCT] to mark the place where the account number will be included in the text. Use the special string [bAL] to mark the place where the balance will be displayed.

Create an input form named solution06.html which will ask the visitor (the head of the family) to enter an account number (really a string).

Within the script, assign a value to a variable named $balance. Note that instruction will eventually be replaced with an instruction to read information from a database.

Within the script, add instructions which will open the text file you have created for the web page and read its contents into a variable named $pageBody.

Use the str_replace() function to replace the special strings [ACCT] and [bAL] with the appropriate pieces of information.

Display the resulting web page

Link to comment
https://forums.phpfreaks.com/topic/191209-im-soooo-lost/
Share on other sites

Okay, this may help or confuse you more! but if you can point out where you are in what book or explain the exact problem i maybe able to help more

 

okay so

 

create a  text file, ie

01234567,£12.00

 

and a html file ie

<B>[ACCT]<B>: [bAL]<BR />

 

Now

Within the script, assign a value to a variable named $balance. Note that instruction will eventually be replaced with an instruction to read information from a database.

Within the script, add instructions which will open the text file you have created for the web page and read its contents into a variable named $pageBody.

Use the str_replace() function to replace the special strings [ACCT] and [bAL] with the appropriate pieces of information.

Display the resulting web page

 

So you need to:~

1. read in the solution06.txt file (hint: file),

2. extract the Account and Balance from the comma delimited lines (hint: explode + bonus hint list)

3. assign the first part to $account and the second part to $balance (hint: $account = array[0] or see bonus hint above)

4. read in the file solution06.html (hint: file_get_contents)

5. use str_replace to replace ACCT and BAL with the $account and $balance

6. echo results / updated string

 

CHECK POINT test what you have..

 

 

NOW.. UPDATE,

 

solution06.txt to

01234567,£12.00
01212367,£1.00
01787787,£57.00
017894567,£102.00

 

new hints (re-read above list but with these hints)

1.5 foreach loop with take you thought each line.

5.5 you may want to use str_replace in a COPY of the solution06.html string)

6.5  concatenate string of multiple solution06.html stings

 

 

ie

$str = file_get_contents('solution06.html');
$display = "";
$display .= str_replace("[ACC]", $account, $str);
$display .= str_replace("[bAL]", $balance, $display);

Link to comment
https://forums.phpfreaks.com/topic/191209-im-soooo-lost/#findComment-1008157
Share on other sites

Im using the Book PHP6  fast & easy web development.  We are reviewing chapter 9 and 10 (Using your file system & Uploading files to your Web site).  I can tell youthat he bookhas a lot of errors to it.  The assignment is what I posted.  The instructor handed us the assignment she didn't take it from the book.  I don't know what else i can give you that can help you. All I know is that I have to turn in 3 separate post, .txt, .html, and .php and have them all interact with each other.  Thanks for the help!

Link to comment
https://forums.phpfreaks.com/topic/191209-im-soooo-lost/#findComment-1008165
Share on other sites

okay this is untested (I'm too lazy to create the files),

but i have added some comments to help explain it

 

<?php
/*solution06.html
<B>[ACCT]<B>: [bAL]<BR />
*/
/*solution06.txt
01234567,£12.00
01212367,£1.00
01787787,£57.00
017894567,£102.00
*/
$HTML = ""; //OUTPUT html
$HTMLPart = file_get_contents('solution06.html'); //get HTML part, just get the whole file into a string

$accounts = file('solution06.txt'); // get Details, we use FILE as it reads line by line

foreach($accounts as $acc){ //loop though details (line by line)
//
//Option 1
$details = explode(",",$acc); //convert a comma delimited string into an array
$account = $acc[0]; //assign $account to the FIRST item in the array (which is 0) arrays start at 0
$balance = $acc[1]; //assign $balance to the SECOND item in the array
//~~OR~~
//Option 2
list($account,$balance) = explode(",",$acc); //convert a comma delimited string into an array and assign variables
//

$display = str_replace("[ACC]", $account, $HTMLPart); // assign temp html string to html part replacing ACC with account number
$display = str_replace("[bAL]", $balance, $display); // assign temp html string to itself replacing BAL with balance
$HTML .= $display; // concatanate OUTPUT HTML with updated HTML Part
}
echo $HTML; //Output

 

PS I'm not in the habit of doing others homework as it will cause more problems for them.. so please make sure it makes sense and any questions please fell free to ask

Link to comment
https://forums.phpfreaks.com/topic/191209-im-soooo-lost/#findComment-1008177
Share on other sites

I guess I need something more basic.  All that is too confusing, this is the fist time I've ever used PHP.  I don't get it.  I know that I need to have 3 separate scripts that will some how talk to each other.

Let me first start with the .txt file, this is what I think it should look like(PLEASE let me know if it's wrong):

 

<HTML>

<HEAD>

<TITLE>My Title Here</TITLE>

</HEAD>

<BODY>

<P>This is the textfile that will display the results</P>

<P>Account number is [ACCT]and balance is [bAL]</P>

</BODY>

</HTML>

 

as you can see, I need this explained as if one were talking to a 7 year old :).  Again, thanks for the help!! I do appreciate it.

   

Link to comment
https://forums.phpfreaks.com/topic/191209-im-soooo-lost/#findComment-1008187
Share on other sites

Oh I read the instructions wrong, its simpler than the code I wrong  :-[

 

Details,

okay first we create a small part of  HTML code, but as we want the data to be dynamic we put some tags in the file that we can replace later (ACC and BAL), Then we create a HTML FORM (i assume you know how to do this), now the form has 2 inputs named account and balance, and the forms action is solution06.php,

 

Now we write the PHP code to get the input from the FORM and get the HTML from the txt file and replace the known tags with the form data..

 

 

Okay first of all

do not include the header tags - treat the text in this document as the body of the page, rather than the entire thing.

so,

Step 1 - Create solution06.txt

<P>This is the textfile that will display the results</P>
<P>Account number is [ACCT] and balance is [bAL]</P>

 

That's step 1 done.

 

Step 2 - Create solution06.html

Create a form that requires 2 inputs account number and balance

 

Step 3 - Create solution06.php

$pageBody = file_get_contents('solution06.txt'); //put file into variable
//Get form data
$account = $_POST['account'];
$balance= $_POST['balance'];

//Replace data in text file from with form data
$pageBody = str_replace("[ACC]", $account, $pageBody);
$pageBody = str_replace("[bAL]", $balance, $pageBody);
echo $pageBody;

 

Okay i hope that has helped

Link to comment
https://forums.phpfreaks.com/topic/191209-im-soooo-lost/#findComment-1008200
Share on other sites

Okay,so i think I got the HTML part. No please don't assume I know how to do anything :) I am so lost it's not even funny.  Okay, please take a look at my HTML file:

<HTML>

<HEAD>

<TITLE>Solutio06.html</TITLE>

</HEAD>

<BODY>

<P><strong>Please enter your account number and balance: </strong></P>

<FORM METHOD="GET" ACTION="solution06.php">

<br /> Client's account number: <input type="text" name="account number" />

<br /> Client's balance: <input type="text" name="balance" /> <br>

<input type = "submit" Name= "submit" value= "submit" />

</FORM>

</BODY>

</HTML>

 

I tested it out but when it went to the php file I got the follwing error:

Notice: Undefined index: account in C:\wamp\www\solution06.php on line 5

 

Notice: Undefined index: balance in C:\wamp\www\solution06.php on line 6

 

This is the text file that will display the output results.

 

Account number is and balance is

 

so basically I can see that there is something wrong with lines:

$account = $_POST['account'];

$balance= $_POST['balance'];

 

and of course i have no clue what is can possible be.

 

Thank You SOOOOOOOOOOOOOOOOOOOOOOOOOOO MUCH for taking the time to help me out. 

Link to comment
https://forums.phpfreaks.com/topic/191209-im-soooo-lost/#findComment-1008208
Share on other sites

Okay, the error, (always read them)

Notice: Undefined index: account in C:\wamp\www\solution06.php on line 5

So line 5 & 6 would be

$account = $_POST['account'];
$balance= $_POST['balance'];

and Undefined index means it  $_POST['account'] &  $_POST['balance'] don't exist.. but why ?

 

Well because we are sending GET and expecting POST So change

METHOD="GET" 

to

METHOD="POST"

(as we are using $_POST instead of $_GET in our code)

 

now that should fix balance, but your still get the error for account .. Why ?

 

Well look, we send

<input type="text" name="account number" />

and expect

$account = $_POST['account'];

Now it IS POST but the name is different

 

So  name="account number" should be name="account"

 

Try that

Link to comment
https://forums.phpfreaks.com/topic/191209-im-soooo-lost/#findComment-1008212
Share on other sites

Heyyyyyyyyyyyyyyy.....thanks worked, thanks.  I met up with my teacher today and she was impressed. I told her I got help from here and she allowed me to use any source needed because she knows how bad the book is.  I appreciate ALL of your time and help.  You are a life saver.  I would appreciate your help in fute assignments, I have another 5 weeks left for this class:)

Link to comment
https://forums.phpfreaks.com/topic/191209-im-soooo-lost/#findComment-1008523
Share on other sites

I'm glade that all is working and am sure that your find this forum a great resource, I'll be happy to help out (where time permits) as I'm sure others will also help,

 

Just make sure you read the code at the end and make sure you understand it all, and try to write the code again (but try to refer to your working as little as possible) this will help highlight what parts you need to work on.

 

Oh and one thing you need to keep in mind,

Forum Guidelines

3. Users will not post their homework questions expecting to get their homework coded for them. If you have a question about part of the assignment that you do not understand, please post asking for an explanation rather than the code.

Now you seam like you want to learn instead of just pass so you should be okay

 

on a last note, in the bottom left theirs a mark solved button, click that to mark this post as solved (you can unsolved it if needed)

EDIT: I marked this as solved for you

 

 

Link to comment
https://forums.phpfreaks.com/topic/191209-im-soooo-lost/#findComment-1008615
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.