if/else statement giving errors

Discussion in 'Web Design and Development' started by captainmeowtron, Aug 12, 2009.

  1. captainmeowtron macrumors member

    Dec 1, 2008
    My code is giving me unexpected t variable errors around line 42, which is the if part of the statement. What am I doing wrong? :(
    if($_POST['Title'] != "")
      $title_In = cleanvalue($_POST['Title']);
      $serialnum_In = cleanvalue($_POST['SerialNum']);
      $ImageURL_In = cleanvalue($_POST['ImageURL']);
      if (is_numeric($_POST['Price']))
        $price_In = $_POST['Price'];
      if (is_numeric($_POST['Shipping1']))
        $shipping1_In = $_POST['Shipping1'];
      if (is_numeric($_POST['Shipping2']))
        $shipping2_In = $_POST['Shipping2'];
      if ($Type_In=='blood orange')
  2. angelwatt Moderator emeritus


    Aug 16, 2005
    Sometimes the error is before the line number they give, that's just when it notices there is an issue. Not sure if line 42 was the first line you posted or not.
  3. Darth.Titan macrumors 68030


    Oct 31, 2007
    Austin, TX
    T_VARIABLE errors usually are caused by errors directly before the given line number.

    Look for a missing ';' or unclosed set of parentheses before line 42. The code you've posted looks fine.
  4. m3kilpat macrumors regular

    Jul 6, 2009
    The only thing that I see is that blood orange may need double quotes around it and not single quotes.
  5. captainmeowtron thread starter macrumors member

    Dec 1, 2008
    Thanks for all the help. I'm looking through it for some unclosed parentheses or anything like that. I didn't post the entire thing, figuring nobody wanted to scroll through pages of code.
  6. SrWebDeveloper macrumors 68000


    Dec 7, 2007
    Alexandria, VA, USA

    Based on the incomplete code you posted there are no syntax errors in the block of text - not that I mean you could run code as posted and it'll work, of course.

    Do not be put off by any negative replies about debugging, etc and the single vs. double quote which is fine for a string with no variables embedded. Yes, your code has some minor issues, but as to your question:

    It's just hard for us to help you when you do what you did (posting incomplete code based on a specific reference to a specific line number) - that's the only part which prevents us from helping you.

    Please post all code.

  7. Joined:
    Jun 30, 2009
    Get yourself a real text editor. Try TextWrangler. It is free and powerful enough. This way, you will have line numbering.

    When you get an error message, check the line first and the code around it/related to it. Check it for errors. If you don't manage to do it yourself, even after trying a lot, ask for help on a forum, but in a decent manner. That is, post all the code you've got between <?php ?>.
  8. captainmeowtron thread starter macrumors member

    Dec 1, 2008
    I got Text Wrangler and it is helping me immensely. I selected "zap gremlins" and it deleted that extra curly brace (wherever it was). Now I am trying to redirect a parent window from a child window and then close the child window. It sounds simple, but after hours of googling and trying different things, I can't get it working. Here's what I've got (the entire page this time :D)
    I want to submit the item to the shopping cart, open the shopping cart in the parent window, and close the popup. This is the popup. The parent window is not the shopping cart, but a catalog page.
    <STYLE type="text/css">
    A { text-decoration:none }
    <body bgcolor="#000000" TEXT="000000" body link="#000000" vlink="#000000" alink="#000000">
    <table border="0" bordercolor="" style="background-color:#000000" width="100%" cellpadding="" cellspacing="">
    <td><img src="1.jpg"></td>
    <td> </td>
    <form method="post" action="ShoppingCart.php">
    Item Title: <strong><font color="E3E5CD">cool spiral pendant</font></strong><br />
    <font color="E3E5CD">Frosty turquoise glass wrapped in a steel spiral. 1.75 inches.</font><br />
    <br />
    Item Price: <strong><font color="E3E5CD">$30.00</font></strong><br />
    Item Shipping: <strong>$5.00</strong><br />
    Item Additional Shipping: <strong>$0.00</strong><br />
    <input name="Title" type="hidden" value="cool spiral pendant" />
    <input name="Price" type="hidden" value="30.00" />
    <input name="Shipping1" type="hidden" value="0.00" />
    <input name="Shipping2" type="hidden" value="0.00" />
    <input name="cmd" type="hidden" id="cmd" value="1" />
    <input type="submit" name="Submit" value="Add To Cart" / >
    <script type="text/javascript" language="javascript">
  9. Cerebrus' Maw macrumors 6502

    Mar 9, 2008
    Brisbane, Australia
    You have not attached the javascript to the submission of your form.

    <form method="post" action="your.php" onSubmit="javaScriptFunction();" >
  10. angelwatt Moderator emeritus


    Aug 16, 2005
    The code,
    doesn't actually mean anything.

    Assigning some actions to onunload would occur when the user moves to another page. You have an action to close the window, but by the time onunload is running, that window is likely being closed.

    If you need the parent window to go to a different URL you would have something like,
    window.opener.location.href="some URL here";
    You can have at the end of your ShoppingCart.php script a piece of JavaScript that closes the window. You can also submit the form using JavaScript since it looks you're forcing the users to have JavaScript enabled.

    (You form would need a name attribute for this, or an id attribute and use the getElementById function.)

    Here's one small discussion on this.
  11. captainmeowtron thread starter macrumors member

    Dec 1, 2008
    I think I may have figured it out. Looks like it's
    <form method="post" action="ShoppingCart.php" onsubmit="opener.location='ShoppingCart.php';self.close()">
    <input type="submit" name="Submit" value="Add To Cart" / >
    It seems to be working so far. I'll be back if something goes awry.

Share This Page