www.webdeveloper.com
Results 1 to 9 of 9

Thread: Trying to learn PHP and need some help. Please I am stuck

  1. #1
    Join Date
    Mar 2014
    Posts
    15

    Question Trying to learn PHP and need some help. Please I am stuck

    I have been reading the book "Murach's PHP and MySQL" and trying to follow all the samples and type them all out. I have already downloaded Xampp ver 3.2.1 and went through all the setup just like it shows. When I go through localhost it shows under status activated and all green. I am trying to run a practice program and the HTML part comes back fine but the text in the input boxes does not transition to the .php page when I enter information into the textbox and run the program it just displays blank responses. I am not sure if it's an error on the setup of the xampp or what I am doing wrong. The code (3 pages) HTML,CSS,PHP is below.

    HTML:

    !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" xml:lang="en" lang="en">
    <head>

    <title>Product Discount Calculator</title>
    <link rel="stylesheet" type="text/css" href="main.css" />
    </head>

    <body>
    <div id="content">
    <h1>Product Discount Calculator</h1>
    <form action="display_discount.php" method="post">

    <div id="data">
    <label>Product Description</label>
    <input type="text" name="product_description"/><br />

    <label>List Price</label>
    <input type="text" name="list_price"/><br />

    <label>Discount Percent:</label>
    <input type="text" name="discount_percent" />%<br />
    </div>

    <div id="buttons">
    <label>&nbsp;</label>
    <input type="submit" value="Calculate Discount" /><br />
    </div>
    </form>
    </div>

    </body>
    </html>

    PHP:

    <?php
    //get the data from the form
    $product_description = $_POST['product_description'];
    $list_price = $_POST['list_price'];
    $discount_percent = $_POST['discount_percent'];

    // calculate the discount
    $discount = $list_price * $discount_percent * .01;
    $discount_price = $list_price - $discount;

    // apply currency formatting to the dollar and percent amounts
    $list_price_formatted = "$".number_format($list_price, 2);
    $discount_percent_formatted = $discount_percent."%";
    $discount_formatted = "$".number_format($discount, 2);
    $discount_price_formatted = "$".number_format($discount_price, 2);
    ?>

    <!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" xml:lang="en" lang="en">
    <head>


    <title>Product Discount Calculator</title>
    <link rel="stylesheet" type="text/css" href="main.css" />
    </head>
    <body>
    <div id="content">
    <h1>Product Discount Calculator</h1>

    <label>Product Description:</label>
    <span><?php echo "$product_description"; ?></span><br />

    <label>List Price:</label>
    <span><?php echo "$list_price_formatted"; ?></span><br />

    <label>Standard Discount:</label>
    <span><?php echo "$discount_percent_formatted"; ?></span><br />

    <label>Discount Amount:</label>
    <span><?php echo "$discount_formatted"; ?></span><br />

    <label>Discount Price:</label>
    <span><?php echo "$discount_price_formatted"; ?></span><br />

    <p>&nbsp;</p>
    </div>
    </body>
    </html>

    CSS:
    body {
    font-family: Arial, Helvetica, sans-serif;
    margin: 10px;
    padding: 0;
    }

    #content {
    width: 450px;
    margin: 0 auto;
    padding: 15px;
    background: white;
    border: 2px solid navy;
    }

    h1 {
    color: navy;
    }

    label {
    width: 10em;
    padding-right: 1em;
    float: left;
    }

    #data input {
    float: left;
    width: 15em;
    margin-bottom: .5em;
    }
    #buttons input {
    float: left;
    margin-bottom: .5em;
    }

    br {
    clear: left;
    }

    I am sure it's probably the setup of the XAMPP because I have tried other demo's from the book and it does the same thing but not sure how to fix the problem.

  2. #2
    Join Date
    Jul 2013
    Location
    Voorheesville NY USA
    Posts
    546
    your posting is confusing.

    1 - please use the proper code tags in this forum.
    2 - please post an accurate view of how your code is actually written. Very confusing seeing your html page, followed by some php, followed by your html page. Don't think we need your css though.

  3. #3
    Join Date
    Mar 2014
    Posts
    15
    There are three pages the first one which has the HTML: above the code is for the opening application which ask for item name, item price, and discount %. The second page which has the PHP: above the code has the PHP code that is to get the information the person enters from the HTML and then it does the math and spits it back out to the HTML that's built onto the same PHP code page. This is the exact code from the book "murachs PHP and MySQL chapter one" which you can see the first chapter on their website www.murachs.com. I think my problem is the xampp setup because it shows all the HTML portion perfect but doesn't display the .PHP part of the program. What settings would be wrong on the xampp if it's not displaying the .php I have stopped the xampp and rebooted the computer and then restarted the xampp but the same thing happens. What is another way to test a program that is using PHP to see if it works.

  4. #4
    Join Date
    Jul 2013
    Location
    Voorheesville NY USA
    Posts
    546
    For one thing, a server doesn't "display the .php". For another - is it too much to ask for you to post the code again properly and properly labeled so we all understand each other??

    You could try a very simple little script that puts out a simple post form and see what happens with that to test your xampp.

  5. #5
    Join Date
    May 2014
    Posts
    49
    I am trying to run a practice program and the HTML part comes back fine but the text in the input boxes does not transition to the .php page when I enter information into the textbox and run the program it just displays blank responses.
    it shows all the HTML portion perfect but doesn't display the .PHP part of the program.
    1) So when you open the php page does anything show at all? Or is it just a full blank white page?
    2) I assume the address bar lists http:// and not file://?
    3) Try a simple hello world example and see if it shows:
    test.php
    PHP Code:
    <?php echo "hello world"?>
    or just a
    PHP Code:
    <?php phpinfo(); ?>
    4) If you view the source of the loaded PHP file in the browser, can you see the PHP code?
    5) Please put [php ] [/php] around your code so it's easy to read.

  6. #6
    Join Date
    Mar 2014
    Posts
    15
    When I open the PHP page it shows the div and the text but not any numbers someone would have entered from the first page before hitting submit. I have tried simple test PHP and it works like the hello world. Just when your asking for text input it doesn't show the end user input. It does still show localhost/htdocs/display_discount.php in the address bar.

  7. #7
    Join Date
    Mar 2014
    Posts
    15

    Trying to write the code so everyone can understand it better.

    This is the index.html file
    HTML Code:
    <!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" xml:lang="en" lang="en">
    	<head>
    				
    		<title>Product Discount Calculator</title>
    		<link rel="stylesheet" type="text/css" href="main.css" />
    	</head>
    	<body>
    		<div id="content">
    			<h1>Product Discount Calculator</h1>
    			<form action="display_discount.php" method="post">				
    				<div id="data">
    					<label>Product Description</label>
    					<input type="text" name="product_description"/><br />
    					
    					<label>List Price</label>
    					<input type="text" name="list_price"/><br />
    					
    					<label>Discount Percent:</label>
    					<input type="text" name="discount_percent" />%<br />
    				</div>
    				
    				<div id="buttons">
    					<label>&nbsp;</label>
    					<input type="submit" value="Calculate Discount" /><br />
    				</div>
    			</form>
    		</div>
    	</body>
    </html>
    This is the display_discount.php file yes this file has some HTML for displaying the HTML this is code from a textbook and just trying to figure why my text boxes are blank when you hit the submit button to start the application.
    PHP Code:
    <?php
        
    //get the data from the form
        
    $product_description $_POST['product_description'];
        
    $list_price $_POST['list_price'];
        
    $discount_percent $_POST['discount_percent'];
        
        
    // calculate the discount
        
    $discount $list_price $discount_percent .01;
        
    $discount_price $list_price $discount;
        
        
    // apply currency formatting to the dollar and percent amounts
        
    $list_price_formatted "$".number_format($list_price2);
        
    $discount_percent_formatted $discount_percent."%";
        
    $discount_formatted "$".number_format($discount2);
        
    $discount_price_formatted "$".number_format($discount_price2);
    ?>

    <!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" xml:lang="en" lang="en">
        <head>
            
            
            <title>Product Discount Calculator</title>
            <link rel="stylesheet" type="text/css" href="main.css" />
        </head>
        <body>
            <div id="content">
                <h1>Product Discount Calculator</h1>
                
                <label>Product Description:</label>
                <span><?php echo "$product_description"?></span><br />
                
                <label>List Price:</label>
                <span><?php echo "$list_price_formatted"?></span><br />
                
                <label>Standard Discount:</label>
                <span><?php echo "$discount_percent_formatted"?></span><br />
                
                <label>Discount Amount:</label>
                <span><?php echo "$discount_formatted"?></span><br />
                
                <label>Discount Price:</label>
                <span><?php echo "$discount_price_formatted"?></span><br />
                
                <p>&nbsp;</p>
            </div>
        </body>
    </html>

  8. #8
    Join Date
    Mar 2014
    Posts
    15
    I have the program working if I go to the internet and type it directly in http://localhost/aptana/product_discount_calculator/ then when I enter data into the text boxes and hit submit it calculates and brings back website http://localhost/aptana/product_disc...y_discount.php with the proper calculations. The problem seems to be when I use Aptana or notepad++ and run it from the text editor it opens this web-address file:///C:/xampp/htdocs/aptana/product_discount_calculator/index.html the when I enter data into the text boxes and hit submit it sends it to web-address
    file:///C:/xampp/htdocs/aptana/product_discount_calculator/display_discount.php so now I need to figure why when I use the text editor it does not use the localhost address. Is their a setting in the text editors I need to change. Remember I am new to learning PHP and using a local server I have only ever used HTML,CSS,JavaScript.

  9. #9
    Join Date
    May 2014
    Posts
    49
    Quote Originally Posted by pro2know View Post
    I have the program working if I go to the internet and type it directly in http://localhost/aptana/product_discount_calculator/ then when I enter data into the text boxes and hit submit it calculates and brings back website http://localhost/aptana/product_disc...y_discount.php with the proper calculations. The problem seems to be when I use Aptana or notepad++ and run it from the text editor it opens this web-address file:///C:/xampp/htdocs/aptana/product_discount_calculator/index.html the when I enter data into the text boxes and hit submit it sends it to web-address
    file:///C:/xampp/htdocs/aptana/product_discount_calculator/display_discount.php so now I need to figure why when I use the text editor it does not use the localhost address. Is their a setting in the text editors I need to change. Remember I am new to learning PHP and using a local server I have only ever used HTML,CSS,JavaScript.
    I've never opened a website from a text editor before, a text editor edits files on the local file system, not through the http protocol that the internet uses. The text editor most probably wouldn't even know where to find the live version.

    I normally just have the website open in 1 window and a text editor open separately. After I save any changes I ALT+TAB to the browser and refresh.

    This is normal behaviour in my opinion and something you might have to learn to work around, unless you have an IDE which is built to have this specific functionality. I've not used or seen one, probably because often the page address does not match the actual folder structure on the computer. Consider for example includes, htaccess redirects, etc.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles