2011-05-09 11 views
44

मैं इस त्रुटि हो रही है:पीएचपी, MySQL त्रुटि: कॉलम की संख्या पंक्ति में मूल्य संख्या मेल नहीं खाती 1

$name = $_GET['name']; 
$description = $_GET['description']; 
$shortDescription = $_GET['shortDescription']; 
$ingredients = $_GET['ingredients']; 
$method = $_GET['method']; 
//$image = $_GET['image']; 
$username = $_GET['username']; 
$length = $_GET['length']; 
$dateAdded = uk_date(); 
$conn = mysql_connect('localhost', 'dbname', 'pass'); 
mysql_select_db('dbname'); 
$query = sprintf("INSERT INTO dbname (id, Name, Description, shortDescription, Ingredients, Method, Length, dateAdded, Username) VALUES ('', '%s', '%s', '%s', '%s', '%s', '%s', '%s')", 
    mysql_real_escape_string($name), 
    mysql_real_escape_string($description), 
    mysql_real_escape_string($shortDescription), 
    mysql_real_escape_string($ingredients), 
    //mysql_real_escape_string($image), 
    mysql_real_escape_string($length), 
    mysql_real_escape_string($dateAdded), 
    mysql_real_escape_string($username)); 

    $result = mysql_query($query) or die(mysql_error()); 

क्या करता है:

Column count doesn't match value count at row 1

निम्न कोड से त्रुटि मतलब है?

+0

आपने टिप्पणी की है कि // // mysql_real_escape_string ($ image), 'आपकी क्वेरी आपके द्वारा पास किए गए 9 चरों की प्रतीक्षा करती है 8 – afarazit

+0

मैं छवि को एक और तरीके से अपलोड करने जा रहा हूं। छवि कुंजी तालिका में है, लेकिन इसके लिए एक मूल्य डाला नहीं जा रहा है। क्या यह एक कारण हो सकता है? –

उत्तर

81

आपके पास 9 फ़ील्ड सूचीबद्ध हैं, लेकिन केवल 8 मान हैं। विधि जोड़ने का प्रयास करें।

+14

फिर आपने समस्या को ठीक नहीं किया। क्योंकि वह * समस्या * है। –

13

आपकी सम्मिलित क्वेरी में कॉलम पैरामीटर की संख्या 9 है, लेकिन आपने केवल 8 मान प्रदान किए हैं।

INSERT INTO dbname (id, Name, Description, shortDescription, Ingredients, Method, Length, dateAdded, Username) VALUES ('', '%s', '%s', '%s', '%s', '%s', '%s', '%s') 

क्वेरी, "आईडी" पैरामीटर छोड़ देते हैं चाहिए क्योंकि यह स्वत: जनरेट है (या वैसे भी होना चाहिए):

INSERT INTO dbname (Name, Description, shortDescription, Ingredients, Method, Length, dateAdded, Username) VALUES ('', '%s', '%s', '%s', '%s', '%s', '%s', '%s') 

गुड लक!

+0

सिवाय इसके कि सभी फ़ील्ड एक-एक करके बंद हैं। –

6

आपकी क्वेरी में 8 या संभवतः 9 चर भी हैं, यानी। नाम, विवरण इत्यादि। लेकिन मान, इन चीजें --->'', '%s', '%s', '%s', '%s', '%s', '%s', '%s')", केवल कुल 7, चरों की संख्या मानों के समान ही होनी चाहिए।

मुझे एक ही समस्या थी लेकिन मैंने इसे समझ लिया। उम्मीद है कि यह आपके लिए भी काम करेगा।

+3

कृपया ध्यान दें कि इस प्रश्न का उत्तर पहले ही दिया जा चुका है। 1.5 साल पुरानी पोस्ट को पुनर्जीवित करने की कोई आवश्यकता नहीं है जबतक कि आप कुछ नया जोड़ सकें। वैसे भी आपके प्रयास के लिए धन्यवाद। – fancyPants

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