Wow Web Designs Forums Home

Search
   
Members

Calendar

Help

Home
Search by username
Not logged in - Login | Register 
Wow Web Designs Forums > Scripting > PHP > anybody help me php code


anybody help me php code
 Moderated by: Aycan  

New Topic

Reply

Print
AuthorPost
reggiex
Member
 

Joined: Mon Oct 3rd, 2005
Location:  
Posts: 124
Status:  Offline
Mana: 
 Posted: Wed Feb 22nd, 2006 04:28 am

Quote

Reply
anybody please help me with this:

how will i make this condition

$dlname is the variable for my txtbox set as POST

$dlname=$_POST['delete_lnametxt'];

$dfname=$_POST['delete_fnametxt'];

this is my condition

lname and fname are fields in my table in my database.i've already connect to the database. i want  the value entered in the textbox(delete_lnametxt) to be check first in the database,if it exist then thats the time to execute my command..but i get an error with this condition..i think there's something wrong with the condition i put in my if statement..pls help..tnx.

if ((isset($dlname)==lname))&&(isset($dfname)==fname))){

ive already have a query and i think theres nothing wrong with it..i think whats wrong here is the condition i put in my if statement.


 

Last edited on Wed Feb 22nd, 2006 04:30 am by reggiex

klimaks
Member
 

Joined: Thu Dec 29th, 2005
Location:  
Posts: 52
Status:  Offline
Mana: 
 Posted: Wed Feb 22nd, 2006 05:28 am

Quote

Reply

if ((isset($dlname)==$lname)&&(isset($dfname)==$fname)){

reggiex
Member
 

Joined: Mon Oct 3rd, 2005
Location:  
Posts: 124
Status:  Offline
Mana: 
 Posted: Wed Feb 22nd, 2006 07:25 am

Quote

Reply
ok tnx..ill try it..thnx a lot..

reggiex
Member
 

Joined: Mon Oct 3rd, 2005
Location:  
Posts: 124
Status:  Offline
Mana: 
 Posted: Thu Feb 23rd, 2006 05:06 am

Quote

Reply
i tried it but still it wont work..i just want my value enter in the txtbox to be check if it exist in the database, and if it exist then execute so commands..can you give me an example code for that? just a simple example; im a beginner..ive already done adding a record in the database with php..and i want it to check the inputted text in the txtbox if it is in the database,if it exist then it wont add the same record..if you could give me a simple example much better..thanks

reggiex
Member
 

Joined: Mon Oct 3rd, 2005
Location:  
Posts: 124
Status:  Offline
Mana: 
 Posted: Thu Feb 23rd, 2006 05:10 am

Quote

Reply
ive tried the example you gave me but i didnt work..ive tried adding a record to the database which is inputed from a textbox..i just want it to have a checking before it adds the record to the database..if the name you inputed in the textbox exist in the database then i wont add again the same record and it willl exit..im totally a beginner..if you have a simple example that is much better..tnx alot.

csg
Member
 

Joined: Sun Apr 17th, 2005
Location: Kennewick, Washington USA
Posts: 114
Status:  Offline
Mana: 
 Posted: Thu Feb 23rd, 2006 05:16 am

Quote

Reply
I found your problem. You are comparing your variables wrong. When you use the isset function it returns true or false (ie.. true for the variable exists or false it doesn't). So if the variable is true or not, when you compare the strings you are comparing a boolen value(true or false) and a string(text), and those are always false. What you'll want to do is check if the variable exists then compare the strings. Something like this:

if (isset($myvar)) {
    if ($myvar == $myvar2) {
       //item in database exists and matchs
    } else {
       //Item exists and does not match
} else {
    //Item does not exists in
}

reggiex
Member
 

Joined: Mon Oct 3rd, 2005
Location:  
Posts: 124
Status:  Offline
Mana: 
 Posted: Thu Feb 23rd, 2006 05:44 am

Quote

Reply
in your example, what doest $myvar and $myvar2 represents? coz i did something like that already but it didnt work..

like:

$myvar=$_Post['txtboxname'];

$myvar2 should be the fieldname in your database;

(like example:my field name in the table inside my database is "lname")how will i compare that to $myvar(the inputed txt in the texbox)

and then i compared the two.

like if ($myvar==$myvar2){ -- if the inputed text is the same as a record in the database then......

 

csg
Member
 

Joined: Sun Apr 17th, 2005
Location: Kennewick, Washington USA
Posts: 114
Status:  Offline
Mana: 
 Posted: Thu Feb 23rd, 2006 05:48 am

Quote

Reply
Sorry about that. This was your example:

if ((isset($dlname)==$lname)&&(isset($dfname)==$fname)){

here is my

if (isset($dlname) && isset($dsname) {
    if ($dlname == $lname && $dfname == $fname) {
       //item in database exists and matchs
    } else {
       //Item exists and does not match
    }
} else {
    //Item does not exists in
}
 

reggiex
Member
 

Joined: Mon Oct 3rd, 2005
Location:  
Posts: 124
Status:  Offline
Mana: 
 Posted: Thu Feb 23rd, 2006 06:09 am

Quote

Reply
ok thnx..ill try that..thanx a lot..

reggiex
Member
 

Joined: Mon Oct 3rd, 2005
Location:  
Posts: 124
Status:  Offline
Mana: 
 Posted: Thu Feb 23rd, 2006 06:11 am

Quote

Reply
ok ill try that..thanx a lot...

reggiex
Member
 

Joined: Mon Oct 3rd, 2005
Location:  
Posts: 124
Status:  Offline
Mana: 
 Posted: Thu Feb 23rd, 2006 07:57 am

Quote

Reply
its still dont work..by the way heres my code;

 

<?php
mysql_connect('localhost','root','april15') or die(mysql_error());
mysql_select_db('names')or die(mysql_error());

$l_name=$_POST['lnametxt'];
$f_name=$_POST['fnametxt'];

 

$trimmed=trim($l_name);//trim white spaces from stored variable so that the textbox will
$trimmed2=trim($f_name);//be filled up completely

 if (isset($_POST['mybutton'])){
   //check if lnametxt and fnametxt are not blank
   if (($trimmed=="")||($trimmed2=="")){
    echo"please complete the form\n";
    exit;
    }
   if (isset($l_name)&& isset($f_name)){
    if ($l_name==$lname && $f_name==$fname){
     echo "You are currently registed in my database";
     exit;
    }
   } 
   
 
 //execute the query(to add)
 else{
   mysql_query("INSERT INTO members(lname,fname) values('$l_name','$f_name')") or die(mysql_error());
   
   echo "<table width=750 border=2>Data Added\n";
   echo "<tr>";
   echo "<td>";
   echo "<h1>WELCOME  $fname $lname</h1><br>";
   
   echo "</td>";
   echo "</tr>";
   
   echo "</table>";
   }
   
  
  
  
 }

?>

reggiex
Member
 

Joined: Mon Oct 3rd, 2005
Location:  
Posts: 124
Status:  Offline
Mana: 
 Posted: Thu Feb 23rd, 2006 07:59 am

Quote

Reply
it still dont work..by the way heres my code

 

<?php
mysql_connect('localhost','root','april15') or die(mysql_error());
mysql_select_db('names')or die(mysql_error());

$l_name=$_POST['lnametxt'];
$f_name=$_POST['fnametxt'];

 

$trimmed=trim($l_name);//trim white spaces from stored variable so that the textbox will
$trimmed2=trim($f_name);//be filled up completely

 if (isset($_POST['mybutton'])){
   //check if lnametxt and fnametxt are not blank
   if (($trimmed=="")||($trimmed2=="")){
    echo"please complete the form\n";
    exit;
    }
   if (isset($l_name)&& isset($f_name)){
    if ($l_name==$lname && $f_name==$fname){
     echo "You are currently registed in my database";
     exit;
    }
   } 
   
 
 //execute the query(to add)
 else{
   mysql_query("INSERT INTO members(lname,fname) values('$l_name','$f_name')") or die(mysql_error());
   
   echo "<table width=750 border=2>Data Added\n";
   echo "<tr>";
   echo "<td>";
   echo "<h1>WELCOME  $fname $lname</h1><br>";
   
   echo "</td>";
   echo "</tr>";
   
   echo "</table>";
   }
   
  
  
  
 }

?>

klimaks
Member
 

Joined: Thu Dec 29th, 2005
Location:  
Posts: 52
Status:  Offline
Mana: 
 Posted: Thu Feb 23rd, 2006 08:13 am

Quote

Reply
klimaks wrote:
if ((isset($dlname)==$lname)&&(isset($dfname)==$fname)){

 

My bad, should have been

if ((isset($dlname))&&($dlname==$lname)&&(isset($dfname))&&($dfname==$fname)) {

csg
Member
 

Joined: Sun Apr 17th, 2005
Location: Kennewick, Washington USA
Posts: 114
Status:  Offline
Mana: 
 Posted: Thu Feb 23rd, 2006 08:14 am

Quote

Reply
The variblaes $lname and $fname are not declared with anything. There for when you if statement is called php creates those variables, but with no value. So it will always be false. The other variables you are comparing are most likely from a user input, but then where are you wanting the other values from ($fname, $lname)?

reggiex
Member
 

Joined: Mon Oct 3rd, 2005
Location:  
Posts: 124
Status:  Offline
Mana: 
 Posted: Thu Feb 23rd, 2006 08:23 am

Quote

Reply
the variables $fname and $lname are the fieldnames in my database..how will i do that?

csg
Member
 

Joined: Sun Apr 17th, 2005
Location: Kennewick, Washington USA
Posts: 114
Status:  Offline
Mana: 
 Posted: Thu Feb 23rd, 2006 08:50 am

Quote

Reply
Do you know how to get information from the database. Because you code doesn't have it. Example:

$result = mysql_query("SELECT lname, fname FROM members;") or die(mysql_error());

while ($row = mysql_fetch_array($result)) {
    if ($l_name = $row['lname'] && ....) {
    ...
}


Once you have selected the information from the database it is in an array. You loop through the array to see if the user in any of the users. You have to change your code so that doesn't have mutilple results from the loop, for example. If you just add this code to your php file. It might add the user several times to the database.

Last edited on Thu Feb 23rd, 2006 08:56 am by csg

reggiex
Member
 

Joined: Mon Oct 3rd, 2005
Location:  
Posts: 124
Status:  Offline
Mana: 
 Posted: Fri Feb 24th, 2006 12:43 am

Quote

Reply
thanx..i havent tried asking information from the database yet..im just a beginner..ive only made adding info into the database and deleting..ill try searching and displaying later..thanx a lot... 

mark-o-matic
Member


Joined: Mon Apr 17th, 2006
Location: Australia
Posts: 218
Status:  Offline
Mana: 
 Posted: Mon Apr 17th, 2006 10:44 am

Quote

Reply
csg wrote: Do you know how to get information from the database. Because you code doesn't have it. Example:

$result = mysql_query("SELECT lname, fname FROM members;") or die(mysql_error());

while ($row = mysql_fetch_array($result)) {
    if ($l_name = $row['lname'] && ....) {
    ...
}


Once you have selected the information from the database it is in an array. You loop through the array to see if the user in any of the users. You have to change your code so that doesn't have mutilple results from the loop, for example. If you just add this code to your php file. It might add the user several times to the database.

 

Hummmm Il take a look and ill try some stuff ill get back to you latter :D


 Current time is 05:59 pm




Powered by WowBB 1.7 - Copyright © 2003-2006 Aycan Gulez
Page processed in 0.2335 seconds (10% database + 90% PHP). 18 queries executed.