PHP - Column Count Doesn't Match Value Count At Row 1
Why am I getting this error when there are 3 Fields with 3 values?
Column count doesn't match value count at row 1 Code: [Select] $sql5="INSERT INTO participants (participant_name, team_no, sport) VALUES ('".implode("','$_POST[team]'),('",$_POST['participant_name'])."','$_POST[team]','$sport')"; Similar TutorialsHi guys, I need your help. I am trying to insert the rows in the mysql database as I input the values in the url bar which it would be like this: Code: [Select] www.mysite.com/testupdate.php?user=tester&pass=test&user1=tester&email=me@shitmail.com&ip=myisp However i have got a error which i don't know how to fix it. Error: Column count doesn't match value count at row 1 <?php session_start(); define('DB_HOST', 'localhost'); define('DB_USER', 'mydbusername'); define('DB_PASSWORD', 'mydbpassword'); define('DB_DATABASE', 'mydbname'); $errmsg_arr = array(); $errflag = false; $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD); if(!$link) { die('Failed to connect to server: ' . mysql_error()); } $db = mysql_select_db(DB_DATABASE); if(!$db) { die("Unable to select database"); } function clean($var){ return mysql_real_escape_string(strip_tags($var)); } $username = clean($_GET['user']); $password = clean($_GET['pass']); $adduser = clean($_GET['user1']); $email = clean($_GET['email']); $IP = clean($_GET['ip']); if($username == '') { $errmsg_arr[] = 'username is missing'; $errflag = true; } if($password == '') { $errmsg_arr[] = 'PASSWORD is missing'; $errflag = true; } if($errflag) { $_SESSION['ERRMSG_ARR'] = $errmsg_arr; echo implode('<br />',$errmsg_arr); } else { $sql = "INSERT INTO `members` (`username`,`email`,`IP`) VALUES ('$adduser','$email','$IP')"; if (!mysql_query($sql,$link)) { die('Error: ' . mysql_error()); } echo "The information have been updated."; } ?> Here's the name of the columns i have got in my database: Code: [Select] username IP I have input the correct columns names, so I can't correct the problem I am getting. Please can you help? This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=331562.0 How to write this in a shorter way? I've got a set of results and I need to check them against another database results. If they both are similar then I want to make it as "1" (points). The questions and the answers are in the same order (Question1, Question2, Question3 = Answer1, Answer2, Answer3). sa I guess the maching could be done using a set of arrays. E.g. get records from db1 get records from db2 get records from dbY get records from dbX COUNT the matching data from db1 against dbY = echo TOTAL_SCORE1 COUNT the matching data from db2 against dbX = echo TOTAL_SCORE2 I've managed to get the data from the databases in order. But i need to get the COUNT of the MATCHING records. php \\Assume this is db1 $SomeVar = $_POST['sitting2']; $queryU = "SELECT * FROM adxone WHERE username = '".$SomeVar."'"; $resultU = mysql_query($queryU); $scoreU = mysql_fetch_assoc($resultU); $userRa1 = $scoreU['roundzAa']; $userRa2 = $scoreU['roundzAb']; $userRa3 = $scoreU['roundzAc']; $userRa4 = $scoreU['roundzAd']; $userRa5 = $scoreU['roundzAe']; $userRa6 = $scoreU['roundzAf']; $userRa7 = $scoreU['roundzAg']; $userRa8 = $scoreU['roundzAh']; \\ Assume this is dbY $WinVar = 'examinationA'; $query = "SELECT * FROM markacs WHERE roundx = '".$WinVar."'"; $result = mysql_query($query); $scoreM = mysql_fetch_assoc($result); $winRa1 = $scoreM['markwinxa']; $winRa2 = $scoreM['markwinxb']; $winRa3 = $scoreM['markwinxc']; $winRa4 = $scoreM['markwinxd']; $winRa5 = $scoreM['markwinxe']; $winRa6 = $scoreM['markwinxf']; $winRa7 = $scoreM['markwinxg']; $winRa8 = $scoreM['markwinxh']; /*need to match if $winRa1 = $userRa1, $winRa2 = $userRa2, etc.. then get the COUNT of the matching results*/ I can't get the COUNT of the matching results? Please help. $SomeVar = myname; $queryU = "SELECT * FROM adxone WHERE username = '".$SomeVar."'"; $resultU = mysql_query($queryU); while($scoreP = mysql_fetch_array($resultU)) { $scoreP['roundzAa']; $scoreP['roundzAb']; $scoreP['roundzAc']; $scoreP['roundzAd']; $scoreP['roundzAe']; $scoreP['roundzAf']; $scoreP['roundzAg']; $scoreP['roundzAh']; } $WinV = 'resultA'; $query = "SELECT * FROM acs WHERE resultx = '".$WinV."'"; $result = mysql_query($query); while($scoreUsr = mysql_fetch_array($result)) { $scoreUsr = $scoreM1['winxa']; $scoreUsr = $scoreM1['winxb']; $scoreUsr = $scoreM1['winxc']; $scoreUsr = $scoreM1['winxd']; $scoreUsr = $scoreM1['winxe']; $scoreUsr = $scoreM1['winxf']; $scoreUsr = $scoreM1['winxg']; $scoreUsr = $scoreM1['winxh']; } $count1 = count( array_intersect($resultU, $result) ); echo($count1); mysql_query("UPDATE comp SET id=$count1 WHERE username = '".$SomeVar."'"); ?> I'm printing some mysql results to a table and sometimes I have rows with no results so they never get counted... which results in an ugly looking parenthesis on my page with nothing it (). For these times, I'd like to print a zero. How can I rewrite the following to achieve this? Code: [Select] if($row['mycount'] does not exist) { $row['mycount'] = '0'; } Hi Everyone, I am working on implementing a blog comment system using the query below to display comments. My question is what is the best way to do a row count for the id column with this query or do I need to do a second db query to accomplish this? The purpose of this is to echo out the number of comments for that post, before displaying them. Any help is appreciated. Thanks in advance, kaiman <?php // get url variables $post_id = mysql_real_escape_string($_GET['id']); include ("../../scripts/includes/nl2p.inc.php"); // connects to server and selects database include ("../../scripts/includes/dbconnect.inc.php"); // table name $tbl_name3="blog_comments"; // select info from comments database $result3 = mysql_query ("SELECT count(*) FROM $table_name3 WHERE id='$post_id' ORDER BY id DESC LIMIT 1") or trigger_error("A mysql error has occurred!"); if (mysql_num_rows($result3) > 0 ) { while($row = mysql_fetch_array($result3)) { extract($row); // display number of comments // display date $row_date = strtotime($row['date']); putenv("TZ=America/Denver"); echo "<p class=\post\">On ".date('F, jS, Y', $row_date)." "; // display commenter name if($row['url'] == "") { echo $row['name']." wrote:</p>\n"; } else { echo "<a href=\"".$row['url']."\" target=\"_blank\">".$row['name']."</a> wrote:</p>\n"; } // display content $comments = $row['comment']; echo nl2p($comments); } } else { echo "<p class=\"large_spacer\">No Comments</p>"; } ?> This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=320119.0 Hi everyone, Like the title says I need to count the amount of 1's in a column but I can't figure out how. Gr and thanx already Ryflex Anyone can help me? <?php $tbl_name="menu"; $kategorije = mysql_query("SELECT * FROM $tbl_name WHERE Left(menu_name, 1) BETWEEN 'A' AND 'M' ORDER BY menu_name ASC"); if (!$kategorije) { die("Database query failed: " . mysql_error()); } while ($row=mysql_fetch_array( $kategorije )) { echo "<div id=lista-header><h4>{$row["menu_name"]}</h4></div>"; $id_sub=$row['id_menu']; $podkategorije = mysql_query("SELECT * FROM submenu WHERE id_menu=$id_sub ORDER BY sub_name ASC", $connection); if (!$podkategorije) { die("Database query failed: " . mysql_error()); } echo "<ul class=\"pod\">"; while ($pod=mysql_fetch_array( $podkategorije )) { echo "<li><a href=index.php?=podkate?".$pod["id_sub"]." class=black>{$pod["sub_name"]}</a><hr size=1 align=left width=100px color=#cccccc></li>"; } echo "</ul>"; } ?> In this way, I get list with categories and hes subcategories. How to count how many subcategories have each categories, and count how many articles have each categories? Example (I wanna get this kind of look): Categories name (3) subcategoriesname (2) subcategoriesname (4) subcategoriesname (7) Categories name (5) subcategoriesname (1) subcategoriesname (14) subcategoriesname (9) subcategoriesname (2) subcategoriesname ( Categories name (2) subcategoriesname (28) subcategoriesname (17) Where the numbers represent how many categories and sub-items have articles Hello,
I am trying to get the report of my sales table. I want to get total number of leads for each month. And then i have to use this data to create graph using google graph.
But i am not getting how eactly i can get this.
Here is my code
<?php if(isset($_POST['submit'])) { $type = $_POST['type']; $sql="select * from leads where lead_customer='".$type."'"; $query=mysql_query($sql); while ($row = mysql_fetch_array($query)) { list($year,$month,$day)=explode("-", $row['last_modified']); $l = $row['last_modified']; $count=mysql_num_rows($month); echo $count; $myurl[] = "['".$month."', ".$count."]"; } print_r($myurl); echo implode(",", $myurl); } ?>But for $count, it doesn't show any values. below is my database. Capture.PNG 18.16KB 0 downloads Please suggest me Hey All, I need to count and display the number of rows I have. <?php //declare the SQL statement that will query the database $query = " SELECT COUNT(id) FROM connectvisits WHERE staffid = '$staffid' "; //execute the SQL query and return records $result = mssql_query($query); $thismonth = mssql_num_rows($result); echo "Total Meetings This Month: "; echo $thismonth; echo "<br />"; ?> For some reason I keep getting a result of 1. Everything else I try gives me a "Resource ID" number. Any help would be apprecaited. Maybe I have the completely wrong code. Thanks! returns -30. how can i remove the minus so it just returns 30 Code: [Select] $days = (strtotime(date("Y-m-d")) - strtotime($info['expiredate'])) / (60 * 60 * 24) echo $days hey i'm just woundering how i would go abouts on echoing unread messages sent to a user i want to beable to see how many unread messages i have Hello, I'm using the following code to count the amount of SQL results and divide it. Works great as is but I want to alter it so it works with categories. $amount = mysql_query('SELECT COUNT(`car_id`) AS num FROM `tbl_cars`') or die(mysql_error()); $amount_row = mysql_fetch_assoc($amount); I tried adding... WHERE car_cat = '".$cat."' which causes an error. Why doesn't this work, and how can I get the amount of results as a variable? I have the following array: Code: [Select] Array ( [item0] => Array ( [0] => name1 [1] => name2 [2] => name3 [3] => name4 [4] => name5 )etc... Is it possible to count the number of times a name exists in the compleet array? Thanx in advance! I have an XML document that id decrypted and shown onto a table. At the bottom of the page, I'm trying to have it count up one Code: [Select] foreach($Data as $Types) // loop through book foreach($Types as $Colors) // loop through book { print_r(count($Colors->Color)); } There are 4 colors, blue, green, red, yellow. Blue is listed 7 times, green is 3, red is 8, and yellow is 4 times. What I expect it to print is: 7 3 8 4 Instead, it's printing this: 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 If I was to just do the print function without count, it lists like this: blue red blue red green yellow blue red yellow red red green yellow yellow blue blue green blue yellow blue red red blue red My end-goal of this code is to get it to print this: Blue: 7 Green: 3 Red: 8 Yellow: 4 Hi All, The following code works but for some reason it is leaving 1 result off of each page when displaying results from DB. I assume there is something wrong with the count but I cannot find the problem. Thank you for any help. Code: [Select] <?php $page = $_GET['page']; $result2 = mysql_query("SELECT * FROM vendors WHERE vendor_type_id = '$vdrt' AND active ='Yes' ORDER BY RAND()"); $total_results = mysql_num_rows($result2); if (empty($total_results)) {echo "Sorry, but we do not have any results for that search at this time. <br/><br/><a href='index.php'>Please try your search again</a>";} else { $total_pages = ceil($total_results / $results_limit); // $results_limit is set to 7 in config file if (empty($page)) { $page = "1"; } $offset = ($page - 1) * $results_limit; $result = mysql_query("SELECT * FROM vendors WHERE vendor_type_id = '$vdrt' AND active ='Yes' LIMIT $offset, $results_limit") or die ("$DatabaseError"); $row = mysql_fetch_assoc($result); $vendor_type_id = $row['vendor_type_id']; $num = mysql_numrows($result); if ($num == 0) : print "<br><br><p>Sorry, no vendors could be found.</p><br><br>"; elseif ($num > 0) : echo "Page - "; if ($page != 1) { echo "<a href=$PHP_SELF?city=Orlando&state=FL&vdrt=$vendor_type_id&page=1><< First</a> "; $prevpage = $page - 1; } if ($page == $total_pages) { $to = $total_pages; } elseif ($page == $total_pages-1) { $to = $page+1; } elseif ($page == $total_pages-2) { $to = $page+2; } else { $to = $page+3; } if ($page == 1 || $page == 2 || $page == 3) { $from = 1; } else { $from = $page-3; } for ($i = $from; $i <= $to; $i++) { if ($i == $total_results) $to=$total_results; if ($i != $page) { echo "<a href=$PHP_SELF?city=Orlando&state=FL&vdrt=$vendor_type_id&showold=yes&page=$i>$i</a>"; } else { echo "<b><span class='current-page'>[$i]</span></b>"; } if ($i != $total_pages) echo " "; } if ($page != $total_pages) { $nextpage = $page + 1; echo " <a href=$PHP_SELF?city=Orlando&state=FL&vdrt=$vendor_type_id&page=$total_pages>Last >></a>"; } if ($num == 0) { echo "<br><br>";} else {echo "<br><br>";} $i = 0; while ($i < $num) : while ($row = mysql_fetch_assoc($result)) { $vdrid = $row['vendor_id']; $vendor_name = $row['vendor_name']; $vendor_name_enc = urlencode($row['vendor_name']); $vendor_city = $row['vendor_city']; $vendor_state = $row['vendor_state']; $vendor_phone = $row['vendor_phone']; $vendor_overview = $row['vendor_overview']; // Trim overview if(strlen($vendor_overview) > 385) {$trimed_vendor_overview = substr($vendor_overview,0,385) . "..."; } else { $trimed_vendor_overview = $vendor_overview; } echo "<strong><a href='listing.php?$vendor_name_enc-$vendor_city-$vendor_state-&vdrid=$vdrid'>$vendor_name</a> </strong> - $vendor_city, $vendor_state $vendor_phone<br/>"; echo "$trimed_vendor_overview<br/><br/>"; } $i++; endwhile; endif; } ?> How to get the count if any of this ($ArrayDrRes) contain the word "APPROVED"? $Array1 = array($user1, $user2, $user3, $user4, $user5, $user6, $user7, $user8); $Array2 = array('APPROVED'); $count3 = count( array_intersect($Array1, $Array2) ); echo $count3; |