Code produces blank page

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dreamy
    New Member
    • Jul 2009
    • 29

    Code produces blank page

    This is my code

    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">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
    </head>
    
    <body>
    <?php 
    
    if (isSet($_POST['name']))
    {
    $name=$_POST['name'];
    }
    if (isSet($_POST['age']))
    {
    $age=$_POST['age'];
    }
    if (isSet($_POST['phone']))
    {
    $phone=$_POST['phone'];
    }
    if (isSet($_POST['school']))
    {
    $school=$_POST['school'];
    }
    
    $connection =mysql_connect("localhost", "root", "") or die ("Could not connect to Mysql");
    $selection = mysql_select_db('second') or die ("Unable select database");
    
    $sql= mysql_query("INSERT INTO try1, try2 VALUES (name.age),(phone, school)");
    ?>
    
    <?php 
    $sql = mysql_query("SELECT * FROM try1"); 
    $sql1 = mysql_query("SELECT * FROM try2"); 
    $result = mysql_fetch_array($sql); 
    $result = mysql_fetch_array($sql1); 
    while($result==0) { 
       print $result['$name'].$result['$age'].$result['$phone'].$result['$school'].'<br/>'; 
    } 
    ?>
    
    </body>
    </html>
    after run, but why is in blank page
    Last edited by Banfa; Jul 27 '09, 02:38 PM. Reason: Added [code] ... [/code] tags
  • bilibytes
    New Member
    • Jun 2008
    • 128

    #2
    because you have not turned error reporting on, and your code contains errors, such as
    Code:
    isSet()
    which should be written
    Code:
    isset()
    lowercased.

    As mark suggested you in a previous post, read the posting guidelines of the forum.

    regards

    Comment

    • Canabeez
      New Member
      • Jul 2009
      • 126

      #3
      In addition to bilibytes,

      you should add link to functions like mysql_query() or mysql_select_db () (for example mysql_select_db ('second', $connection);. Plus.. there's no reason to INSERT something to the database and then select it from there, you could just check if the INSERT went good or not, and then use the same variables... more then that, look at lines 37 and 38, if you run the 38, then then the 37 has no point because you're using the same variable name ($result), you just get something from the database and then override it with something else.

      And the last thing, there's no point in:
      [code=php]
      if (isset($_POST['name']))
      {
      $name=$_POST['name'];
      }[/code]
      You could just:
      [code=php]
      $name = isset($_POST['name']) ? $_POST['name'] : false;[/code]

      Comment

      • code green
        Recognized Expert Top Contributor
        • Mar 2007
        • 1726

        #4
        This is rather a strange observation
        And the last thing, there's no point in:
        Code:
        if (isset($_POST['name'])) 
        { 
           $name=$_POST['name']; 
        }
        You could just:
        Code:
        $name = isset($_POST['name']) ? $_POST['name'] : false;
        I know you are giving a tip but this more of a preference than an improvement.
        Besides $name is handled differently if $_POST['name'] does not exist

        Comment

        • Dheeraj Joshi
          Recognized Expert Top Contributor
          • Jul 2009
          • 1129

          #5
          Most languages execution speed improve by using ? operators.(For checking)

          So i observer this by giving multiple if's and replaced it by ? operator.

          Thats the only advantage i think.

          Is it same case in php... I never tried it in php.?

          Comment

          • Canabeez
            New Member
            • Jul 2009
            • 126

            #6
            Originally posted by code green
            This is rather a strange observation
            I know you are giving a tip but this more of a preference than an improvement.
            Besides $name is handled differently if $_POST['name'] does not exist
            As you said, I was giving a tip, and showing a person an alternative way, I usually prefer to use... :)

            Comment

            • dreamy
              New Member
              • Jul 2009
              • 29

              #7
              Dear, thz a lot, i ll try to fix it up.

              Comment

              • dreamy
                New Member
                • Jul 2009
                • 29

                #8
                Dear Canabeez

                if i follow ur way to put as
                $name = isset($_POST['name']) ? $_POST['name'] : false;

                but it will come out an error Parse error: parse error, expecting `','' or `')''

                so?

                Comment

                • Dheeraj Joshi
                  Recognized Expert Top Contributor
                  • Jul 2009
                  • 1129

                  #9
                  I generally use like this

                  Code:
                  $name = $_POST["name"]
                  So name is enclosed in the double quotes rather than single quotes.

                  Above code is working fine.

                  You replace your single quotes by double quotes and try.

                  Comment

                  • code green
                    Recognized Expert Top Contributor
                    • Mar 2007
                    • 1726

                    #10
                    I just don't think the ternary operator is good practice for a newbie.
                    The syntax is not as clear as if....else.
                    As for the performance, all benchmark tests I have seen produce miniscule differences.

                    Back to the problem. Your ternary syntax is correct dreamy.
                    The problem is elsewhere ie. isSet instead of isset.
                    But I suspect you have a missing bracket.
                    Your VALUES (name.age),(pho ne, school) will also not work

                    Comment

                    • dreamy
                      New Member
                      • Jul 2009
                      • 29

                      #11
                      Dear, dheerajjoshim
                      if i put $name=$_POST ['name'];
                      and i hv try this before, but it will get the error of undefined index.
                      can i know why and ['name'] is the text name, rite?

                      And Dear code green,
                      i aldy change the isSet ti isset.
                      and, u hv suspect i hv missing bracket, can gv me the tips?

                      The last,
                      beside the undefined text error, i also hv
                      You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Resource id #3' at line 1
                      can i know how to solve it.
                      thz.

                      very thx both of u

                      Comment

                      • Dheeraj Joshi
                        Recognized Expert Top Contributor
                        • Jul 2009
                        • 1129

                        #12
                        It's text filed name.

                        <input type="text" name="myname">

                        $name = $_POST["myname"];

                        Comment

                        • Canabeez
                          New Member
                          • Jul 2009
                          • 126

                          #13
                          Can't see any syntax error, check out the quotes, that must be it...

                          Comment

                          • dreamy
                            New Member
                            • Jul 2009
                            • 29

                            #14
                            ok, i try to change my text name.
                            ['name'] exact same wif my text file name.
                            thz ya, dheerajjoshim

                            Comment

                            • Dheeraj Joshi
                              Recognized Expert Top Contributor
                              • Jul 2009
                              • 1129

                              #15
                              That will not be a problem.


                              Your file name can be same.

                              Comment

                              Working...