Jump to content

ronaldb103

New Members
  • Posts

    5
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

ronaldb103's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. I have a MYsql database of burial records and when you search for the person it returns Name, block and plot where buried and date of birth and death. For some of the records there is no date for either the birth or death in those cases I would like it to show "Unknown" in the field. Any suggestions on how this would work where if the results for the field are empty it echos Unknown. Tried a few different things but can't seem to figure it out. Here is the code that was created with the help of the people here: <?php include("admin.php"); $error_msg = ''; $fname = ''; $lname = ''; if (isset($_POST['first']) || isset($_POST['last'])) { //User submitted a search query $fname = trim($_POST['first']); $lname = trim($_POST['last']); if(empty($lname)) { //No last name entered $validationError = "Please enter a last name"; } else { //Perform the database search mysql_connect("antondad.db.4161444.hostedresource.com", $username, $password); @mysql_select_db($database) or die( "Unable to select database"); $sql_fname = mysql_real_escape_string($fname); $sql_lname = mysql_real_escape_string($lname); $query="SELECT block, plot, first, last, birth, death FROM burial_records WHERE last LIKE '{$sql_lname}' AND first LIKE '%{$sql_fname}%'"; if ($last == "") $result=mysql_query($query); if(!$result) { $error_msg = "Database error occured."; } elseif(mysql_num_rows($result)==0) { $error_msg = "Sorry, no results found."; } else { $headResults .= " <th><font face=\"Arial, Helvetica,bold, sans-serif\">Block</font></th>\n"; $headResults .= " <th><font face=\"Arial, Helvetica, sans-serif\">Plot</font></th>\n"; $headResults .= " <th><font face=\"Arial, Helvetica, sans-serif\">First Name</font></th\n>"; $headResults .= " <th><font face=\"Arial, Helvetica, sans-serif\">Last Name</font></th>\n"; $headResults .= " <th><font face=\"Arial, Helvetica, sans-serif\">Born</font></th>\n"; $headResults .= " <th><font face=\"Arial, Helvetica, sans-serif\">Died</font></th>\n"; $recordResults = ''; while ($record = mysql_fetch_assoc($result)) { $recordResults .= " <tr>\n"; $recordResults .= " <td><font face=\"Arial, Helvetica, sans-serif\">{$record['block']}</font></td>\n"; $recordResults .= " <td><font face=\"Arial, Helvetica, sans-serif\">{$record['plot']}</font></td>\n"; $recordResults .= " <td><font face=\"Arial, Helvetica, sans-serif\">{$record['first']}</font></td>\n"; $recordResults .= " <td><font face=\"Arial, Helvetica, sans-serif\">{$record['last']}</font></td>\n"; $recordResults .= " <td><font face=\"Arial, Helvetica, sans-serif\">{$record['birth']}</font></td>\n"; $recordResults .= " <td><font face=\"Arial, Helvetica, sans-serif\">{$record['death']}</font></td>\n"; $recordResults .= " </tr>\n"; } } mysql_close(); } } ?>
  2. Thanks will try both of those suggestions
  3. I have a form and the php is inside the HTML but I don't think the formatting is correct I have some HTML at the start a form then PHP and then combination of PHP and HTML to display the results. There are two place where I check for empty field or valid results then echo something and use the exit command. I think this is causing me problems because this is not letting the close body and close html tags to be generated. Here is the code below: <html> <body> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html> <head> <title>Eugene Pioneer Cemetery</title> <script type="text/javascript" src="js/nav_buttons.js"></script> <LINK rel="stylesheet" type="text/css" href="css/ds.css"> </head> <body bgcolor="#EEEEEE"> <table align="center" cellpadding="0" cellspacing="0" width="891" border="0"><tr><td align="center" class="form" valign="top">WHOLE BUNCH OF HTML<img src="img/TP_pixel.gif" width="1" height="10" border="0" alt=""><form action="record.php" method="post"> <div align="left"><img src="img/TP_pixel.gif" width="280" height="1" border="0" alt="">First Name:<img src="img/TP_pixel.gif" width="105" height="1" border="0" alt="">Last Name:</div><input type="text" name="first" /><img src="img/TP_pixel.gif" width="20" height="1" border="0" alt=""><input type="text" name="last" /><br /> <img src="img/TP_pixel.gif" width="1" height="30" border="0" alt=""><br> <input type="submit" name="submit" value="Submit" /> </form> <?php mysql_connect("antondad.db.4161444.hostedresource.com",$username,$password); @mysql_select_db($database) or die( "Unable to select database"); $first = $_POST['first']; $last = $_POST['last']; $query="SELECT * FROM names where last like '%$last%' AND first like '%$first%'"; if ($last == "") { echo "<p>Please enter a last name</p>"; exit; } $result=mysql_query($query); $num=mysql_numrows($result); if(mysql_num_rows($result)==0){ echo "<p>Sorry no results found</p>"; exit; } mysql_close(); ?> </td></tr> <TR><TD align="center"> <table border="1" cellspacing="2" cellpadding="2" align="center"> <tr> <th><font face="Arial, Helvetica, sans-serif">Block</font></th> <th><font face="Arial, Helvetica, sans-serif">Plot</font></th> <th><font face="Arial, Helvetica, sans-serif">First Name</font></th> <th><font face="Arial, Helvetica, sans-serif">Last Name</font></th> </tr> <?php $i=0; while ($i < $num) { $f1=mysql_result($result,$i,"block"); $f2=mysql_result($result,$i,"plot"); $f3=mysql_result($result,$i,"first"); $f5=mysql_result($result,$i,"last"); ?> <tr> <td><class="body"><?php echo $f1; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $f2; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $f3; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $f5; ?></font></td> </tr> <?php $i++; } ?> </TABLE></td></tr></table> </body> </html>
  4. Thanks that worked.
  5. I'm sure this has been asked many times but I can't seem to find a solution when I search the forums. I can get my insert.php to connect to the database but it won't insert into the table. Am I missing something? <form action="insert.php" method="post"> First Name: <input type="text" name="first"><br> Last Name: <input type="text" name="last"><br> Phone: <input type="text" name="phone"><br> Mobile: <input type="text" name="mobile"><br> Fax: <input type="text" name="fax"><br> E-mail: <input type="text" name="email"><br> Web: <input type="text" name="web"><br> <input type="Submit"> </form> <? $username="antondad"; $password="Ruthholmes1"; $database="antondad"; $first=$_POST['first']; $last=$_POST['last']; $phone=$_POST['phone']; $mobile=$_POST['mobile']; $fax=$_POST['fax']; $email=$_POST['email']; $web=$_POST['web']; mysql_connect("antondad.db.4161444.hostedresource.com",$username,$password); @mysql_select_db($database) or die( "Unable to select database"); echo 'Connected successfully'; mysql_query($query); $query = "INSERT INTO contacts ('','$first','$last','$phone','$mobile','$fax','$email','$web')"; mysql_query($query) or die ( 'Unable to update databae'); echo "Database updated with " .$first. "" .$last. "" ; mysql_close(); ?>
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.