473,804 Members | 2,998 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

php mysql issue.....if a specific field exists

omerbutt
638 Contributor
hi there i am new to php ,have been working in asp classic and access but now have switched to php and mysql,and for the practice sake i started to convert my asp and access based projects into php and mysql, i have a inventory system in which i have a stock entry Portion which has aloots of fields concerning to the codeno,partno, auto , product,quantit y, size, height and lots of other fields too but our main concern is with these two
"CODENO and PARTNO
sample values for these tow are here
codeno--------part no
1000--------CSV-3345
1000--------CSV-3346
1001--------CSV-3345

by looking at the values above you can figure outsome how that the values for the code no can be repeated more than once for eg you can enter part nos for the CODENO=1000 as many times as u want lets say partno=CSV-3345 but you cannot enter the existing partno for the codeno=1000 twice means the partno=csv-3345 can not be entered twice under codeno=1000 but the same partno=CSV-3345 can be entered for another code no say
"1001"in asp and access what i did for checking if the record exists this is what i did
Expand|Select|Wrap|Line Numbers
  1. sqlf="SELECT Stk_items.Prt_no from Stk_items where Stk_items.Code_no="&lngcodeno
  2. rf.Open sqlf, connf, 3
  3. foundit=False
  4. do until rf.EOF OR foundit //runs until foundit becomes true
  5.   if (StrComp(rf.Fields("Prt_no"), partno, vbTextCompare) = 0) then                   foundIt=True //assign true to foundit 
  6. else
  7. rf.MoveNext //else move to next record
  8. End if 
  9. Loop
  10. rf.Close
  11. set rf = Nothing
  12. set connf= Nothing    
  13.  
this runs accurately perfect foor asp and access but in php the case is different what i have done in my php code is here
Expand|Select|Wrap|Line Numbers
  1.     $hostname="localhost";
  2.     $username="root";
  3.     $password="66456";
  4.     $database="db1";
  5.  
  6. $conn_stk = mysql_pconnect($hostname, $username, $password) or 
  7. trigger_error(mysql_error(),E_USER_ERROR);
  8.     mysql_select_db($database, $conn_stk);
  9.  
  10.     $codeno=$_POST["code_no"];
  11.     $prtno=$_POST["prt_no"];
  12.     $prd=$_POST["prd"];
  13.     $brand=$_POST["brand"];
  14.     $auto=$_POST["auto"];
  15.     $uprc=$_POST["unit_price"];
  16.     $qtty=$_POST["qtty"];
  17.     $sroom=$_POST["show_room"];
  18.     $st1=$_POST["store_1"];
  19.     $st2=$_POST["store_2"];
  20.     $st3=$_POST["store_3"];
  21.     $size=$_POST["size"];
  22.     $height=$_POST["height"];
  23.     $od1=$_POST["out_d1"];
  24.     $od2=$_POST["out_d2"];
  25.     $id1=$_POST["in_d1"];
  26.     $id2=$_POST["in_d2"];
  27.     $trep=$_POST["t_rep"];
  28.     $rp1=$_POST["rp_no1"];
  29.     $rp2=$_POST["rp_no2"];
  30.     $rp3=$_POST["rp_no3"];
  31.     $rp4=$_POST["rp_no4"];
  32.     $rp5=$_POST["rp_no5"];
  33.     $rp6=$_POST["rp_no6"];
  34.  
  35.  
  36.     $sqlf="select Prt_no from stk_items where Code_no='$codeno'";
  37.     $rs=mysql_query($sqlf) or die(mysql_error().'<br />'.$sqlf);
  38.  
  39.     $foundit=false;
  40.  
  41.     if(mysql_num_rows($rs))
  42.     {
  43.         while($f=mysql_fetch_array($rs));
  44.             {    
  45.                 $ret=strcmp($f['Prt_no'],$prtno);                
  46.                 if($ret==0)
  47.                 {
  48.                     $foundit=true;
  49.                 }
  50.                 else
  51.                 {}                
  52.             }
  53.     }
  54.  
BUT THE PROB IS THAT IF I ENTER THE PART NO WHICH ALREADY EXISTS IT TELLS THAT THE VALUE EXISTS BUT IF I ENETER ANY OTHER PART NO THAT DOESNOT EXIST IT JUST HANKS
ANY SUGGESTIONS WOULD BE HIGHLY APPRECIATED
REGARDS,
OMER
Feb 13 '08 #1
1 2099
dlite922
1,584 Recognized Expert Top Contributor
hi there i am new to php ,have been working in asp classic and access but now have switched to php and mysql,and for the practice sake i started to convert my asp and access based projects into php and mysql, i have a inventory system in which i have a stock entry Portion which has aloots of fields concerning to the codeno,partno, auto , product,quantit y, size, height and lots of other fields too but our main concern is with these two
"CODENO and PARTNO
sample values for these tow are here
codeno--------part no
1000--------CSV-3345
1000--------CSV-3346
1001--------CSV-3345

by looking at the values above you can figure outsome how that the values for the code no can be repeated more than once for eg you can enter part nos for the CODENO=1000 as many times as u want lets say partno=CSV-3345 but you cannot enter the existing partno for the codeno=1000 twice means the partno=csv-3345 can not be entered twice under codeno=1000 but the same partno=CSV-3345 can be entered for another code no say
"1001"in asp and access what i did for checking if the record exists this is what i did
Expand|Select|Wrap|Line Numbers
  1. sqlf="SELECT Stk_items.Prt_no from Stk_items where Stk_items.Code_no="&lngcodeno
  2. rf.Open sqlf, connf, 3
  3. foundit=False
  4. do until rf.EOF OR foundit //runs until foundit becomes true
  5. if (StrComp(rf.Fields("Prt_no"), partno, vbTextCompare) = 0) then foundIt=True //assign true to foundit 
  6. else
  7. rf.MoveNext //else move to next record
  8. End if 
  9. Loop
  10. rf.Close
  11. set rf = Nothing
  12. set connf= Nothing    
  13.  
this runs accurately perfect foor asp and access but in php the case is different what i have done in my php code is here
Expand|Select|Wrap|Line Numbers
  1.     $hostname="localhost";
  2.     $username="root";
  3.     $password="66456";
  4.     $database="db1";
  5.  
  6. $conn_stk = mysql_pconnect($hostname, $username, $password) or 
  7. trigger_error(mysql_error(),E_USER_ERROR);
  8.     mysql_select_db($database, $conn_stk);
  9.  
  10.     $codeno=$_POST["code_no"];
  11.     $prtno=$_POST["prt_no"];
  12.     $prd=$_POST["prd"];
  13.     $brand=$_POST["brand"];
  14.     $auto=$_POST["auto"];
  15.     $uprc=$_POST["unit_price"];
  16.     $qtty=$_POST["qtty"];
  17.     $sroom=$_POST["show_room"];
  18.     $st1=$_POST["store_1"];
  19.     $st2=$_POST["store_2"];
  20.     $st3=$_POST["store_3"];
  21.     $size=$_POST["size"];
  22.     $height=$_POST["height"];
  23.     $od1=$_POST["out_d1"];
  24.     $od2=$_POST["out_d2"];
  25.     $id1=$_POST["in_d1"];
  26.     $id2=$_POST["in_d2"];
  27.     $trep=$_POST["t_rep"];
  28.     $rp1=$_POST["rp_no1"];
  29.     $rp2=$_POST["rp_no2"];
  30.     $rp3=$_POST["rp_no3"];
  31.     $rp4=$_POST["rp_no4"];
  32.     $rp5=$_POST["rp_no5"];
  33.     $rp6=$_POST["rp_no6"];
  34.  
  35.  
  36.     $sqlf="select Prt_no from stk_items where Code_no='$codeno'";
  37.     $rs=mysql_query($sqlf) or die(mysql_error().'<br />'.$sqlf);
  38.  
  39.     $foundit=false;
  40.  
  41.     if(mysql_num_rows($rs))
  42.     {
  43.         while($f=mysql_fetch_array($rs));
  44.             {    
  45.                 $ret=strcmp($f['Prt_no'],$prtno);                
  46.                 if($ret==0)
  47.                 {
  48.                     $foundit=true;
  49.                 }
  50.                 else
  51.                 {}                
  52.             }
  53.     }
  54.  
BUT THE PROB IS THAT IF I ENTER THE PART NO WHICH ALREADY EXISTS IT TELLS THAT THE VALUE EXISTS BUT IF I ENETER ANY OTHER PART NO THAT DOESNOT EXIST IT JUST HANKS
ANY SUGGESTIONS WOULD BE HIGHLY APPRECIATED
REGARDS,
OMER

Use mysql_fetch_ass oc instead of array.

or change it to access it like $f[0]

also change $ret==0 to $ret===0 (check type)

then try again.

PS, you don't need that extra else.
Feb 20 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
11769
by: dave | last post by:
Hello there, I am at my wit's end ! I have used the following script succesfully to upload an image to my web space. But what I really want to be able to do is to update an existing record in a table in MySQL with the path & filename to the image. I have successfully uploaded and performed an update query on the database, but the problem I have is I cannot retain the primary key field in a variable which is then used in a SQL update...
0
3953
by: Mike Chirico | last post by:
Interesting Things to Know about MySQL Mike Chirico (mchirico@users.sourceforge.net) Copyright (GPU Free Documentation License) 2004 Last Updated: Mon Jun 7 10:37:28 EDT 2004 The latest version of this document can be found at: http://prdownloads.sourceforge.net/souptonuts/README_mysql.txt?download
2
3452
by: Sam White | last post by:
I have set up a MySQL db on one server, IIS 6.0 on another. Using Frontpage I created some forms to input data. On a test page I made, I have 4 fields. First is the ID which is autonumber (I leave alone). The second is marked as TEXT, the third is MEDIUMTEXT, and the fourth is DATE. This is just an example though, the problem exists in no matter what manner I create the form. Now here is the issue. In the TEXT fields nothing is saved...
110
10641
by: alf | last post by:
Hi, is it possible that due to OS crash or mysql itself crash or some e.g. SCSI failure to lose all the data stored in the table (let's say million of 1KB rows). In other words what is the worst case scenario for MyISAM backend? Also is it possible to not to lose data but get them corrupted?
3
1266
by: kd8con | last post by:
Ok, I am writing an application in which - a user enters data into a field, then when leaving this field and going to the next field, I need to do a search on the access database for that data and pop up a window if it exists giving specific data from that record in the database. Setting up the database connection is done, since it is the same database - what I'm having a problem with is performing this action during a field entry. Also I...
1
2528
by: paulq182 | last post by:
PLEASE HELP ME WITH MY CODE?? import java.sql.*; import java.io.*; class min_filmdb_rel_mysql { public static void main (String args ) throws SQLException, IOException {
6
38533
Atli
by: Atli | last post by:
This is an easy to digest 12 step guide on basics of using MySQL. It's a great refresher for those who need it and it work's great for first time MySQL users. Anyone should be able to get through this without much trouble. Programming knowledge is not required. Index What is SQL? Why MySQL? Installing MySQL. Using the MySQL command line interface
221
367773
Atli
by: Atli | last post by:
You may be wondering why you would want to put your files “into” the database, rather than just onto the file-system. Well, most of the time, you wouldn’t. In situations where your PHP application needs to store entire files, the preferred method is to save the file onto the server’s file-system, and store the physical location of the file in your database. This is generally considered to be the easiest and fastest way to store files. ...
1
9596
ssnaik84
by: ssnaik84 | last post by:
Hi Guys, Last year I got a chance to work with R&D team, which was working on DB scripts conversion.. Though there is migration tool available, it converts only tables and constraints.. Rest of things (stored procedures, functions).. we have to manually edit. That time, we face some interesting challenges.. I failed to document all of them, but whatever I can share with u.. I will try.. :) ...
0
9706
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9579
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10332
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10321
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10077
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7620
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6853
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
2
3820
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2991
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.