PHP - Invalid Parameter Number: Number Of Bound Variables Does Not Match Number Of Tokens
I'm getting the dreaded " Invalid parameter number: number of bound variables does not match number of tokens" error and I've looked at this for days. Here is what my table looks like:
| id | int(4) | NO | PRI | NULL | auto_increment | | user_id | int(4) | NO | | NULL | | | recipient | varchar(30) | NO | | NULL | | | subject | varchar(25) | YES | | NULL | | | cc_email | varchar(30) | YES | | NULL | | | reply | varchar(20) | YES | | NULL | | | location | varchar(50) | YES | | NULL | | | stationery | varchar(40) | YES | | NULL | | | ink_color | varchar(12) | YES | | NULL | | | fontchosen | varchar(30) | YES | | NULL | | | message | varchar(500) | NO | | NULL | | | attachment | varchar(40) | YES | | NULL | | | messageDate | datetime | YES | | NULL |Here are my params: $params = array( ':user_id' => $userid, ':recipient' => $this->message_vars['recipient'], ':subject' => $this->message_vars['subject'], ':cc_email' => $this->message_vars['cc_email'], ':reply' => $this->message_vars['reply'], ':location' => $this->message_vars['location'], ':stationery' => $this->message_vars['stationery'], ':ink_color' => $this->message_vars['ink_color'], ':fontchosen' => $this->message_vars['fontchosen'], ':message' => $messageInput, ':attachment' => $this->message_vars['attachment'], ':messageDate' => $date );Here is my sql: $sql = "INSERT INTO messages (user_id,recipient, subject, cc_email, reply, location,stationery, ink_color, fontchosen, message,attachment) VALUES( $userid, :recipient, :subject, :cc_email, :reply, :location, :stationery, :ink_color, :fontchosen, $messageInput, :attachment, $date);"; And lastly, here is how I am calling it: $dbh = parent::$dbh; $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING); if (empty($dbh)) return false; $stmt = $dbh->prepare($sql); $stmt->execute($params) or die(print_r($stmt->errorInfo(), true)); if (!$stmt) { print_r($dbh->errorInfo()); }I know my userid is valid and and the date is set above (I've echo'd these out to make sure). Since the id is auto_increment, I do not put that in my sql (though I've tried that too), nor in my params (tried that too). What am I missing? I feel certain it is something small, but I have spent days checking commas, semi-colons and spelling. Can anyone see what I'm doing wrong? Similar TutorialsHello,
I have problem durring binding update query. I can't find what is causing problem.
public function Update(Entry $e) { try { $query = "update entry set string = $e->string,delimiter=$e->delimiter where entryid= $e->id"; $stmt = $this->db->mysqli->prepare($query); $stmt->bind_param('ssi',$e->string,$e->delimiter,$e->id); $stmt->close(); } catch(Exception $ex) { print 'Error: ' .$ex->getMessage(); } }When I run function update I'm getting next error:Warning: mysqli_stmt::bind_param(): Number of variables doesn't match number of parameters in prepared statement Can you help me to solve this problem ? Edited by danchi, 17 October 2014 - 10:25 AM. I have the following code just to insert a username and hashed password into the database but somehow I am getting this error and I couldn't find out where I am doing it wrong...can someone please give me a hand?
I tried it in two ways and both errors...
the first few lines are just connecting database which worked fine and a password.php so I can use password_hash() with my php version
$hash = password_hash('xx', PASSWORD_BCRYPT, array('cost' => 10)); $username = 'xx'; $insertQuery = $db->prepare(" INSERT INTO et_todo (username, password) VALUES (:username, :hash) "); $insertQuery->execute(array( 'username' => $username, 'password' => $hash ));also tried $hash = password_hash('xx', PASSWORD_BCRYPT, array('cost' => 10)); $insertQuery = $db->prepare(" INSERT INTO et_todo (username, password) VALUES ('xx', :hash) "); $insertQuery->execute(array( 'username' => 'xx', 'password' => $hash )); I need to display a number(the number is retrieved from the db) in the form input field such that only the last 4 digits is visbile, the remaining can be masked as * or X or whatever is applicable. I know the last 4 can be obtained as follows: Code: [Select] $number=substr($number,-4,4); But when i hit the submit button the form validates the input field and checks if the number is a valid number of a specific format. Therefore when I click on the submit button then I should still be able to unmask the masked numbers or do something similar that would help me validate the whole number. Code: [Select] <input type="text" name="no" value="<?php if(!empty($number)){ echo $number;} ?>"> This is my preg_match code:
preg_match("/(\d+)|(T)|(A)/", $link, $matches, PREG_OFFSET_CAPTURE, ($off-30)
It works and matches the number I want, except it only returns the first character in the $matches array. For instance, if the number it finds is 10, it only returns 1. Now I understand that is what preg_match does, but how would I make that regex ungreedy? I tried adding a *, but it just made an error, and preg match all would keep searching for strings after the first one. All I want is for the first number, regardless of the length of it, to be returned in full. Thanks for any help.
Hey I have a string that looks like the following: Quote top-php-tutorials-2.html I have a script that cycles through each page. The 2 in the quote above is the page number. How can I extract the number between the - and the .html and replace it with another number? I've tried Code: [Select] substr($engine->selectedcaturl, 0,-6).$v.".html"But then I realised this only works for numbers that are 1 digit long Any input would be appreciated My code keeps giving me and error on 22 saying: Warning: mysqli_stmt_bind_param() [function.mysqli-stmt-bind-param]: Number of variables doesn't match number of parameters in prepared statement in E:\xampp\htdocs\m9\findRecords2.php on line 22 Code: [Select] <html> <head> <title>Display Records</title> </head> <body> <?php $conn = new mysqli("localhost", "proxy_user", "my*password", "m9"); if (mysqli_connect_errno()){ echo 'Cannot connect to database: ' . mysqli_connect_error($conn); } else{ //read keyword from user if(!empty($_POST["keyword"])){ $keyword = $_POST["keyword"]; // create prepared statement if ($query = mysqli_prepare($conn, "SELECT FirstName, LastName, Age, Hometown, Job FROM people WHERE age <='" . $keyword ."' " )) { // bind parameters mysqli_stmt_bind_param ($query, "i", $keyword); //run the query and keep results in $result variable mysqli_stmt_execute($query); // bind variables to prepared statement mysqli_stmt_bind_result($query, $FirstName, $LastName, $Age, $Hometown, $Job); // fetch values while (mysqli_stmt_fetch($query)) { echo "<strong>$LastName, $FirstName</strong> from $Hometown<br/>age: $Age, occupation: $Job <br/><br/>"; } //free memory used by a result handle mysqli_stmt_close ($query); } else //problem with a query echo "Error: " . mysqli_error($conn); } else { //no keyword echo "No keyword was specified"; } mysqli_close($conn); } ?> </body> </html> keyword and age are ints can anybody please help Hey everyone, I'm new to PHP so excuse me if this is an obvious question: I've got a horizontal scrolling image gallery as an include, as it will be used in dozens of pages. Each page that includes the image gallery will be using different pictures and in different numbers (anywhere from 1 - 15 images). In each page that includes the image gallery, I've turned each image to be used into a variable.. $image 1 = "images/image1.jpg"; $image 2 = "images/image2.jpg"; ... $image 7 = "images/image7.jpg"; etc. Now, I imagine I need to write a loop in the include that will account for as many pictures as there are variables in each page, without adding links for variables that aren't in the page in question. Something like (simplified): Defined on page: $image 1 = "images/image1.jpg"; $image 2 = "images/image2.jpg"; $image 3 = "images/image3.jpg"; $image 4 = "images/image4.jpg"; Loop in photo gallery include: <?php for($i = 1; $i <=15; $i++) { $imagei = ("$" ."image".$i); if (defined($imagei)) { echo '<li><a href="' .$imagei.'">'; echo '<img src=" '.$imagei.'" >'; echo '</a></li>'; } } ?> I know this doesn't work because $imagei isn't referring to the defined variables on the external page, but I'm not sure exactly where to go from here. As in, $imagei in the first execution of the loop is equal to "$image1", but how do I link that to the $image1 variable defined in the page (as "image/image1.jpg") to display the image? Does that make sense? Thanks! hello, i have a start time and an end time (no dates). the following works great, except for when the start time is at night, and the end time is in the morning. im thinking if i can do an if the number is negative, add 24, that it will resolve my issue. any ideas? Code: [Select] $tbilled = $tfinish - $tstart; Hi all, I'm trying to build a simple shopping cart, there are only 8 products and I want to save the quantity value into a section for each product (product1, product2, etc). I'm having a problem where the I can't get the session value to increase by one if the same item is added to the cart again. Here is the code I have so far, am I missing something or is there a php setting that would cause this not to work. <?php session_start(); // setup if(!isset($_SESSION['product1'])) $_SESSION['product1'] = 0; if(!isset($_SESSION['product2'])) $_SESSION['product2'] = 0; if(!isset($_SESSION['product3'])) $_SESSION['product3'] = 0; if(!isset($_SESSION['product4'])) $_SESSION['product4'] = 0; if(!isset($_SESSION['product5'])) $_SESSION['product5'] = 0; if(!isset($_SESSION['product6'])) $_SESSION['product6'] = 0; if(!isset($_SESSION['product7'])) $_SESSION['product7'] = 0; if(!isset($_SESSION['product8'])) $_SESSION['product8'] = 0; // add product if(mysql_escape_string($_GET['add']) != '') { $addItem = mysql_escape_string($_GET['add']); $_SESSION["product$addItem"] = $_SESSION["product$addItem"] + 1; } echo "product$addItem = ".$_SESSION["product$addItem"]; ?> Thanks! Hi there, I need a PHP number format to match one and all of these sequence of numbers: 8500.00 9999.99 15.00 0.00 Hi all I am trying to print a pattern shown below: 1 23 456 7891011 1213141516 17181920 212223 2425 26 Any know how to do it? I'm a bit stuck, I completed it with asterix. I am trying to create a registration form where users put their name, email and password only.
but i want to write an auto generated account number into database table for each user e.g; XY1234567 where XY should not change 1234567 auto generated random number and no duplicates (in numbers only).
example...
XY1234567
XY2345678
XY2233455
i found code
$num_of_ids = 10000; //Number of "ids" to generate. $i = 0; //Loop counter. $n = 0; //"id" number piece. $l = "AAA"; //"id" letter piece. while ($i <= $num_of_ids) { $id = $l . sprintf("%04d", $n); //Create "id". Sprintf pads the number to make it 4 digits. echo $id . "<br>"; //Print out the id. if ($n == 9999) { //Once the number reaches 9999, increase the letter by one and reset number to 0. $n = 0; $l++; } $i++; $n++; //Letters can be incremented the same as numbers. Adding 1 to "AAA" prints out "AAB". }but its not working as i want. Any help please? Edited by 684425, 27 December 2014 - 12:58 PM. Hi I have this code and when I echo the count it shows 1 when theres actually 5. Have I wrote it wrong $loginsq = mysql_query("SELECT email FROM logindetails WHERE email = ".$_SESSION['MM_Username'].""); $logins = mysql_fetch_array($loginsq); $logs = count($logins); echo $logs; Hi Guys I have a code what inserts very simple queries to database, im trying to add a random reference number for each enrty using $reference = rand(111111111111,999999999999); but each time I add an entry it gives me the same random number previously generated for previous entry can you help pleasE? Hi all. I am trying to add 1 to a number. The problem I have is that the number is 4 digits long. So for example the number could be 0007. I add one and it returns 8. I need it to return 0008. Code: [Select] <?php $next = 0007 + 1; echo $next; ?> Can anyone show me how I can get the number to be 4 digits? Thank you $insertCount=0; foreach($results[1] as $curName) { if($insert){$insertCount++;} echo <<< END $curName<BR> END; } Right now the results would show up as... Bill Fred Jessica James John How do you make them show up like... 1 Bill 2 Fred 3 Jessica 4 James 5 John Hi all, i have this records that coming from the database: 0 0 0 1 1 1 1 1 0 0 1 1 1 1 1 1 i want to build a loop that will do like that: if ($res==0) {$res11==number} if ($res was allready 0 ignore it) if ($res==1 ignore it and all other $res=1 and wait till it's $res=0 again if ($res==0 again) { $res11==newnumber } please guide me to doing that, im stuck! thanks Hey forum! I am currently developing a number search and I need some help creating a way to show similar results... For example if someone searches "2009" and there is no result for "2009" is there a way for me to query the database with "2007", "2008", "2010", "2011", etc. until I find a result? Any help would be greatly appreciated. I have to do an assignment for school where I create an html page and a separate page for php. The code is to sum two numbers and return an error if the value entered is not numeric. The sum portion is working; however the numeric validation is not. The code is he
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Enter your information in the form below</title> </head> <body> <!-- Form2.html --> <form action="Form2.php" method="post"> <fieldset><legend> Enter a number in the form below:</legend> <p><b>number 1: <input type="text" name="number1" size="4" maxlength="4" /></b></p> <p><b>number 2: <input type="text" name="number2" size="4" maxlength="4" /></b></p> </fieldset> <div align="center"><input type="submit" name="submit" value="Submit"/></div> </form> </body> </html> <html> <body> <?php $number1 = $_POST['number1']; $number2 = $_POST['number2']; $sum = $number1+$number2; if (!empty($number1)&& !empty($number2)) { if(!is_numeric($number1)) { echo "The value you entered for number 1 is not a number. Please enter a numeric value for number 1"; } else if(!is_numeric($number2)) { echo "The value you entered for number 2 is not a number. Please enter a numeric value for number 2"; } else { echo "The sum of the numbers is: ".$sum; } } ?> </body> </html> One more question to ask. I'm trying to do a count of total logins that have happened in the last 5 months including the current one so far. My users_logins table has the following structu users_id, session_id, login_date(datetime), last_activity(datetime). What the end result is going to be is: <tr> <td></td> <th scope="col"><?php echo date("M", strtotime("-4 month")); ?></th> <th scope="col"><?php echo date("M", strtotime("-3 month")); ?></th> <th scope="col"><?php echo date("M", strtotime("-2 month")); ?></th> <th scope="col"><?php echo date("M", strtotime("-1 month")); ?></th> <th scope="col"><?php echo date("M"); ?></th> </tr> <tr> <th scope="row">Logins</th> <td>94</td> <td>53</td> <td>124</td> <td>92</td> <td>105</td> </tr> Where the first td would be May and the last td would be September. Do I have to do this in 4 separate queries. If so here's what I have for the first query. I'm not sure what woudl go for the WHERE. $four_months_ago_query = "SELCT COUNT(date_login) FROM users_logins WHERE ? "; |