Page 1 of 2 12 LastLast
Results 1 to 40 of 46

Thread: [RESOLVED] PHP Validator/Error checking

  1. #1

    Thread Starter
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Resolved [RESOLVED] PHP Validator/Error checking

    Hi,

    Does anyone know if and where I can get a php validator/Error checker? I have tried using the built-in validator in Dream Weaver. However, it only works for the html and not the php. I am following instructions that my lecturer has given us but I am missing something and I can not figure out what. This is an example of the code:

    PHP Code:
    <?php
    //Start new session
    session_start();
    $email $_POST['Email'];
    $password $_POST['Password']; 
    if ((
    $email == "[email protected]")&&
    (
    $password == "password")){
    //Save the values in session variables
    $_SESSION['email'] = $email;
    echo 
    "<h2>Authorisation success!!!</h2>";
    echo 
    "<a href=member_page.php>Click here to go to the members page</a>";
    }
    else
    {
    header("Location: login.htm");
    exit;
    }
    ?>
    With the above code when accessed via wampserver through htm the follow appears on the screen:

    Authorisation success!!!"; echo "Click here to go to the members page"; } else { header("Location: login.htm"); exit; } ?>
    It outputs the code to the screen too and I can not see why?

    Thanks,

    Nightwalker
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  2. #2
    WiggleWiggle dclamp's Avatar
    Join Date
    Aug 2006
    Posts
    3,527

    Re: PHP Validator/Error checking

    the file extension needs to be .php not .htm

    so myfile.php

  3. #3

    Thread Starter
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Re: PHP Validator/Error checking

    Quote Originally Posted by dclamp View Post
    the file extension needs to be .php not .htm

    so myfile.php
    Yeah, the file is a php file that is being access via another html file! The user enters data into the html page and sends it then the php script responds.

    Edit:

    The problem with that page was I was using upper letters for the first letter of the field name when they were in-fact lower case in the html.

    However, with this code:

    PHP Code:
    <?php
    session_start
    ();
    if(isset(
    $_SESSION['email']));
    {
    $email $_SESSION['email'];
    echo 
    "<h1>Member Page</h1>";
    echo 
    "<p><h2>Welcome back $email</h2></p>";
    echo 
    "<br /><p><b>Your user email is: $email</b></p><br />";
    echo 
    "<p><h2><a href=logout.php>Logout</a></h2></p>";
    }
    else
    {
    //Redirected back to login form if not authorised.
    header("Location: login.htm");
    exit;
    }
    ?>
    There is a problem with the else statement! If I comment out the else statement like so:

    PHP Code:
    //else
    //{
    //Redirected back to login form if not authorised.
    //header("Location: login.htm");
    //exit;
    //} 
    The code works normally!
    Last edited by Nightwalker83; Aug 1st, 2009 at 08:34 PM. Reason: Fixed spelling
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  4. #4
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629

    Re: PHP Validator/Error checking

    well, there's nothing wrong with your syntax. you need to be a little more specific than just "there is a problem."

  5. #5

    Thread Starter
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Re: PHP Validator/Error checking

    Quote Originally Posted by kows View Post
    well, there's nothing wrong with your syntax. you need to be a little more specific than just "there is a problem."
    I'm not sure what the problem is! I have commented out the else statement as stated above and it works. I just can't see why it's not working with the else in the code.

    Edit:

    The error points to the line "//else" as a parse error! I'm not sure what that means?
    Last edited by Nightwalker83; Aug 2nd, 2009 at 06:02 AM. Reason: Adding more
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  6. #6
    PowerPoster kfcSmitty's Avatar
    Join Date
    May 2005
    Posts
    2,248

    Re: PHP Validator/Error checking

    Why do you have a semicolon after your if?

    PHP Code:
    if(isset($_SESSION['email'])); 

  7. #7

    Thread Starter
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Re: PHP Validator/Error checking

    Quote Originally Posted by kfcSmitty View Post
    Why do you have a semicolon after your if?

    PHP Code:
    if(isset($_SESSION['email'])); 
    It was a typo however, removing it has solved the problem. Thanks!
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  8. #8

    Thread Starter
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Re: PHP Validator/Error checking

    I can't figure out why this is not working:

    login.php
    PHP Code:
    <?php
    //Start new session
    session_start();
    $email $_POST['email'];
    $password $_POST['password']; 
    if ((
    $email == "")&&
    (
    $password == "")){
    header("Location: login.htm");
    exit;
    }
    else
    {
    //Connect to the server and select database
    require_once ('conn_db.php');
    //Create and issue the query
    $query "select * from customers where Email = '$email' AND Password = '$password'";
    $result mysql_query ($query) or die ("Invaid Customer ID or Password");

    //Get the number of rows in the results set; should be 1 if there is a match
    if (mysql_num_rows($result) == 1){
    //If authorized, get values of firstname, lastname, phone and email
    $first_name=mysql_result($result0"first_name");
    $last_name=mysql_result($result0"last_name");
    $phone=mysql_result($result0"phone");
    $email=mysql_result($result0"email");
    mysql_close();
    //Save the values in session variables
    $_SESSION['first_name'] = $first_name;
    $_SESSION['last_name'] = $last_name;
    $_SESSION['phone'] = $phone;
    $_SESSION['email'] = $email;
    echo 
    "<h2>Authorisation success!!!</h2>";
    echo 
    "<a href=member_page.php>Click here to go to the members page</a>";
    }
    else
    {
    header ("Location: login.htm");
    exit;
    }
    }
    conn_db.php
    PHP Code:
    <?php
    # FileName = "conn_db.php"

    $hostname "localhost";
    $database "custdb";
    $user "user";
    $pass "password";
    //Connect
    $mysql_link mysql_connect($hostname$user,$pass) or die ("Unable to connect to mysql server!");
    mysql_select_db ($database,$mysql_link) or die ("Unable to select database!");
    ?>
    The form is suppose to connect to the database and display the record matching the email and password. However, I receive this error:

    Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'user'@'localhost' (using password: YES) in C:\wamp\www\Lesson 5\conn_db.php on line 9
    Unable to connect to mysql server!
    That error is referring to the "conn_db.php" posted above. I tried putting user privileges on the database to match above but the page takes a while to send the data then I receive this error, see attachment!
    Attached Images Attached Images  
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  9. #9
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629

    Re: PHP Validator/Error checking

    sounds like you have an incorrect username or password?

  10. #10

    Thread Starter
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Re: PHP Validator/Error checking

    Quote Originally Posted by kows View Post
    sounds like you have an incorrect username or password?
    I managed to copy the code from the pdf that we were given! Unfortunately, I can't test to see if it works because of the problem with apache (above).
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  11. #11
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629

    Re: PHP Validator/Error checking

    well, the error you posted is just a generic "program not responding/program crashed" error. you could try looking at the Apache error log to see what happened, it should be in /error/ or /logs/ or something similar in the Apache directory. my guess is it won't be incredibly helpful though.

    changing MySQL user privileges wouldn't make Apache crash. MySQL and Apache are completely unrelated -- so you must have done something else (or your computer must have, or something).

    I'd just reinstall Apache from scratch if you can't get it working.

  12. #12

    Thread Starter
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Re: PHP Validator/Error checking

    Quote Originally Posted by kows View Post
    well, the error you posted is just a generic "program not responding/program crashed" error. you could try looking at the Apache error log to see what happened, it should be in /error/ or /logs/ or something similar in the Apache directory. my guess is it won't be incredibly helpful though.

    changing MySQL user privileges wouldn't make Apache crash. MySQL and Apache are completely unrelated -- so you must have done something else (or your computer must have, or something).
    I'd just reinstall Apache from scratch if you can't get it working.

    I have reinstalled WampServer twice and Apache still crashes. I am wondering if it was because I edited the wrong files when editing the apache httpd.conf and httpd-ssl.conf before I had setup the program properly. Although, I remember replacing the files with back ups of the originals afterward.
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  13. #13
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629

    Re: PHP Validator/Error checking

    Never dealt with packages that install Apache, MySQL and PHP together. I always just install them separately and have no problems. you might want to give it a try, but I'm not entirely sure it would fix anything.

  14. #14

    Thread Starter
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Re: PHP Validator/Error checking

    I'm trying to do that on Vista but I'm having a hard time setting it up:

    http://www.vbforums.com/showthread.php?t=574444
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  15. #15
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629

    Re: PHP Validator/Error checking

    erm. am I missing something? the link you posted shows you asking about IIS but not Apache.

    but, that brings up a question -- are you trying to run both Apache and IIS at the same time, on the same port? IIS could be using the port and Apache could be crashing because of it.

  16. #16

    Thread Starter
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Re: PHP Validator/Error checking

    Quote Originally Posted by kows View Post
    erm. am I missing something? the link you posted shows you asking about IIS but not Apache.

    but, that brings up a question -- are you trying to run both Apache and IIS at the same time, on the same port? IIS could be using the port and Apache could be crashing because of it.
    No! I trying to setup IIS in that thread since Vista has a strange way with dealing with phpdev/wamp server. I have tried installing both phpdev and wampserver on Vista but the IIS is needed in order to use it.

    At the moment I have Wampserver installed on my laptop (where apache is causing problems) and I am trying to setup IIS on my pc.
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  17. #17
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629

    Re: PHP Validator/Error checking

    I highly doubt that IIS is needed to install these MySQL/PHP/Apache packages on Vista. Like I said before, I've never used a packaged installer, but I've converted a Vista machine into a web server before with no problems. And I definitely didn't use IIS. IIS is just another web server (Apache is the web server in the case of both WAMP and PHPdev), it doesn't even need to be installed or turned on. In my case, I used it to create an FTP while Apache ran my web services. If you can't get it to work, install them separately.

    And I don't really think I can help you with your Apache crashing problem!

  18. #18

    Thread Starter
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Re: PHP Validator/Error checking

    Quote Originally Posted by kows View Post
    I highly doubt that IIS is needed to install these MySQL/PHP/Apache packages on Vista.
    I do too! I'm just having difficulty locating the files in the "www" directory because whenever I start wampserver in Vista instead of localhost display the link to the files in the "www" directory it displays the IIS website.
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  19. #19
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: PHP Validator/Error checking

    I suggested you ditch WAMP and install each component individually. Start with Apache, then PHP theh MySql.
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  20. #20
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: PHP Validator/Error checking

    And disable IIS too
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  21. #21

    Thread Starter
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Re: PHP Validator/Error checking

    Well, it looks like only one of my tutorials was causing problems with wampserver (apache). All the other tutorials I tested worked in Wampserver.

    Edit:

    Quote Originally Posted by visualAd View Post
    I suggested you ditch WAMP and install each component individually. Start with Apache, then PHP theh MySql.
    What difference would that make?

    Quote Originally Posted by visualAd View Post
    And disable IIS too
    Done!
    Last edited by Nightwalker83; Aug 16th, 2009 at 06:40 AM. Reason: Adding more
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  22. #22
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: PHP Validator/Error checking

    Quote Originally Posted by Nightwalker83 View Post
    What difference would that make?
    Do you know how to configure the PHP Apache module in the httpd.conf file? If the answer is no, then that is the difference it will make.

    One click installations of a complex envrionment like that will never be flawless and IMO encourage users to blindly install and use the tools without a sound understanding of how they interact and work together and without the experience to fix any configuration issues.

    Packages such as WAMP also include their own bespoke configurations which can cause problems with some web applications and system set ups.
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  23. #23

    Thread Starter
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Re: PHP Validator/Error checking

    Quote Originally Posted by visualAd View Post
    Do you know how to configure the PHP Apache module in the httpd.conf file? If the answer is no, then that is the difference it will make.
    Ah ok! However, I been given notes by my lecturer about what lines in that file I must change.
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  24. #24

    Thread Starter
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Re: PHP Validator/Error checking

    The reason I was receiving the error in post #8 was because I was trying to close to database when it was still being accessed via an external script.

    To fix the problem I replaced:

    PHP Code:
    mysql_close(); 
    in login.php

    with

    PHP Code:
    mysql_close($mysql_link); 
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  25. #25
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629

    Re: PHP Validator/Error checking

    you never, ever need to call mysql_close(). PHP does this for you. you can just get rid of that call altogether.

  26. #26
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: PHP Validator/Error checking

    Quote Originally Posted by Nightwalker83 View Post
    The reason I was receiving the error in post #8 was because I was trying to close to database when it was still being accessed via an external script.

    To fix the problem I replaced:

    PHP Code:
    mysql_close(); 
    in login.php

    with

    PHP Code:
    mysql_close($mysql_link); 
    Odd, I never saw those lines in the original code. Then again, it does lack calrity and readability so I may have missed it
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  27. #27

    Thread Starter
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Re: PHP Validator/Error checking

    Quote Originally Posted by visualAd View Post
    Odd, I never saw those lines in the original code. Then again, it does lack calrity and readability so I may have missed it
    The line is in there after:

    PHP Code:
    $email=mysql_result($result0"email"); 
    I forgot to mention in my other post that the close statement should go just before the final else.
    Last edited by Nightwalker83; Aug 18th, 2009 at 07:40 PM. Reason: Fixing spelling!
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  28. #28

    Thread Starter
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Re: PHP Validator/Error checking

    My lecturer just informed me that WAMPServer 2.0 which I was using was not compatibile with the code he gave us (i.e the above code). He advised me to use xampplite instead.
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  29. #29
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: PHP Validator/Error checking

    I reiterate, you should install it yourself.
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  30. #30

    Thread Starter
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Re: PHP Validator/Error checking

    Quote Originally Posted by visualAd View Post
    I reiterate, you should install it yourself.
    I'm guessing my lecturer wanted us to use the wamp software because it was/is easy to install. Whereas this is better alternative for school because it means you don't have to stuff around installing multiple programs on a system just to have these programs removed until next time you have that class.

    The computers at our school have software on them that refresh the system state after a certain period of time. Therefore any software that was not installed prior will be removed.
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  31. #31

    Thread Starter
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Re: [RESOLVED] PHP Validator/Error checking

    Could some please figure out how to get this code working:

    PHP Code:
    conn_video.php 
    <?php 
    # FileName="conn_video.php" 
    $hostname"localhost"&#894; 
    $database "cartdb"&#894; 
    $user "root"&#894; 
    $pass ""&#894; 
    mysql_connect($hostname,$user,$pass) or die( "Unable to 
    connect to the server"
    )&#894; 
    mysql_select_db($database) or die( "Unable to select the 
    database"
    )&#894; 
    ?>
    products.php
    PHP Code:
    <?php 
    session_start
    ()&#894; 
    $type $_POST['type']&#894;
    $item_name $_POST['item_name']&#894; 
    //connect to server and select database 
    require_once('conn_video.php')&#894; 
    //Search products 
    if (($item_name=="") && ($type=="")) 
    $query "SELECT item_id, item_name FROM 
    products"
    &#894; 
    else if (($item_name=="") && ($type !="")) 
    $query "SELECT item_id, item_name FROM products 
    WHERE (type = '
    $type')"&#894; 
    else if (($item_name!="") && ($type =="")) 
    $query "SELECT item_id, item_name FROM products 
    WHERE (item_name='
    $item_name')"&#894; 
    else 
    $query "SELECT item_id, item_name FROM products 
    WHERE (type = '
    $type' AND item_name='$item_name')"&#894; 
    $result mysql_query ($query) or die ("query 2 
    failed"
    )&#894; 
    mysql_close()&#894; 
    ?> 
    <html> 
    <body> 
    <form method="post" action="products.php"> 
    <table width="699" border="0"> 
    <tr> 
    <td><strong>Title</strong></td> 
    <td><strong>Category</strong></td> 
    <td><strong>Search</strong></td> 
    <td>&nbsp;</td> 
    </tr> 
    <tr> 
    <td width="152"><input name="item_name" 
    type="text" id="item_name"></td> 
    <td width="196"><select name="type" size="1" 
    id="type"> 
    <option selected></option> 
    <option value="comedy">Comedy</option> 
    <option value="romance">Romance</option> 
    <option value="action">Action</option> 
    <option value="other">Other</option> 
    </select></td> 
    <td width="121"> 
    <div align="left">
    <input type="submit" name="Submit" 
    value="Search"> 
    </div></td> 
    <td width="212"><a 
    href="view_cart.php"><strong>View your Shopping Cart 
    </strong></a></td> 
    </tr> 
    </table> 
    </form> 
    <table width="100%"  border="1"> 
    <tr> 
    <td><b>Select Item</b> </td> 
    <td><b> Item Name </b></td> 
    <td><b> Quantity </b></td> 
    <td><b> Add to Cart </b></td> 
    </tr> 
    <?php 
    //Display products 
    while ($row mysql_fetch_row 
    ($result)) 

    echo 
    "<tr><form  action=add_to_cart.php 
    method=POST>"
    &#894; 
    echo "<td> <input name= item_id 
    type=checkbox id= 
    $row[0] value=$row[0]></td>"&#894; 
    echo "<td> $row[1]</td>"&#894; 
    echo"<td><input name=qty type=text 
    id=qty value=1 size=4 maxlength=2></td>"
    &#894; 
    echo"<td><INPUT  name=add TYPE=submit 
    id=add value=Add><td>"
    &#894; 
    echo "</tr></form>"&#894; 

    ?> 
    </form> 
    </table> 
    </td> 
    <td height="244" align="center" valign="middle"><p 
    align="left">&nbsp;</p> 
    <p align="left">&nbsp;</p></td> 
    </tr> 
    </table> 
    </body> 
    </html>
    add_to_cart.php

    PHP Code:
    <?php
    session_start
    ();
    include 
    'cart.php';
    //Get the item id and the quantity
    if(isset($_POST['item_id'], $_POST['qty'])){
    $item_id $POST['item_id'];
    $qty $POST['qty'];
    }
    // Store the number of items in the shopping cart
    $counter $_SESSION ['counter'];
    $cart = new Cart ();
    // Unserialized the cart if the cart is not empty
    if ($counter>0)
    $cart Unserialize ($_SESSION ['cart']);
    else
    {
    session_register ('cart');
    session_register ('counter'); 
    }
    if ((
    $item_id =="") or ($qty <1))
    {
    header ("Location: products.php");
    exit;
    }
    else
    {
    //Connect to server and select database
    require_once('conn_video.php');
    $query "SELECT item_name, price FROM products WHERE (item_id = 'item_id')";
    $result mysql_query ($query) or die ("Database Error!");
    if (
    mysql_num_rows ($result)==1){
    $item_name mysql_result($result0"item_name");
    $price mysql_result($result0"price");
    //Add to the cart
    $new_item = new Item ($item_id$item_name$qty$price);
    $cart->additem($new_item);
    //Update the counter
    $_SESSION ['counter'] = $counter 1;
    $_SESSION ['cart'] = serialize ($cart);
    header ("Location: view_cart.php");
    mysql_close();
    }
    else
    {
    header ("Location: products.php");
    exit;
    }
    }
    ?>
    remove_from_cart.php

    PHP Code:
    <?php 
    session_start
    ()&#894; 
    include 'cart.php'&#894; 
    $item_no=$_POST['item_no']&#894; 
    //remove item from the cart if selected ¬ mark as 
    deleted 
    if ($item_no!=""){ 
    $counter $_SESSION['counter']&#894; 
    $cart = new Cart()&#894; 
    $cart unserialize($_SESSION['cart'])&#894; 
    //delete selected item from the cart 
    $cart&#172;>delete_item($item_no); 
    //update the counter 
    $_SESSION['counter'] = $counter&#172;1; 
    $_SESSION['cart'] = serialize($cart)&#894; 
    header("Location: view_cart.php")&#894; 

    ?>
    view_cart.php
    PHP Code:
    <?php 
    session_start
    ()&#894; 
    include 'cart.php'&#894; 
    $cart = new Cart()&#894; 
    $counter$_SESSION['counter']&#894; 
    ?> 
    <html> 
    </head> 
    <body> 
    <table width="100%"  border="0"> 
    <tr>
    <td height="244" colspan="4" valign="top"> 
    <?php 
    //check whether the cart is empty or not 
    if ($counter==0){ 
    echo
    "<h1>Shopping Cart</h1>"&#894; 
    echo"<br><br><p><b> Your Shopping Cart is 
    empty !!! </b></p>"
    &#894; 
    echo"<p><b> <a href=products.php>Go back to 
    products </a> </b></p>"
    &#894; 

    else { 
    $cart unserialize($_SESSION['cart'])&#894; 
    //$cart = $_SESSION['cart']; 
    $depth $cart&#172;>get_depth(); 
    echo"<h1>Shopping Cart</h1>"&#894; 
    echo "<table border=1>"&#894; 
    echo"<tr><td><b>Item 
    Name</b></td><td><b>Quantity</b></td><td><b> 
    Price</b></td></tr>"
    &#894; 
    for ($i=0&#894; $i < $depth; $i++) 

    $item $cart&#172;>get_item($i); 
    $deleted $item&#172;>deleted; 
    //display if the item is not marked for 
    deletion 
    if (!$deleted){ 
    $item_id $item&#172;>get_item_id(); 
    $item_name $item&#172; 
    >get_item_name()&#894; 
    $qty $item&#172;>get_qty(); 
    $price $item&#172;>get_price(); 
    echo "<tr><form 
    action=remove_from_cart.php method=POST>"
    &#894; 
    echo"<td>$item_name</td><td>$qty 
    </td><td>
    $price</td>"&#894; 
    echo "<td> <input name= item_no 
    type=checkbox id= item_no value=
    $i></td>"&#894; 
    echo"<td><INPUT  name=remove 
    TYPE=submit id=remove value=Remove><td>"
    &#894; 
    echo "</tr></form>"&#894; 


    echo 
    "</table>"&#894;
    echo"<p><b> <a href=checkout.php>Checkout 
    </a> </b></p>"
    &#894; 
    echo"<p><b> <a href=products.php>Go back to 
    products </a> </b></p>"
    &#894; 

    ?> 
    </tr> 
    </table> 
    </body> 
    </html>
    checkout.php

    PHP Code:
    <?php 
    session_start
    ()&#894; 
    include 'cart.php'&#894; 
    $cart = new Cart()&#894; 
    $counter$_SESSION['counter']&#894; 
    if ($counter==0
    echo
    "<br><br><p><b> Your Shopping Cart is 
    empty !!! </b></p>"
    &#894; 
    else { 
    $cart unserialize($_SESSION['cart'])&#894; 
    $depth $cart&#172;>get_depth(); 
    echo"<h1>Shopping Cart</h1>"&#894; 
    echo "<table border=1>"&#894; 
    echo"<tr><td><b>Item 
    Name</b></td><td><b>Quantity</b></td><td><b> 
    Price</b></td></tr>"
    &#894; 
    for ($i=0&#894; $i < $depth; $i++) 

    $item $cart&#172;>get_item($i); 
    $deleted $item&#172;>deleted; 
    if (!$deleted){ 
    $item_id $item&#172;>get_item_id(); 
    $item_name $item&#172; 
    >get_item_name()&#894; 
    $qty $item&#172;>get_qty(); 
    $price $item&#172;>get_price(); 
    $total_price $total_price 
    (
    $price*$qty)&#894; 
    echo"<tr><td>$item_name</td><td>$qty 
    </td><td>
    $price</td></tr>"&#894; 


    echo
    "<tr><td><b> Total 
    </b></td><td>&nbsp;</td><td><b>
    $total_price</b></td></tr>"&#894;
    echo "</table>"&#894; 
    echo"<p><b> <a href=view_cart.php>Remove 
    Items from the Cart </a> </b></p>"
    &#894; 
    echo"<p><b> <a href=products.php>Go back to 
    products </a> </b></p>"
    &#894; 

    ?>
    The code is for a shopping cart! It was a example my lecturer gave us but I haven't been able to get it to work My lecturer gave me his working example but I have misplaced it.

    This code is also required for the above example:

    cart.php
    PHP Code:
    <?php

    class Item {
        var 
    $item_id;
        var 
    $item_name;
        var 
    $qty;
        var 
    $price;

        var 
    $deleted false;

        function 
    get_item_cost() {
          return 
    $this->qty $this->price;
        }

        function 
    delete_item() {
            
    $this->deleted true;
        }

        function 
    Item ($item_id$item_name$qty$price) {
            
    $this->item_id $item_id;
            
    $this->item_name $item_name;
            
    $this->qty $qty;
            
    $this->price $price;
        }

        function 
    get_item_id() {
            return 
    $this->item_id;
        }
        
        function 
    get_item_name() {
            return 
    $this->item_name;
        }
        function 
    get_qty() {
            return 
    $this->qty;
        }
        function 
    get_price() {
            return 
    $this->price;
        }

    }

    class 
    Cart {
        var 
    $items;
        var 
    $depth;

        function 
    Cart() {
            
    $this->items = array();
            
    $this->depth 0;
        }

        function 
    add_item($item) {
            
    $this->items[$this->depth] = $item;
            
    $this->depth++;
        }

        function 
    delete_item($item_no) {
            
    $this->items[$item_no]->delete_item();
        }

        function 
    get_depth() {
            return 
    $this->depth;
        }
        function 
    get_item($item_no) {
            return 
    $this->items[$item_no];
        }
    }

    ?>
    And the sql for the database:
    PHP Code:
    CREATE TABLE `customers` (
      `
    first_namevarchar(15NOT NULL,
      `
    last_namevarchar(20NOT NULL,
      `
    phonevarchar(20NOT NULL,
      `
    emailvarchar(30NOT NULL,
      `
    passwordvarchar(8NOT NULL,
      
    PRIMARY KEY  (`email`)
    ENGINE=InnoDB DEFAULT CHARSET=latin1;

    CREATE TABLE `orders` (
      `
    order_idvarchar(20NOT NULL,
      `
    emailvarchar(30NOT NULL,
      `
    shipping_addresstext NOT NULL,
      `
    total_amountdecimal(6,2NOT NULL,
      `
    statusvarchar(15NOT NULL,
      
    PRIMARY KEY  (`order_id`)
    ENGINE=InnoDB DEFAULT CHARSET=latin1;


    CREATE TABLE `order_line` (
      `
    order_idvarchar(20NOT NULL,
      `
    item_idvarchar(6NOT NULL,
      `
    qtyint(4NOT NULL
    ENGINE=InnoDB DEFAULT CHARSET=latin1;

    CREATE TABLE `products` (
      `
    item_idvarchar(6NOT NULL,
      `
    item_namevarchar(30NOT NULL,
      `
    pricedecimal(6,2NOT NULL,
      `
    typevarchar(15NOT NULL,
      `
    item_datedate NOT NULL default '2004-11-11',
      
    PRIMARY KEY  (`item_id`)
    ENGINE=InnoDB DEFAULT CHARSET=latin1;


    INSERT INTO `products` (`item_id`, `item_name`, `price`, `type`, `item_date`) VALUES
    ('1001''Life on Mass''12.00''Action''2004-11-11'),
    (
    '1002''Load of the Ring I''16.00''Action''2004-11-11'),
    (
    '1003''Heros S1''36.00''Action''2004-11-11'),
    (
    '1004''Friends S2''19.00''Comedy''2004-11-11'); 
    Edit:

    Sorry about the mess the above was copied from a pdf through gmail.
    Last edited by Nightwalker83; Oct 25th, 2009 at 07:44 PM. Reason: Adding more!
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  32. #32
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629

    Re: [RESOLVED] PHP Validator/Error checking

    I'm not sure why you insist on bumping old threads to ask completely unrelated questions? in a resolved thread nonetheless? lol :/

    if you copied all of this code directly, and I'm assuming the forum hasn't messed anything up, you have an HTML entity instead of a terminator (";") at the end of each full line. if this is actually the code you're running, then do a find on "&#894;" and replace it with ";", and then do a find on "&#172" and replace it with "-".

    other than that, maybe you should ... tell us what errors you're getting? if you haven't, turn on error reporting and tell us something -- if it isn't obvious what the errors mean.

  33. #33

    Thread Starter
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Re: [RESOLVED] PHP Validator/Error checking

    Well for products I still need to fix the following:

    Notice: Undefined index: type in on line 50
    Notice: Undefined index: item_name in products.php on line 51
    I looked at my code and the fields are named:

    HTML Code:
    <td><input name="item_name" type="text" id="item_name"/></td>
    <td><select name="type" size ="1" id="type">
    Just like the php is reffering to.

    PHP Code:
    $type $_POST['type'];
    $item_name $_POST['item_name']; 
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  34. #34
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629

    Re: [RESOLVED] PHP Validator/Error checking

    okay, except you define those variables before you even know whether or not "products.php" has been submitted to -- it obviously has not, which means those variables aren't set.

    even still, you didn't answer anything I asked in my post. I don't know how to "fix" your code if it's a A) a complete mess and un-runnable as is (second line in my post), and B) you can't tell me what it's doing wrong.

    if the only problem is that you're getting is undefined indexes, then just make sure those variables exist before assigning values.

    PHP Code:
    if(isset($_POST['var1'], $_POST['var2'])){
      
    $myvar1 $_POST['var1'];
      
    $myvar2 $_POST['var2'];


  35. #35

    Thread Starter
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Re: [RESOLVED] PHP Validator/Error checking

    Quote Originally Posted by kows View Post
    okay, except you define those variables before you even know whether or not "products.php" has been submitted to -- it obviously has not, which means those variables aren't set.

    even still, you didn't answer anything I asked in my post. I don't know how to "fix" your code if it's a A) a complete mess and un-runnable as is (second line in my post), and B) you can't tell me what it's doing wrong.
    oops, you are correct! ; is replacing ";" and &#172; replacing "-" although I don't know why that happened. I can't copy directly from the pdf file because it is protected that's why I use the above method to copy the text.

    if the only problem is that you're getting is undefined indexes, then just make sure those variables exist before assigning values.

    PHP Code:
    if(isset($_POST['var1'], $_POST['var2'])){
      
    $myvar1 $_POST['var1'];
      
    $myvar2 $_POST['var2'];

    Thanks! If that doesn't work I'll ask my lecturer tomorrow for his working code then compare the above with it and see what I missed out.

    Edit:

    Well, that solved the problem with the products page! However, Add to cart isn't working and I don't receive any errors. It looks like I have to ask my lecturer.
    Last edited by Nightwalker83; Oct 25th, 2009 at 07:34 PM. Reason: Adding more!
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  36. #36

    Thread Starter
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Re: [RESOLVED] PHP Validator/Error checking

    Ok! this code works.

    add products:
    PHP Code:
    <?php
    session_start
    ();
    include 
    'cart.php';
            
    //get the item_id and the quantity
            
    $item_id=$_POST['item_id'];
            
    $qty=$_POST['qty'];
            
    //store number of items in the shopping cart
            
    $counter $_SESSION['counter'];
            
    $cart = new Cart();
            
    //unserialize the cart if the cart is not empty
            
    if ($counter>0)
                
    $cart unserialize($_SESSION['cart']);
            else {
                
    session_register('cart');
                
    session_register('counter');
            }
            if ((
    $item_id == "")or ($qty 1))
            {
                    
    header("Location: products.php");
                    exit;
            }
            else
            {
                
    //connect to server and select database
                
    require_once('conn_video.php');
                   
    $query "SELECT item_name, price from products WHERE (item_id = '$item_id') ";
                
    $resultmysql_query($query) or die( "Database Error");
                if (
    mysql_num_rows($result) == 1) {
                    
    $item_name=mysql_result($result,0,"item_name");
                    
    $price=mysql_result($result,0,"price");
                    
    //add items to the cart
                    
    $new_item = new Item($item_id$item_name$qty$price);
                    
    $cart->add_item($new_item);
                    
    //update the counter
                    
    $_SESSION['counter'] = $counter+1;
                    
    $_SESSION['cart'] = serialize($cart);
                    
    header("Location: view_cart.php");
                }
                else
                    {
                         
    header("Location: products.php");
                            exit;
                     }
            }
        
    ?>
    checkout:
    PHP Code:
    <?php
    session_start
    ();
    include 
    'cart.php';
    $cart = new Cart();
    $counter$_SESSION['counter'];
            
    if (
    $counter==0)
                echo
    "<br><br><p><b> Your Shopping Cart is empty !!! </b></p>";
            else {
                
    $cart unserialize($_SESSION['cart']);
                
    $depth $cart->get_depth();
                echo
    "<h1>Shopping Cart</h1>";
                echo 
    "<table border=1>";
                echo
    "<tr><td><b>Item Name</b></td><td><b>Quantity</b></td><td><b> Price</b></td></tr>";
                for (
    $i=0$i $depth$i++)
                {
                    
    $item $cart->get_item($i);
                    
    $deleted $item->deleted;
                    if (!
    $deleted){
                        
    $item_id $item->get_item_id();
                        
    $item_name $item->get_item_name();
                        
    $qty $item->get_qty();
                        
    $price $item->get_price();
                     
    $total_amount $total_amount +($price*$qty);                    
                        echo
    "<tr><td>$item_name</td><td>$qty </td><td>$price</td></tr>";
                            
                    }        
                }

                echo
    "<tr><td><b> Total </b></td><td>&nbsp;</td><td><b>$total_amount</b></td></tr>";    
                echo 
    "</table>";
                echo
    "<p><b> <a href=view_cart.php>Remove Items from the Cart </a> </b></p>";
                echo
    "<p><b> <a href=products.php>Go back to products </a> </b></p>";
            }
    ?>
    products:
    PHP Code:
    <?php
        session_start
    ();
        
    //connect to server and select database
        
    require_once('conn_video.php');
    ?>
    <html>
    <body>
        <form method="post" action="products.php">
          <table width="699" border="0">
            <tr>
              <td><strong>Title</strong></td>
              <td><strong>Category</strong></td>
              <td><strong>Search</strong></td>
              <td>&nbsp;</td>
            </tr>
            <tr>
              <td width="152"><input name="item_name" type="text" id="item_name"></td>
              <td width="196"><select name="type" size="1" id="type">
                <option selected></option>
                <option value="comedy">Comedy</option>
                <option value="romance">Romance</option>
                <option value="action">Action</option>
                <option value="other">Other</option>
              </select></td>
              <td width="121">
                <div align="left">
                  <input type="submit" name="Submit" value="Search">        
                  </div></td>
              <td width="212"><a href="view_cart.php"><strong>View your Shopping Cart </strong></a></td>
            </tr>
          </table>
        </form>
        <table width="100%"  border="1">
        <tr>
        
        <td><b>Select Item</b> </td>
        <td><b> Item Name </b></td>
        <td><b> Quantity </b></td>
        <td><b> Add to Cart </b></td>
        </tr>
        
          <?php
        
                                  
    //Search products 
    if(isset($_POST['type'], $_POST['item_name'])){
      
    $type $_POST['type'];
      
    $item_name $_POST['item_name'];
      }
        if ((
    $item_name =="") && ($type ==""))
            
    $query "SELECT * FROM products";
        else
            
    $query "SELECT item_id, item_name FROM products WHERE (type = '$type' AND item_name='$item_name')";
        
        
    $result mysql_query ($query) or die ("query 2 failed");
        
                      
    //Display products
                    
    while ($row mysql_fetch_row ($result))
                    {
                      echo 
    "<tr><form  action=add_to_cart.php method=POST>";
                      echo 
    "<td> <input name= item_id type=checkbox id= $row[0] value=$row[0]></td>";
                      echo 
    "<td> $row[1]</td>";
                      echo
    "<td><input name=qty type=text id=qty value=1 size=4 maxlength=2></td>";
                      echo
    "<td><INPUT  name=add TYPE=submit id=add value=Add><td>";
                      echo 
    "</form></tr>";
                      
                     }
         
    ?>   
       </table>
    </body>
    </html>
    remove from cart:

    PHP Code:
    <?php
    session_start
    ();
    include 
    'cart.php';

            
    $item_no=$_POST['item_no'];
            
    //remove item from the cart if selected - mark as deleted
            
    if ($item_no!=""){
                
    $counter $_SESSION['counter'];
                
    $cart = new Cart();
                
    $cart unserialize($_SESSION['cart']);
                
    //delete selected item from the cart
                
    $cart->delete_item($item_no);
                
    //update the counter
                
    $_SESSION['counter'] = $counter-1;
                
    $_SESSION['cart'] = serialize($cart);
                
    header("Location: view_cart.php");
            }
    ?>
    view cart:
    PHP Code:
    <?php
    session_start
    ();
    include 
    'cart.php';

            
    $cart = new Cart();
            
    $counter$_SESSION['counter'];
        
    ?>
    <html>
    </head>

    <body>
    <table width="100%"  border="0">
      
      <tr>
        <td height="244" colspan="4" valign="top">
        <?php
            
    //check whether the cart is empty or not
            
            
            
    if ($counter==0){
                echo
    "<h1>Shopping Cart</h1>";
                echo
    "<br><br><p><b> Your Shopping Cart is empty !!! </b></p>";
                echo
    "<p><b> <a href=products.php>Go back to products </a> </b></p>";
            }
            else {
                
    $cart unserialize($_SESSION['cart']);
                
    //$cart = $_SESSION['cart'];
                
    $depth $cart->get_depth();
                echo
    "<h1>Shopping Cart</h1>";
                echo 
    "<table border=1>";
                echo
    "<tr><td><b>Item Name</b></td><td><b>Quantity</b></td><td><b> Price</b></td></tr>";
                for (
    $i=0$i $depth$i++)
                {
                    
    $item $cart->get_item($i);
                    
    $deleted $item->deleted;
                    
    //display if the item is not marked for deletion
                    
    if (!$deleted){
                        
    $item_id $item->get_item_id();
                        
    $item_name $item->get_item_name();
                        
    $qty $item->get_qty();
                        
    $price $item->get_price();
                        echo 
    "<tr><form  action=remove_from_cart.php method=POST>";
                        echo
    "<td>$item_name</td><td>$qty </td><td>$price</td>";
                        echo 
    "<td> <input name= item_no type=checkbox id= item_no value=$i></td>";
                        echo
    "<td><INPUT  name=remove TYPE=submit id=remove value=Remove><td>";
                        echo 
    "</tr></form>";
                    }
                }
            
                echo 
    "</table>";
                echo
    "<p><b> <a href=checkout.php>Checkout </a> </b></p>";
                echo
    "<p><b> <a href=products.php>Go back to products </a> </b></p>";
            }
        
    ?>
      </tr>
    </table>
    </body>
    </html>
    However, I keep receiving "Undefined variable" errors in the products code on the $type and $item_name although, this time it appears below the variable talked about above.

    Also, in the checkout code I keep getting:

    PHP Code:
    Undefined variabletotal_amount 
    on the line that calculates the total amount of the purchase.
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  37. #37
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629

    Re: [RESOLVED] PHP Validator/Error checking

    uhhh. and? do you not know what that warning means?

    it's saying that you're referencing a variable that has yet to be initialised in your program. the line in question does: "$total_amount = $total_amount + something" -- this line is initialising the variable $total_amount with a value of $total_amount + something. if $total_amount doesn't exist before this point, then PHP will look at the $total_amount variable in the assignment and not be able to find it anywhere. hence the warning.

    you could avoid this by simply declaring/initialising your variables at the beginning of your program's scope, or whenever you're about to use them (generally before loops). set it to a value of 0.

  38. #38

    Thread Starter
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Re: [RESOLVED] PHP Validator/Error checking

    Quote Originally Posted by kows View Post
    uhhh. and? do you not know what that warning means?

    it's saying that you're referencing a variable that has yet to be initialised in your program. the line in question does: "$total_amount = $total_amount + something" -- this line is initialising the variable $total_amount with a value of $total_amount + something. if $total_amount doesn't exist before this point, then PHP will look at the $total_amount variable in the assignment and not be able to find it anywhere. hence the warning.

    you could avoid this by simply declaring/initialising your variables at the beginning of your program's scope, or whenever you're about to use them (generally before loops). set it to a value of 0.
    Yes, I realize that but if I put something like:

    PHP Code:
    $total_amount = ($price*$qty); 
    The calculation does add up correctly.

    or

    put:

    PHP Code:
    var $total_amount
    at the top I get:

    Parse error: parse error in checkout.php on line 2
    Edit:

    Apart from the errors appearing on screen the whole thing is working as it is suppose to.
    Last edited by Nightwalker83; Oct 28th, 2009 at 02:26 AM. Reason: Adding more!
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  39. #39
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: [RESOLVED] PHP Validator/Error checking

    All variables are declared implicitly. So simply write a value to the variable to initialize it:
    PHP Code:
    $totalAmount 0
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  40. #40

    Thread Starter
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Re: [RESOLVED] PHP Validator/Error checking

    Quote Originally Posted by visualAd View Post
    All variables are declared implicitly. So simply write a value to the variable to initialize it:
    PHP Code:
    $totalAmount 0
    I have set it like so:

    PHP Code:
    $totalAmount 0
    $total_amount =  $total_amount +($price*$qty); 
    Although, I still get the above message on the second line, I think it has to do with the second "$total_amount" rather than the first.

    Edit:

    If I put:

    PHP Code:
    $total_amount =  ($price*$qty); 
    instead of

    PHP Code:
    $total_amount =  $total_amount +($price*$qty); 
    The message no longer appears. However the calculation doesn't calculation the values correctly if I use the first line of code.
    Last edited by Nightwalker83; Oct 28th, 2009 at 03:35 AM. Reason: Adding more!
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

Page 1 of 2 12 LastLast

Posting Permissions

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



Click Here to Expand Forum to Full Width