Jump to content
Larry Ullman's Book Forums

hfcnew

Members
  • Posts

    14
  • Joined

  • Last visited

Posts posted by hfcnew

  1. I'm actually on p.350. It said something about testing connection username and password by using them in the MySQL client, which I thought was a reference to p. 438.

     

    Anyhow, this is my code for mysqli_connect.php:

     

    <!doctype html>

    <html lang="en">
    <head>
       <meta charset="utf-8">
       <title>Connect to MySQL</title>
    </head>
    <body>
    <?php // Script 12.1 - mysqli_connect.php
    /* This script connects to the MySQL database. */
     
    // Attempt to connect to MySQL and print out messages:
    if ($dbc = mysqli_connect('localhost', 'username', 'password', 'myblog')) {
     
       print '<p>Successfully connected to the database!</p>';
       
       mysqli_close($dbc); // Close the connection.
       
     } else {
       print '<p style="color: red;">Could not connect to the database.</p>';
       
    }
     
    ?>
    </body>
    </html>

     

    But when I bring up its page, I get the following:

     

     

    Warning: mysqli_connect(): (HY000/1045): Access denied for user 'username'@'localhost' (using password: YES) in C:\xampp\htdocs\tutorialspoint\mysqli_connect.php on line 12 
    Could not connect to the database.

    As far as installing MySQL, I've just installed XAMPP on Windows 7 Professional.

    I thought XAMPP already has MySQL. Or have I misunderstood something?

  2. I'm currently at step 5 on p.440. 

    I got the "Enter password" prompt, but when I entered a password, I got the following response:

     

    ERROR 1045 <28000>: Access denied for user 'root'@'localhost' <using password: Y

    ES>

    It was really weird the way it was cut off like that. But try as I might, I could only expand the command prompt window vertically, not horizontally. So I'm not 100% sure what the messages are.

     

    So I tried using "yes" as a password and got this response:

     

    ERROR 1045 <28000>: Access denied for user 'root'@'localhost' <using password: N

    O>

    What am I doing wrong?

  3. Hello again. 
     
    When I tried out the scripts demonstrating transforming strings and arrays, this is what I got:

     

     

    Object not found!

    The requested URL was not found on this server. The link on the referring page seems to be wrong or outdated. Please inform the author of that page about the error.

    If you think this is a server error, please contact the webmaster.

    Error 404 localhost
    Apache/2.4.26 (Win32) OpenSSL/1.0.2l PHP/7.1.7

     

    Here's my code for list.html:

     

    <!doctype html>

    <html lang="en">
    <head>
       <meta charset="utf-8">
       <title>I Must Sort This Out!</title>
    </head>
    <body>
    <!-- Script 7.6 - list.html -->
    <div><p>Enter the words you want alphebetized with each individual word separated by a space:</p>
     
    <form action="list/php" method="post">
     
       <input type="text" name="words" size="60">
       <input type="submit" name="submit" value="Alphabetize!">
     
    </form>
    </div>
    </body>
    </html>

     

    and for list.php:

     

    <!doctype html>

    <html lang="en">
    <head>
       <meta charset="utf-8">
       <title>I Have This Sorted Out</title>
    </head>
    <body>
    <?php // Script 7.7 - list.php
    /* This script recieves a string in $_POST['words']. It then turns it into an array, sorts the array alphabetically, and reprints it. */
     
    // Address error management, if you want.
     
    // Turn the incoming string into an array:
    $words_array = explode(' ' , $_POST['words']);
     
    // Sort the array:
    sort($words_array);
     
    // Turn the array back into a string:
    $string_words = implode('<br>', $words_array);
     
    // Print the results:
    print "<p>An alphabetized version of your list is: <br>$string_words</p>";
     
    ?>
    </body>
    </html>

     

    What am I doing wrong?

  4. Dang it! I've already hit yet another snag!

     

    This is my current code for the Product Cost Calculator ("handle_calc.php" p.84&85):

     

    <!doctype html>

    <html lang="en">
    <head>
       <meta charset="utf-8">
       <title>Product Cost Calculator</title>
       <style type="text/css">
           .number { font-weight: bold; }
       </style>
    </head>
    <body>
    <?php // Script 4.2 - handle_calc.php
    /* This script takes values from calculator.html and performs
    total cost and monthly payment calculations. */
     
    // Address error handling, if you want.
     
    // Get the values from the $_POST array:
    $price = $_POST['price'];
    $quantity = $_POST['quantity'];
    $discount = $_POST['discount'];
    $tax = $_POST['tax'];
    $shipping = $_POST['shipping'];
    $payments = $_POST['payments'];
     
    // Calculate the total:
    $total = $price * $quantity;
    $total = $total + $shipping;
    $total = $total - $discount;
     
    // Determine the tax rate:
    $taxrate = $tax / 100;
    $taxrate = $taxrate + 1;
     
    // Factor in the tax rate:
    $total = $total * $taxrate;
     
    // Calculate the monthly payments:
    $monthly = $total / $payments;
     
    // Apply the proper formatting:
    $total = number_format($total, 2);
    $monthly = number_format($monthly, 2);
     
    // Print out the results:
    print "<p>You have selected to purchase:<br>
    <span class=\"number\">$quantity</span> widget(s) at <br>
    $<span class=\"number\">$price</span> price each plus a <br>
    $<span class=\"number\">$shipping</span> shipping cost and a <br>
    <span class=\"number\">$tax</span> percent tax rate.<br>
    After your $<span class=\"number\">$discount</span> discount, the total cost is
    $<span class=\"number\">$total</span>.<br>
    Divided over <span class=\"number\">$payments</span> monthly payments, that would be $<span class=\"number\"$monthly</span> each.</p>";
     
    ?>
    </body>
    </html>

     

    This the result when I run the calculator ("calculator.html"):

     

     

    You have selected to purchase:
    4 widget(s) at 
    $99 price each plus a 
    $8.95 shipping cost and a 
    5.5 percent tax rate.
    After your $25 discount, the total cost is $400.85.
    Divided over 24 monthly payments, that would be $ each.

    I'm looking, but I don't know why that last figure ("16.70") is not appearing.

  5. Hi, I had the same errors.  After much searching and testing different things this is what ended up working. 

     

    In your feedback.html page add this:

     

    <form enctype="form-data/multipart" method="POST" action="handle_form.php">

     

    After updating and saving the feedback.html page the handle_form.php page now works.  Remember to refresh the feedback.html page and start again before using it.

    Thanks! That worked!

     

    Hmm...thanks for sharing what worked for you, although it'd surprise me if that made a difference, but your mileage may vary. The most important question is whether the form is being submitted with data or not. If there's no data, then it should print those errors (as written at that point in the book). 

    I admit I didn't know that I actually had to add "http://" to the URL first. I thought it was already there even if I didn't literally see it in the address bar. BUT even after I did add "http://" it still didn't work. Only after I tried Quinn's suggestion did it work.

    Is there a reason why I and Quinn have to do something like this but others don't? Are we using versions of certain software that's too old or something?

  6. SWEAR I entered the code for lines 14-17 exactly as in the book:

     

    $title = $_POST['title'];
    $name = $_POST['name'];
    $response = $_POST['response'];
    $comments = $_POST['comments'];
     
    But the page I got was:
     
    Notice: Undefined index: title in C:\xampp\htdocs\tutorialspoint\handle_form.php on line 14

    Notice: Undefined index: name in C:\xampp\htdocs\tutorialspoint\handle_form.php on line 15

    Notice: Undefined index: response in C:\xampp\htdocs\tutorialspoint\handle_form.php on line 16

    Notice: Undefined index: comments in C:\xampp\htdocs\tutorialspoint\handle_form.php on line 17

    Thank you, , for your comments.

    You stated that you found this example to be '' and added:

     

     

    So I tried a suggestion I found online and altered the code like so:

     

    $title = isset($_POST['title']) ?$_POST['title'] : 0 ;
    $name = isset($_POST['name']) ? $_POST['name'] : '' ;
    $response = isset($_POST['response']) ? $_POST['response'] : '' ;
    $comments = isset($_POST['comments']) ? $_POST['comments'] : '' ;
     
    The page I got was the following:
     

    Thank you, 0 , for your comments.

    You stated that you found this example to be '' and added:

     

     

    Why isn't it working?

     

    P.S. Is there a way to attach files to posts as with emails? I've got screenshots of what I did.

     

     

  7. Hello all. First time user here.
    I don't think anyone's asked this yet, but my apologies if there's already a thread about this that I've missed.
     
    I recently purchased a copy of this book ("PHP for the Web: Visual QuickStart Guide, 5th Edition" of course) and followed one of its recommendations: to go to www.apachefriends.org to download XAMPP.
     
    I went to that site, followed alll the links, followed its installation wizard, but every time I've tried to install XAMPP (the Windows 7.1.7 version. My OS is Windows 7 Professional) the wizard keeps giving me this pop-up:

     

    Warning

    Problem running post-install step. Installation may not complete correctly
    Could not set registry key HKEY_LOCAL-MACHINE\Software\xampp Install_Dir
    REG_SZ

     

     

    How can I fix this?
    Or can I just ignore this?
     
    I've asked this question in the Apache Friends Support Forum about a week ago, but no one's responded yet.
    I'm hoping Mr. Ullman or someone can help me with this.
×
×
  • Create New...