Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > Beginning PHP
|
Beginning PHP Beginning-level PHP discussions. More advanced coders should post to the Pro PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning PHP section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 12th, 2006, 01:06 PM
Registered User
 
Join Date: Jan 2006
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default query for identical field and echo...

Hello all,

I have a questionaire that consists of four pages. Hidden fields are used to carry the information from page to page. The code below is from the first page. I am trying to query the database to see if the propertyname already exists; if it does, to echo an error while keeping the other user-entered information intact. Here's what I've come up with so far, but in preview nothing happens when I enter an already used propertyname. Any help would be most appreciated!


<?php require_once('Connections/connectdb.php'); ?>
<?php
$connectdb;
@mysql_select_db(rentlogin) or die( "Unable to select database");
$Propertyname = $_POST['Propertyname'];
$check = mysql_query("select Propertyname from owner_prop where Propertyname=\"$Propertyname\"");
$returned = mysql_fetch_array($check);
if (isset($_POST['Propertyname']))
    if(!empty($returned))
{ echo 'Propertyname already exists, please choose another name.';
        mysql_close($connectdb);
                Die();
}

?>
 
Old January 15th, 2006, 12:59 PM
Friend of Wrox
 
Join Date: Dec 2004
Posts: 154
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I understand what you are trying to do but it seams just too complicated for me :S and since no one replied:
<?php
$Propertyname1 = $_POST['Propertyname'];
@$dbh=mysql_connect ("localhost", "database username here" , "database password here") or die ('There was a problem connecting to the database - please press refresh');

@mysql_select_db ("rentlogin");
$query = "SELECT * FROM owner_prop WHERE Propertyname LIKE '$Propertyname1'";
$result = mysql_query($query) or die ("There was a problem connecting to the database - please press refresh");
$Propertynameexist="";
while ($row = mysql_fetch_array($result))
  {
     extract($row);
     $Propertynameexist = $Propertyname; }

if ( $Propertynameexist != "" ) { die ("Property name already exist"); }
if ( $Propertynameexist == "" )
{
.
.
.
}
?>
 
Old January 15th, 2006, 05:48 PM
Registered User
 
Join Date: Jan 2006
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks Mantis. I appreciate your input. I'll take what you have and try to rework the code!






Similar Threads
Thread Thread Starter Forum Replies Last Post
Ex10_01 Identical code, different output tonyjeffs BOOK: Ivor Horton's Beginning Visual C++ 2005 4 December 7th, 2007 05:50 AM
Finding identical values voskoue Access VBA 7 January 30th, 2007 08:43 AM
Identical results in Drop Down List 5ilverado ASP.NET 1.0 and 1.1 Professional 0 July 3rd, 2006 12:26 AM
Problem with echo from query result Steve Newbie MySQL 2 August 16th, 2004 11:48 AM
multiple definitions with identical signatures Galina Crystal Reports 0 February 14th, 2004 05:39 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.