PHP submit button causes strang url issue -


i working on php search box, it's supposed work database find keywords. when click search button though thing changes url, have looked on code dozen times , can't seem find error. thought has in name "searchsubmitbutton", have made absolutely sure correct everywhere. have found few other spelling errors, i'm sure there must 1 i'm missing.

here imgur shows happens can see url changes, nothing else prints should.

edit: i'm sorry absent minded forgot post code.

index.php

<?php  require("./config.php");  if (isset($_post['searchsubmitbutton'])) { // if form has been submitted     if (!isset($_post['searchtext']) || empty($_post['searchtext'])) { //if search text wasn't set         die("<strong>error:</strong> search text empty");     } else {         $searchtext = $mysql->real_escape_string($_post['searchtext']);          $query = $mysql->query("select * `products` `product` '%" . $searchtext . "%'");          if ($query->num_rows) { // if @ least 1 row has been returned             print("<h3>results:</h3>\n");             print("<table id=\"resultstable\">\n");              print("<th>item number</th>\n");             print("<th>product</th>\n");             print("<th>price</th>\n");              while ($product = $query->fetch_assoc()) {                 print("<tr>\n");                  print("<td>" . $product['id'] . "</td>\n");                 print("<td>" . $product['product'] . "</td>\n");                 print("<td>" . $product['price'] . "</td>\n");                  print("</tr>\n");             }             print ("</table>\n");         } else { // if nothing has been returned             print("<h3>sorry, there no products matching search.</h3>\n");         }     } }  print("<h2>search products</h2>\n"); print("<form id=\"searchform\" action=\"./\" methond=\"post\">\n"); print("<input id=\"searchtext\" name\"searchtext\" type=\"text\" /><br /><br />\n"); print("<button id=\"searchsubmitbutton\" name=\"searchsubmitbutton\" type=\"submit\">search</button>\n"); print("</form>") ?> 

config.php

<?php  $dbhost = "localhost"; $dbuser = "root"; $dbpass = ""; $dbname = "test1";  $mysql = new mysqli($dbhost, $dbuser, $dbpass, $dbname);  if ($mysql->connect_error) {     die("<strong>error: </strong> (" . $mysql->connect_errno . ")" . $mysql->connect_error); } else {     print("<strong>successfully connected database.</strong><br /><br />"); } ?> 

the problems causing code fail these:

methond=\"post\" 

which contains typo. change to:

method=\"post\" 

also, missing equal sign in

name\"searchtext\" 

change to

name=\"searchtext\" 

and code work.

sidenote: may want change action=\"./\" action=\"\" or action='' given you're executing same page.


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -