SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    SitePoint Member
    Join Date
    Jun 2005
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    does record exist

    Problem:
    Designing a form to check the existence of a record in the database. If record exists, I need to hold the value of that record and present users with another form. If record does not exist, present users with some type of
    "no record found" type of message. I will need a total of three forms completed before I can display them with the proper webpage.

    Anwser:
    Yes please!! I'm on a deadline and I'm getting from all levels of management. The sooner I complete it, the better my "existence" as an employee will be. (haha!)

    Thanks to everyone who replies.

  2. #2
    SitePoint Evangelist klik's Avatar
    Join Date
    Jan 2005
    Location
    Scotland, UK
    Posts
    547
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Post some code, to show what you have thus far.

  3. #3
    SitePoint Member
    Join Date
    Jun 2005
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here's what I've been working with so far. It's more of a beginning point. I have added various php code with no luck.


    <FORM NAME=input>
    <INPUT TYPE=text NAME=PkType VALUE="" ACTION=GET>
    <INPUT TYPE=submit VALUE="Scan Packaging Type">
    </FORM>

  4. #4
    Level 8 Chinese guy Archbob's Avatar
    Join Date
    Sep 2001
    Location
    Somewhere in this vast universe
    Posts
    3,741
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    if(isset($_POST['submit']))
    {
    	$PkType=$_POST['PkType'];
    	$getrecs="SELECT * from table where somefield='$PkType'";
    	$getrecs2=mysql_query($getrecs) or die("Could not get recs");
    	$num=mysql_num_rows($getrecs2);
    	if($num<1)
    	{
    		 print "error emssage";
    	 }
    	 else
    	 {
    		 $getrecs3=mysql_fetch_array($getrecs2);
    		 //print info and put form here
    	  }
    }

  5. #5
    SitePoint Member
    Join Date
    Jun 2005
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    No luck yet, compare field value to record in database

    I've tried for the last 2 days with no luck. I need major help. My brain must have a short circuit.

  6. #6
    SitePoint Guru Ruben K.'s Avatar
    Join Date
    Jun 2005
    Location
    Alkmaar, The Netherlands
    Posts
    693
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    try

    PHP Code:
    if( $num == )
    {
      echo
    'no records';
    }
    else
    {
      echo
    'records :)';


  7. #7
    Level 8 Chinese guy Archbob's Avatar
    Join Date
    Sep 2001
    Location
    Somewhere in this vast universe
    Posts
    3,741
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Techincally since its mysql_num_rows, $num<1 should work since $num can't be negative.

  8. #8
    SitePoint Guru Ruben K.'s Avatar
    Join Date
    Jun 2005
    Location
    Alkmaar, The Netherlands
    Posts
    693
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Logically, if it equals 0 there are no rows.
    In my opinion this is the 'right' way.

  9. #9
    Level 8 Chinese guy Archbob's Avatar
    Join Date
    Sep 2001
    Location
    Somewhere in this vast universe
    Posts
    3,741
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yeah, that is the traditional way to do it I guess
    But really either one should work.

  10. #10
    Level 8 Chinese guy Archbob's Avatar
    Join Date
    Sep 2001
    Location
    Somewhere in this vast universe
    Posts
    3,741
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yeah, that is the traditional way to do it I guess
    But really either one should work.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •