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.
<html>
<body>
<!-- sample body -->
<?php
// sample connection string for your database access
$hostname = "localhost";
$database = "sample_country_database";
$username = "root";
$password = "samplepassword";
mysql_connect($hostname,$username,$password);
mysql_select_db($database) or die("Unable to select database.");
?>
<!-- select field and query -->
<form method="post">
<select name="thecountryname" width = "200">
<option value=''> Country Names </option>
<!-- sample country names display -->
<?php
$myquery=mysql_query("SELECT DISTINCT sample_country_name
from sample_country_table
");
if(mysql_fetch_object($myquery) == null)
{
echo "<option value=''> No Record Found. </option>";
}
else
{
$myquery=mysql_query("SELECT DISTINCT sample_country_name
from sample_country_table
");
while($countryname=mysql_fetch_object($myquery))
{
echo "<option value='$countryname->sample_country_name'>".$countryname->sample_country_name."</option>";
}
}
?>
</select>
<input type="submit" name="view" value=" View ">
</form>
<?php
if($_POST['view'])
{
$counname = $_POST['thecountryname'];
if($counname == null)
{
echo "<script type='text/javascript'>window.alert('Please check your input.')</script>";
//echo "<META http-equiv='refresh' content='0; URL=index.php'>";
}
else if($counname != null)
{
$myquery=mysql_query("SELECT * from sample_coutry_table");
if(mysql_fetch_object($myquery) == null)
{
echo "<center>No Record Found.</center>"; // ---> this is if the sample_country_table have no values
}
else
{
$myquery=mysql_query("SELECT DISTINCT sample_coutry_name
from sample_country_table
where sample_coutry_name = '$counname'
");
while($x=mysql_fetch_object($myquery))
{
echo " <center> ";
echo " <font color = 'red'>Coutry Name : </font>".$x->sample_coutry_name;
}
echo "
<center>
<table class = sample align=center width=1350px height = 50>
<tr bgcolor = '#82CAFA'>
<td width='50' align = 'center'> - </center></td>
<td width='250' align = 'center'>COUTRY NAME</center></td>
<td width='50'><center>COUNTRY DETAIL 1</center></td> <!-- sample details from here -->
<td width='50'><center>COUNTRY DETAIL 2</center></td>
<td width='50'><center>COUNTRY DETAIL 3</center></td>
</tr><tr></tr>";
$myquery=mysql_query("SELECT sample_country_name, detail1, detail2, detail3
from sample_coutry_table
where sample_country_name like '$counname'
order by sample_country_name");
$check=0;
while($y=mysql_fetch_object($myquery))
{
$check++;
//---- country name ----
echo "<tr>";
echo "<td align = right width='50'>$check</td>";
echo "<td width='250' align = left>".$y->sample_country_name."</td>";
if ($y->detail1 == 0 || $y->detail1 == null) // ---> sample details and column names from here
{
echo "<td width='50' align = center><font color = red>"." - "."</font></td>";
}
else
{
echo "<td width='50' align = center>".$y->detail1."</td>";
}
if ($y->detail2 == 0 || $y->detail2 == null)
{
echo "<td width='50' align = center>"." - "."</td>";
}
else
{
echo "<td width='50' align = center>".$y->detail2."</td>";
}
if ($y->detail3 == 0 || $y->detail3== null)
{
echo "<td width='50' align = center>"." - "."</td>";
}
else
{
echo "<td width='50' align = center>".$y->detail3."</td>";
}
echo "</tr>";
}
echo "<tr></tr><tr></tr>";
echo "</table></center>";
echo " ";
}
}
else
{
echo "<center>No Record Found.</center>";
}
}
else
{
echo "<center>No Record Found.</center>";
}
?>
</body>
</html>
happy day ahead! ~_^