2010-06-25 11 views
5

मुझे एक छोटी सी समस्या है। मैं foro.php के माध्यम से साइट का उपयोग करता हूं? Id = 74 & मोड = एड या foro.php? Id = 74 & मोड = संपादित करें यह ठीक काम करता है .. लेकिन जब मैं एक कोलन, अर्धविराम (; या :) foro.php जोड़ता हूं ? id = 74 & मोड = इसे संपादित करें विकल्पस्थिति में एक PHP में समस्या

foro.php? id = 74 & मोड = जोड़ें; ?
foro.php आईडी = 74 & मोड = जोड़ें:?
foro.php आईडी = 74 & मोड = जोड़ें '

नीचे मेरी कोड

<?php 
$numb=mysql_real_escape_string($_GET['id']); 

    if ($_GET['mode']=='add') { 

    $sql1="select * from cello where number='".mysql_real_escape_string($numb)."' LIMIT 1"; 
    $result1=mysql_query($sql1) or die(mysql_error()); 
    while ($row=mysql_fetch_array($result1)) { 

     $name=$row['name']; 
     echo $name; 
    } 
    } 


elseif ($_GET['mode']='edit') { 

$sql="select * from cello account_number='".mysql_real_escape_string($numb)."' limit 1"; 
$result=mysql_query($sql) or die(mysql_error()); 

    while ($row=mysql_fetch_array($result)) { 

$acnumb=$row['number']; 
$name=$row['name']; 
$address=$row['address']; 

echo $acnumb; 
echo $name; 
echo $address; 

    } 
    } 
else {echo "error!!";} 
    ?> 

किसी भी तरह से यह कैसे को रोकने के लिए है ?

उत्तर

8

आपने समानता ऑपरेटर == के बजाय असाइनमेंट ऑपरेटर = का उपयोग किया है।

कोशिश बदलते इस:

elseif ($_GET['mode']='edit') { 
इस के लिए

:

elseif ($_GET['mode']=='edit') { 
+0

धन्यवाद .. यह ठीक – LiveEn

5

समस्या यह है कि निम्नलिखित लाइनों में, अगर बयान में, आप की तुलना नहीं कर रहे हैं, लेकिन करने के लिए एक मूल्य बताए है जीईटी सरणी में मोड तत्व:

... 
elseif ($_GET['mode']='edit') { 

$sql="select * from cello account_number='".mysql_real_escape_string($numb)."' limit 1"; 
$result=mysql_query($sql) or die(mysql_error()); 
... 

वह ऑपरेशन सत्य लौटाता है, पहली तुलना है झूठा, और यही कारण है कि यह संपादन खंड में चला जाता है।

5

समाधान:

समस्या निश्चित रूप से elseif ($_GET['mode']='edit') { लाइन के साथ निहित है; = ऑपरेटर $_GET['mode'] से 'edit' पर सेट करता है (जो हमेशा true का मूल्यांकन करता है)। में प्राप्त करने के लिए एक अच्छा लेकिन lexically-भ्रम अभ्यास तो जैसे सशर्त, लिख रहा है:

if (5 == $some_var) 

अगर दूसरा = शामिल नहीं किया गया जो तुरंत एक त्रुटि दे देंगे।

सुझाव:

आप अपने कोड को व्यवस्थित करने के लिए एक switch नियंत्रण लागू करने के लिए चाहते हो सकता है:

<?php 
switch ($_GET['mode']) { 
    case 'add': 

     $sql1="select * from cello where number='".mysql_real_escape_string($numb)."' LIMIT 1"; 
     $result1=mysql_query($sql1) or die(mysql_error()); 
     while ($row=mysql_fetch_array($result1)) { 

      $name=$row['name']; 
      echo $name; 
     } 

     break; 

    case 'edit': 
     $sql="select * from cello account_number='".mysql_real_escape_string($numb)."' limit 1"; 
     $result=mysql_query($sql) or die(mysql_error()); 

     while ($row=mysql_fetch_array($result)) { 

      $acnumb=$row['number']; 
      $name=$row['name']; 
      $address=$row['address']; 

      echo $acnumb; 
      echo $name; 
      echo $address; 

     } 

     break; 

    default: 
     echo "error!!"; 
} 
+0

धन्यवाद काम किया सुझाव के लिए .. मैं नहीं सोचा था यह पहले – LiveEn

संबंधित मुद्दे