943,177 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Marked Solved
  • Views: 333
  • PHP RSS
You are currently viewing page 1 of this multi-page discussion thread
Sep 2nd, 2010
0

PHP dynamic web site using form database?

Expand Post »
Hello fellow code heads!
I have issues (or so my wife says) but mine stem from the wonderful world of PHP. My web design knowledge is largely based on XHTML and that's where I left the scene. I was recently asked to delve back into the world of web design (something I haven't done in more than a decade and a half) but it was requested that the resulting code was in PHP...and so my learning odyssey began. But I digress...
I was asked to include a form for this site in question. This form is to (as far as I have been able to figure out on my own), on submission, write to a database. In turn, another page on the site would update from this database to display values from the form fields in a specific order. The form has other dynamic qualities such as drop-down selection menus that update in succession: Select Country→Select State/Province/Region(based on country selected)→Select City (based on State/Province/Region selected)...you get the picture, but that is yet another query.
I know this may sound like a fairly simple task for some but you will remember I am a squeaky clean virgin to PHP and while I am pretty quick on the uptake and I'm learning PHP at a phenominal rate, I just can't figure out how to properly code this so it works properly and the code is clean (I'm also a neat-freak). I desperately need help with the coding, syntax, stress reduction...
Any help given would be greatly appreciated, if only pointing me in the right direction to learn how to do this. THANKS IN ADVANCE!

P.S. I'm using PHP and mysql in Dreamweaver CS5 (if you're going to get back in, get back in big). Limited javascript knowledge and no AJAX knowledge to speak of.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
HedoBum is offline Offline
15 posts
since Sep 2010
Sep 2nd, 2010
0
Re: PHP dynamic web site using form database?
Click to Expand / Collapse  Quote originally posted by HedoBum ...
Hello fellow code heads!
I have issues (or so my wife says) but mine stem from the wonderful world of PHP. My web design knowledge is largely based on XHTML and that's where I left the scene. I was recently asked to delve back into the world of web design (something I haven't done in more than a decade and a half) but it was requested that the resulting code was in PHP...and so my learning odyssey began. But I digress...
I was asked to include a form for this site in question. This form is to (as far as I have been able to figure out on my own), on submission, write to a database. In turn, another page on the site would update from this database to display values from the form fields in a specific order. The form has other dynamic qualities such as drop-down selection menus that update in succession: Select Country→Select State/Province/Region(based on country selected)→Select City (based on State/Province/Region selected)...you get the picture, but that is yet another query.
I know this may sound like a fairly simple task for some but you will remember I am a squeaky clean virgin to PHP and while I am pretty quick on the uptake and I'm learning PHP at a phenominal rate, I just can't figure out how to properly code this so it works properly and the code is clean (I'm also a neat-freak). I desperately need help with the coding, syntax, stress reduction...
Any help given would be greatly appreciated, if only pointing me in the right direction to learn how to do this. THANKS IN ADVANCE!

P.S. I'm using PHP and mysql in Dreamweaver CS5 (if you're going to get back in, get back in big). Limited javascript knowledge and no AJAX knowledge to speak of.
hi there hedubom!

there are lots of good and best programmers here in daniweb.
i hope this one helps.

PHP Syntax (Toggle Plain Text)
  1. <html>
  2. <body>
  3. <!-- sample body -->
  4.  
  5. <?php
  6. // sample connection string for your database access
  7.  
  8. $hostname = "localhost";
  9. $database = "sample_country_database";
  10. $username = "root";
  11. $password = "samplepassword";
  12.  
  13. mysql_connect($hostname,$username,$password);
  14. mysql_select_db($database) or die("Unable to select database.");
  15. ?>
  16.  
  17. <!-- select field and query -->
  18.  
  19. <form method="post">
  20. <br>
  21. <select name="thecountryname" width = "200">
  22. <option value=''> Country Names </option>
  23.  
  24. <!-- sample country names display -->
  25.  
  26. <?php
  27. $myquery=mysql_query("SELECT DISTINCT sample_country_name
  28. from sample_country_table
  29. ");
  30.  
  31. if(mysql_fetch_object($myquery) == null)
  32. {
  33. echo "<option value=''> No Record Found. </option>";
  34. }
  35.  
  36. else
  37. {
  38.  
  39. $myquery=mysql_query("SELECT DISTINCT sample_country_name
  40. from sample_country_table
  41. ");
  42.  
  43. while($countryname=mysql_fetch_object($myquery))
  44. {
  45. echo "<option value='$countryname->sample_country_name'>".$countryname->sample_country_name."</option>";
  46. }
  47. }
  48. ?>
  49.  
  50. </select>
  51.  
  52. <input type="submit" name="view" value=" View ">
  53. </form>
  54.  
  55. <?php
  56. if($_POST['view'])
  57. {
  58. $counname = $_POST['thecountryname'];
  59.  
  60. if($counname == null)
  61. {
  62. echo "<script type='text/javascript'>window.alert('Please check your input.')</script>";
  63. //echo "<META http-equiv='refresh' content='0; URL=index.php'>";
  64. }
  65.  
  66. else if($counname != null)
  67. {
  68.  
  69. $myquery=mysql_query("SELECT * from sample_coutry_table");
  70.  
  71. if(mysql_fetch_object($myquery) == null)
  72. {
  73. echo "<center>No Record Found.</center>"; // ---> this is if the sample_country_table have no values
  74. }
  75.  
  76. else
  77. {
  78. $myquery=mysql_query("SELECT DISTINCT sample_coutry_name
  79. from sample_country_table
  80. where sample_coutry_name = '$counname'
  81. ");
  82.  
  83. while($x=mysql_fetch_object($myquery))
  84. {
  85. echo " <center> ";
  86. echo " <font color = 'red'>Coutry Name : </font>".$x->sample_coutry_name;
  87. }
  88.  
  89. echo "
  90. <br>
  91. <center>
  92. <table class = sample align=center width=1350px height = 50>
  93. <tr bgcolor = '#82CAFA'>
  94. <td width='50' align = 'center'> - </center></td>
  95. <td width='250' align = 'center'>COUTRY NAME</center></td>
  96. <td width='50'><center>COUNTRY DETAIL 1</center></td> <!-- sample details from here -->
  97. <td width='50'><center>COUNTRY DETAIL 2</center></td>
  98. <td width='50'><center>COUNTRY DETAIL 3</center></td>
  99. </tr><tr></tr>";
  100.  
  101. $myquery=mysql_query("SELECT sample_country_name, detail1, detail2, detail3
  102. from sample_coutry_table
  103. where sample_country_name like '$counname'
  104. order by sample_country_name");
  105.  
  106. $check=0;
  107. while($y=mysql_fetch_object($myquery))
  108. {
  109.  
  110. $check++;
  111.  
  112. //---- country name ----
  113. echo "<tr>";
  114. echo "<td align = right width='50'>$check</td>";
  115. echo "<td width='250' align = left>".$y->sample_country_name."</td>";
  116.  
  117. if ($y->detail1 == 0 || $y->detail1 == null) // ---> sample details and column names from here
  118. {
  119. echo "<td width='50' align = center><font color = red>"." - "."</font></td>";
  120. }
  121. else
  122. {
  123. echo "<td width='50' align = center>".$y->detail1."</td>";
  124. }
  125. if ($y->detail2 == 0 || $y->detail2 == null)
  126. {
  127. echo "<td width='50' align = center>"." - "."</td>";
  128. }
  129. else
  130. {
  131. echo "<td width='50' align = center>".$y->detail2."</td>";
  132. }
  133. if ($y->detail3 == 0 || $y->detail3== null)
  134. {
  135. echo "<td width='50' align = center>"." - "."</td>";
  136. }
  137. else
  138. {
  139. echo "<td width='50' align = center>".$y->detail3."</td>";
  140. }
  141.  
  142. echo "</tr>";
  143. }
  144.  
  145. echo "<tr></tr><tr></tr>";
  146. echo "</table></center><br>";
  147.  
  148. echo " <br>";
  149. }
  150.  
  151. }
  152.  
  153. else
  154. {
  155. echo "<center>No Record Found.</center>";
  156. }
  157. }
  158.  
  159. else
  160. {
  161. echo "<center>No Record Found.</center>";
  162. }
  163.  
  164. ?>
  165.  
  166. </body>
  167. </html>

happy day ahead! ~_^
Reputation Points: 10
Solved Threads: 13
Junior Poster
ﻼim is offline Offline
171 posts
since Aug 2010
Sep 4th, 2010
0
Re: PHP dynamic web site using form database?
WoW...thank you very much ﻼim!
I didn't expect to see a reply so quickly with a page full of code to boot,...and commented no less.
I should have been checking more diligently but I thought I would be automatically emailed when someone answered. I should have checked my settings.
Thank you again ﻼim and I'll try this code to see how it works.

I'll have to get my hands on a proper database to use with it...it's surprising how difficult it is to find a simple sql database with just Country/State/Province/Region in one place. But that's another query.

Thank you once again.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
HedoBum is offline Offline
15 posts
since Sep 2010
Sep 5th, 2010
0
Re: PHP dynamic web site using form database?
*sigh*...I am such a newb
I can't get this code to work for me. I have a database for this but I don't think I'm getting the syntax right or something. I have the database set up...I get a connection with DW but I don't think I implemented it into this code properly or something because in LiveView I just get a blank page with "Unable to select database" at the top. Maybe there needed to be commenting geared for Über-newb because I can't for the life of me figure where I went wrong. Someone figure this out for a database called country.php?

edit: ...and a database table of countries?
Last edited by HedoBum; Sep 5th, 2010 at 4:57 am. Reason: additional info
Reputation Points: 10
Solved Threads: 0
Newbie Poster
HedoBum is offline Offline
15 posts
since Sep 2010
Sep 5th, 2010
0
Re: PHP dynamic web site using form database?
Karibu Daniweb (Welcome to Daniweb)
Since your odyssey is just starting and taking account of your background, PHP code won't make much sense if any at all. I advice you do crash course with PHP and MySQL. you have two "colleges" to learn that. Either Tizag or w3School. After that, you will see how easy that task is becoming
Reputation Points: 462
Solved Threads: 392
Senior Poster
evstevemd is offline Offline
3,681 posts
since Jun 2007
Sep 5th, 2010
0
Re: PHP dynamic web site using form database?
Click to Expand / Collapse  Quote originally posted by HedoBum ...
*sigh*...I am such a newb
I can't get this code to work for me. I have a database for this but I don't think I'm getting the syntax right or something. I have the database set up...I get a connection with DW but I don't think I implemented it into this code properly or something because in LiveView I just get a blank page with "Unable to select database" at the top. Maybe there needed to be commenting geared for Über-newb because I can't for the life of me figure where I went wrong. Someone figure this out for a database called country.php?

edit: ...and a database table of countries?
yeah. i'll suggest that you take the former's advice. ~_^

at the start it may seem complicated but later as you go on with practice and trials you'll see, it's not that difficult.
Reputation Points: 10
Solved Threads: 13
Junior Poster
ﻼim is offline Offline
171 posts
since Aug 2010
Sep 6th, 2010
0
Re: PHP dynamic web site using form database?
I use Uniform Server as a development platform for all my web design. It's light weight and copies how a real server would run. It's perfect for development... and it comes with PMA (PHPMyAdmin).

[Links]
http://www.uniformserver.com/
Reputation Points: 23
Solved Threads: 21
Junior Poster in Training
Nyight is offline Offline
99 posts
since Aug 2010
Sep 6th, 2010
0
Re: PHP dynamic web site using form database?
Click to Expand / Collapse  Quote originally posted by evstevemd ...
Karibu Daniweb (Welcome to Daniweb)
Since your odyssey is just starting and taking account of your background, PHP code won't make much sense if any at all. I advice you do crash course with PHP and MySQL. you have two "colleges" to learn that. Either Tizag or w3School. After that, you will see how easy that task is becoming
Good advice...I'm using W3Schools now. W3Schools is invaluable for information on pretty much anything web related and I reference it regularly (usually).
I am an impatient type and I want to know how to do things now. Needless to say, I learn on an exponential curve.
Thanks for the replies all.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
HedoBum is offline Offline
15 posts
since Sep 2010
Sep 10th, 2010
0
Re: PHP dynamic web site using form database?
If you face specific problem in your learning just file a thread. I think you should close this for now, if you think "all is over" about this thread
Reputation Points: 462
Solved Threads: 392
Senior Poster
evstevemd is offline Offline
3,681 posts
since Jun 2007
Sep 11th, 2010
0
Re: PHP dynamic web site using form database?
ﻼim...I think I understand your code now...well in a cursory way. I just went through it again and now that I have a bit better than a "tourists vocabulary" of PHP, it looks clearer to me. I'm not quite fluent yet but I'm getting there.
Thanks again for the help.


@evstevemd: Thanks for the heads-up...I failed to remember this forum was on the open help system.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
HedoBum is offline Offline
15 posts
since Sep 2010

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: AutoSuggest textbox
Next Thread in PHP Forum Timeline: Submit form and send a mail





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC