473,387 Members | 1,492 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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

omerbutt
638 512MB
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,quantity, 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 2079
dlite922
1,584 Expert 1GB
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,quantity, 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_assoc 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
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...
0
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...
2
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...
110
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...
3
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...
1
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
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...
221
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...
1
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...

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.