473,395 Members | 1,442 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Code produces blank page

29
This is my code

Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <title>Untitled Document</title>
  6. </head>
  7.  
  8. <body>
  9. <?php 
  10.  
  11. if (isSet($_POST['name']))
  12. {
  13. $name=$_POST['name'];
  14. }
  15. if (isSet($_POST['age']))
  16. {
  17. $age=$_POST['age'];
  18. }
  19. if (isSet($_POST['phone']))
  20. {
  21. $phone=$_POST['phone'];
  22. }
  23. if (isSet($_POST['school']))
  24. {
  25. $school=$_POST['school'];
  26. }
  27.  
  28. $connection =mysql_connect("localhost", "root", "") or die ("Could not connect to Mysql");
  29. $selection = mysql_select_db('second') or die ("Unable select database");
  30.  
  31. $sql= mysql_query("INSERT INTO try1, try2 VALUES (name.age),(phone, school)");
  32. ?>
  33.  
  34. <?php 
  35. $sql = mysql_query("SELECT * FROM try1"); 
  36. $sql1 = mysql_query("SELECT * FROM try2"); 
  37. $result = mysql_fetch_array($sql); 
  38. $result = mysql_fetch_array($sql1); 
  39. while($result==0) { 
  40.    print $result['$name'].$result['$age'].$result['$phone'].$result['$school'].'<br/>'; 
  41. ?>
  42.  
  43. </body>
  44. </html>
  45.  
after run, but why is in blank page
Jul 27 '09 #1
18 2683
bilibytes
128 100+
because you have not turned error reporting on, and your code contains errors, such as
Expand|Select|Wrap|Line Numbers
  1. isSet()
which should be written
Expand|Select|Wrap|Line Numbers
  1. isset()
lowercased.

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

regards
Jul 27 '09 #2
Canabeez
126 100+
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:
Expand|Select|Wrap|Line Numbers
  1. if (isset($_POST['name']))
  2. {
  3.    $name=$_POST['name'];
  4. }
You could just:
Expand|Select|Wrap|Line Numbers
  1. $name = isset($_POST['name']) ? $_POST['name'] : false;
Jul 28 '09 #3
code green
1,726 Expert 1GB
This is rather a strange observation
And the last thing, there's no point in:
Expand|Select|Wrap|Line Numbers
  1. if (isset($_POST['name'])) 
  2.    $name=$_POST['name']; 
You could just:
Expand|Select|Wrap|Line Numbers
  1. $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
Jul 28 '09 #4
Dheeraj Joshi
1,123 Expert 1GB
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.?
Jul 29 '09 #5
Canabeez
126 100+
@code green
As you said, I was giving a tip, and showing a person an alternative way, I usually prefer to use... :)
Jul 29 '09 #6
dreamy
29
Dear, thz a lot, i ll try to fix it up.
Jul 29 '09 #7
dreamy
29
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?
Jul 29 '09 #8
Dheeraj Joshi
1,123 Expert 1GB
I generally use like this

Expand|Select|Wrap|Line Numbers
  1. $name = $_POST["name"]
  2.  
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.
Jul 29 '09 #9
code green
1,726 Expert 1GB
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),(phone, school) will also not work
Jul 29 '09 #10
dreamy
29
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
Jul 29 '09 #11
Dheeraj Joshi
1,123 Expert 1GB
It's text filed name.

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

$name = $_POST["myname"];
Jul 29 '09 #12
Canabeez
126 100+
Can't see any syntax error, check out the quotes, that must be it...
Jul 29 '09 #13
dreamy
29
ok, i try to change my text name.
['name'] exact same wif my text file name.
thz ya, dheerajjoshim
Jul 29 '09 #14
Dheeraj Joshi
1,123 Expert 1GB
That will not be a problem.


Your file name can be same.
Jul 29 '09 #15
dreamy
29
ok, but how ro solve tat
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 u help me? thz
Jul 29 '09 #16
Canabeez
126 100+
I think you're sending the $Link instead of the $Query...
Jul 29 '09 #17
dreamy
29
mean?
sending $Link instead of the $Query?

can tell me more? thz Canabeez.
Jul 30 '09 #18
Dormilich
8,658 Expert Mod 8TB
Expand|Select|Wrap|Line Numbers
  1. typeof $Link  --> "resource"
  2. typeof $Query --> "string"
Jul 30 '09 #19

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Rv5 | last post by:
I have an assignment due mid next week that I have completed. I was hoping someone could take a look at the code and tell me what they think of the style. Id like to know if this is good code...
14
by: charlie_M | last post by:
Is there a way to blank the screen in a FORM's onsubmit=... to blank the screen for the user?? I asked this before and got a way to blank a table by id with ...
6
by: Melissa | last post by:
Does anyone have a generic procedure for adding blank lines to reports like Sales details, PO details and/or Orders details. The procedure would need to count the number of line items, determine...
4
by: Nhmiller | last post by:
Access seems to always generate a second page, which is blank, to my one page report. How do I delete the second page? Thanks. Neil Cat Paintings At Carol Wilson Gallery...
6
by: noway | last post by:
I have greated a report and have included a page break in it. The report breaks were it is supposed to but then it creates a blank page between the two pages. Since this report will print out...
1
by: bennett | last post by:
At http://www.brainjammer.com/testing/validator_test.aspx I have a text field where you can enter text, and a button where if you click the button, it sets the value of a label below it, to...
3
by: Wayne | last post by:
I have a report containing 2 subreports. The subreports each contain a chart. The whole thing easily fits on one page but a second blank page is consistently being generated. This has nothing...
1
by: siomay87 | last post by:
please help i have a problem in the ms access reporting, my report have: page header, detail, page footer and report footer In listing "detail section", the number of line is depend on the data...
4
by: sid | last post by:
"about:blank" oepns new browser window I am writing a webpage that will run on other machines that I may or may not know about. My page is framed where frame1 controls the content of frame2. ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.