PHP - (basic) Searching Database For Entry
Hey guys, im new around here, and i have just recently started teaching myself PHP, by looks of this site i seem very experienced but im eager to learn
I seem to get an error with this code. The point of this code is to look into my database and pull out all entries with the first name _____ (whatever the user inputs) Error: Warning: mysql_fetch_array() expects parameter 1 to be resource, null given in C:\xampp\htdocs\searchans.php on line 12 Code: Filename:search.php Code: [Select] <html> <form action='searchans.php' method='POST'> First Name: <input type='text' name='firstname'><br> <input type='submit' value='Search'> </form> </html>Code: Filename:searchans.php Code: [Select] <?php $firstname = $_POST['firstname']; $con = mysql_connect("localhost","peter","abc123"); if (!$con) { die('Could not connect: ' . mysql_error()); } $query = mysql_query("SELECT * FROM Persons WHERE FirstName='$firstname'"); while($row = mysql_fetch_array($result)) { echo $row['FirstName'] . " " . $row['LastName'] . " " . $row['Age']; echo "<br />"; } ?> Similar TutorialsHello,
I've tried to get a dynamic table from an external page, and searching for entries in it, so i used a dynamic XLS file using php excel reader. I only exported the file, but i couldn't search for data.
Can i get some help please ?
i'm trying to get the username of the last person to enter something into a database table,and display it an html table. the problem is, the query is failing, and i get the error "Table 'forum.posts' doesn't exist". if in the error message "forum" means the name of the database, and "posts" the name of the table, there is something wrong, as they both exist. the code i'm using is below $list = "SELECT * FROM section_main ORDER BY section_title"; $result = mysql_query($list) or die ("Query failed"); $numofrows = mysql_num_rows($result); for($j = 0; $j < $numofrows; $j++) { $row = mysql_fetch_array($result); echo "<tr><th>". $row['section_title']."</th></tr>"; $query2 = "SELECT * FROM section_sub WHERE section_id = '".$row['section_id']."' ORDER BY section_sub_title"; $result2 = mysql_query($query2) or die("Select Error :" . mysql_error()); $numofrows2 = mysql_num_rows($result2); for($i = 0; $i<$numofrows2; $i++){ $row2 = mysql_fetch_array($result2); echo "<tr><td><a href='display_forum.php?id={$row2[section_sub_id]}'>".stripslashes($row2[section_sub_title])."</a></td><td>"; $new = mysql_query("Select * FROM posts WHERE section_sub_id = '".$row2['section_sub_id'] . " ' ") or die ("Select Error :" . mysql_error()); //this is where the error message is from $lastpost = mysql_fetch_assoc($new); echo $lastpost['username']; echo"</td></tr>"; } } i've checked that the names of the tables and fields in the queries are correct, but i cant think of anything else that might be wrong. any help would be great. i'm working on a project that stores records of architecture and architects. What i have to do is create a way for users to search the records in a simple way. The user can search by Building name, Architect, Location, Date it was built, Building type and architecture style. Currently i can only search properly by building name, date, type and style. If i add architect to the search query the records screw up when i try to search for the other fields individually..so for example if i add the architect to the query and try to only search by building name the results get screwed up and it displays more results that don't have nothing in comon rather than just display one result which would be the building name Like i said this only happens if i add the "architect" to the query Since the architect, location, date, type and style are stored in different tables i search for them first and get the id. Once i've grabbed the ID for those fields i do the actual search to get the buildings that match those records by ID In the actual query i use the OR statement to search all 5 fields regardless if the user left them empty. So if th user only searches for a building name it the query will basically search for the buildingID OR the rest of the fields as well. I hope someone here can help me figure out why when i add the architect field to the query the results get screwed up. I have the code displayed below: <?php if(isset($_POST['search'])){ $building = mysql_real_escape_string($_POST['building']); $architect = stringForUrl($_POST['architect']); $date = mysql_real_escape_string($_POST['date']); $style = mysql_real_escape_string($_POST['style']); $type = mysql_real_escape_string($_POST['type']); $find_building = mysql_query("SELECT * FROM points WHERE name LIKE '$building'") or die(mysql_error()); $tmp_building = mysql_fetch_assoc($find_building); $buildingID = $tmp_building['id']; $find_architect = mysql_query("SELECT * FROM architects WHERE full_name LIKE '$architect'") or die(mysql_error()); $tmp_architect = mysql_fetch_assoc($find_architect); $architectID = $tmp_architect['id']; $find_style = mysql_query("SELECT * FROM styles WHERE name LIKE '$style'") or die(mysql_error()); $tmp_style = mysql_fetch_assoc($find_style); $styleID = $tmp_style['id']; $find_type = mysql_query("SELECT * FROM types WHERE name LIKE '$type'") or die(mysql_error()); $tmp_type = mysql_fetch_assoc($find_type); $typeID = $tmp_type['id']; } ?> <?php if(isset($_POST['search'])){ $session_arch_id = $_SESSION['architect_id']; //query that does the actual search $get_search_points = mysql_query("SELECT * FROM points WHERE id='$buildingID' OR style_id='$styleID' OR type_id='$typeID' OR architect_id='$architectID' OR date='$date' ORDER BY name") or die(mysql_error()); $num_search_points = mysql_num_rows($get_search_points); print($get_search_points); ?> <h3>Architecure on the map</h3> <span id="num_buildings">Showing <?php echo $num_search_points; ?> buildings</span> <table width="605" cellspacing="0" cellpadding="5" border="0" id="wam_results-tbl"> <tr class="search_headings"> <td width="156">Building Name</td> <td width="114">Architect</td> <td width="45">Date</td> <td width="144">Building Type</td> <td width="96">Style</td> </tr> <?php while($points = mysql_fetch_assoc($get_search_points)){ $point_type_id = $points['type_id']; $point_style_id = $points['style_id']; $point_architect_id = $points['architect_id']; $point_firm_id = $points['firm_id']; ?> <tr> <td><?php echo $points['name']; ?></td> <td> <?php if(!empty($point_architect_id)){ $get_architect = mysql_query("SELECT * FROM architects WHERE id='$point_architect_id'") or die(mysql_error()); $architect = mysql_fetch_assoc($get_architect); echo ''.$architect['first_name'].' '.$architect['last_name'].''; }elseif(empty($point_architect_id)){ $get_firm = mysql_query("SELECT * FROM firms WHERE id='$point_firm_id'") or die(mysql_error()); $firm = mysql_fetch_assoc($get_firm); echo $firm['name']; } ?> </td> <td><?php echo $points['date']; ?></td> <td> <?php $get_types = mysql_query("SELECT * FROM types WHERE id='$point_type_id'") or die(mysql_error()); $type = mysql_fetch_assoc($get_types); echo $type['name']; ?> </td> <td> <?php $get_styles = mysql_query("SELECT * FROM styles WHERE id='$point_style_id'") or die(mysql_error()); $style = mysql_fetch_assoc($get_styles); echo $style['name']; ?> </td> </tr> <?php } ?> </table> <?php } ?> so ik you cna get a search box to search items or text in a database, but what i want to know is how to manually insert text and images into it example image (imagine its an image) text name - text price how would i do this? I'm working on an old cms I built a few years ago and for some reason my Delete page isn't working. It has to be something simple I'm overlooking. The database connection is made just above this code and is pulling the thumb and title listed by id. When I push delete I'm getting the cmd=delete&id=2 passed on so something is up with my last if statement (I think). Here is the code: if(!isset($cmd)) { //display all the news $result = mysql_query("select * from verizon order by id"); //run the while loop that grabs all the news scripts while($r=mysql_fetch_array($result)) { //grab the title and the ID of the enws $title=$r["title"];//take out the title $id=$r["id"];//take out the id $thumb=$r["thumb"]; echo "<div id='delete'> <table> <tr> <td width='350px'><strong>$title</strong></td><td><a href='verizondelete.php?cmd=delete&id=$id'> Delete</a></td> </tr> <td colspan='2' align='center'><img src='../upload/verizon/$thumb'></td> </table> </div><br />"; } } if($cmd=="delete") { $sql = "DELETE FROM verizon WHERE id='$id'"; $result = mysql_query($sql); echo "<h1 style='text-align:center;'>deleted!</h1>"; } } ?> Hi everyone, I need a little bit of help finishing off my code. Ive managed to get this far. Code: [Select] <?php mysql_connect("") or die ("Not Connected to MYSQL"); echo "</br>"; mysql_select_db("") or die ("Not Connected to DB"); // Database Connection stuff $partialNumber = $_POST['partialNumber']; // Post the Partial number $partialNumber = strtoupper($partialNumber); $numberSearch = mysql_query("SELECT * FROM product_option_value_description WHERE name LIKE '%$partialNumber%'") or die (mysql_error()); // Query to select the key number //Query to get product ID // $productId = "SELECT product_id FROM product_option_value_description"; //Query to get product ID // while ($keyNumber = mysql_fetch_array($numberSearch)) { $id = $keyNumber['product_id']; // Query for the images // $query = "SELECT image FROM product WHERE product_id = '$id'"; $result = mysql_query($query); $row = mysql_fetch_array($result) or die(mysql_error()); $query2 = "SELECT product_option_id FROM product_option_value WHERE product_id = '$id'"; $result2 = mysql_query($query2); $row2 = mysql_fetch_array($result2) or die(mysql_error()); $query3 = "SELECT product_option_value_id FROM product_option_value WHERE product_id = '$id'"; $result3 = mysql_query($query3); $row3 = mysql_fetch_array($result3) or die(mysql_error()); ?> <div> <br /><br /> Key Number: <? echo $keyNumber['name']; ?></a> <form action="http://www.co.uk/teststore/index.php?route=checkout/cart" method="post" enctype="multipart/form-data" id="product"> <br /> <table style="width: 100%;"> <tr> <td> Colour: <select name="option[<? echo $row2['product_option_id']; ?>]"> <option value="<? echo $row3['product_option_value_id']; ?>"></option> </select></td> </tr> </table> <div class="content"> Qty: <input type="text" name="quantity" size="3" value="1" /> <input type="hidden" name="product_id" value="<? echo $id; ?>" /> <input name="submit" type="submit" value="Add to Cart" /> </div> </form> <? echo $row3['product_option_value_id']; ?> </div> <br /> <img height="150" width="150" src='http://www.co.uk/teststore/image/<? echo $row['0']; ?>'/> <? } ?> And here is my SQL Table code. Code: [Select] product_option_value_id product_option_id product_id 599 302 49 598 302 49 589 297 42 588 297 42 So as you can probably tell, it is a search program that looks for products on a shopping cart. The products will have different option values, and the php script will grab the option values and echo them in a form to post back to the cart to add the product to the basket. The problem is that the "product_option_value_id" can have lots of different values, but my code echos only the first one it finds. So when I click the add to cart button, it will only add the first option value for the product it finds. For some reason I am having a hard time explaining this, so I hope someone can help me. Thanks for looking. Hi I'm very much a newbie to PHP and am struggling with a registration and login problem. The registration part is fine - the password is emailed out fine, I check the database and the entry is there, the password is encrypted. but when the user tries to log in.... if (mysql_num_rows($result) == 0) .... it returns 0? and the access denied page is shown. I'm thinking it is something to do with the sql database encryption? I'm completely lost here and would appreciate some guidance Thanks in advance Jan Hello, I have this code running and I keep getting "Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in /home/.../search.php on line 10 Any help would be appreciated <table><tr><td>ID</td><td>SCHOOL NAME</td><td>TEACHER NAME</td></tr> <?php if(isset($_POST['submit'])){ if(isset($_GET['go'])){ if(preg_match("/^[ a-zA-Z]+/", $_POST['name'])){ $name=$_POST['name']; $db=mysql_connect ("", "", "") or die ('I cannot connect to the database because: ' . mysql_error()); $mydb=mysql_select_db(""); $sql="SELECT ID, school_name, teacher_name FROM Project_Registration WHERE school_name LIKE '%" . $name . "%'"; $result=mysql_query($sql); while($row = mysql_fetch_array($result, MYSQL_ASSOC)){ echo "<tr><td> {$row['ID']} </td>" . "<td> {$row['school_name']} </td>" . "<td> {$row['teacher_name']} </td></tr>";}}}} ?> </table> I think I've coded myself into a corner. I have numerous items entered with measurement extremes - highest and lowest. Now I want somebody to be able to search for an item that could match a specific length. So I could have several items that are entered into a database like this: Code: [Select] item_id | length | high_low_param -----------+-----------+---------------------- 1234 | 12 cm | high -----------+-----------+--------------------- 1234 | 6 cm | low If somebody searches for an item that is 8 cm long, I want the results to be item 1234 and any other items that span that range. I'm not sure how to do this? array_fill ? I don't know. I don't want to slow down the database too much, and I don't want to have to put an entry for every single length each item could be. Any suggestions? Hi guys, I want a search to be done. That is when the user type the relevant customer id and clicks on search button the details of the customer should appear in a form. Therefore i tried the following code but it generates an empty form. All the customer details were stored in the database under customer table. customer(customer_id, full_name, name_with_initials, address, contact_number, gender) Can anyone show me where i went wrong? <?php $connect=mysql_connect("localhost","root",""); mysql_select_db("bank",$connect) or die ("could not select database"); ?> <!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"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> <style type="text/css"> <!-- #apDiv4 { position:absolute; width:776px; height:598px; z-index:3; left: 206px; top: 300px; } #form1 { font-size: 18px; font-weight: bold; } body,td,th { font-size: 18px; } --> </style> </head> <body> <div id="apDiv4"> <form action="" method="post" name="form1" id="form1"> <fieldset> <legend class="cap"> Customer Details</legend> <table width="85%" height="350" border="0" align="center" cellpadding="5" cellspacing="0"> <?php if(isset($_POST['customer_id'])){ $customer_id=$_POST['customer_id']; $query = "select * from customer where customer_id=" .$customer_id; $result = mysql_query($query) or die(mysql_error()); while ($row=mysql_fetch_array($result)){ } ?> <tr> <td> </td> <td class="title02"> </td> <td> </td> <td> </td> </tr> <tr height="30"> <td width="2%" height="35"> </td> <td width="46%" class="title02" align="left">National ID</td> <td width="50%" class="attribute1" align="left"><input type="text" name="nic" size="30" class="attribute1" value="<?php echo $row['nic'];?>"></td> <td width="2%"> </td> </tr> <tr height="30"> <td height="33"> </td> <td width="46%" class="title02" align="left">Full Name</td> <td width="50%" class="attribute1" align="left"><input type="text" name="full_name" size="30" class="attribute1" value="<?php echo $row['full_name'];?>"></td> <td width="2%"> </td> </tr> <tr height="30"> <td height="34"> </td> <td class="title02" align="left">Name With Initials</td> <td width="50%" class="attribute1" align="left"><input type="text" name="name_with_initials" size="30" class="attribute1" value="<?php echo $row['name_with_initials'];?>"></td> </tr> <tr height="30"> <td width="2%"> </td> <td width="46%" class="title02" align="left">Address</td> <td width="50%" class="attribute1" align="left"><label> <textarea name="address" id="textarea" cols="45" rows="5"><?php echo $row['address']; ?></textarea> </label></td> <td width="2%"> </td> </tr> <tr height="30"> <td width="2%"> </td> <td width="46%" class="title02" align="left">Contact Number</td> <td width="50%" class="attribute1" align="left"><input type="text" name="contact_number" size="30" class="attribute1" value="<?php echo $row['contact_number']?>"></td> <td width="2%"> </td> </tr> <tr height="30"> <td width="2%"> </td> <td width="46%" class="title02" align="left">Sex</td> <td width="50%" class="attribute1" align="left"><p> <select name="gender" id="jumpMenu" > <option selected="selected"><?php echo $row['gender']; ?></option> <option>Male</option> <option>Female</option> </select> <td width="50%" class="attribute1" align="left"> </td> <br /> </p></td> <td width="2%"> </td> </tr> </table> <p align="center"> </p> <p align="center"> <label> </label> <label> <input name="button" type="submit" id="button" value="Approve Account" /> </label> <label> <a href="accsup_help.php"> <input name="button" type="submit" id="button" value="Help" /> </a></label> </td> </p> </fieldset> <td width="5%"> </td> </tr> <tr> <td> </td> <td> </td> <td> </td> </tr> <tr> <td> </td> <td align="center"> </td> <td> </td> </tr> <tr> <td> </td> <td><font color="red" size="1" ></font></td> <td> </td> </tr> <?php } ?> </table> </form> </div> <img src="../images/mahapitiya 1.jpg" width="1024" height="139" /> </body> </html> Thanks, Hello all. I am finishing up a paypal IPN php script and was wondering how I can take some data and cut some of it off before I enter it into the mysql database? Heres what I have. $payment_date = HH:MM:SS DD Mmm YY, YYYY PST This comes from paypal. I want to in my code take that and automatically cut off the HH:MM:SS part. So my question is, how can I take a known piece of data and automatically trim the first 9 spots off of it? Something like: $payment_date = HH:MM:SS DD Mmm YY, YYYY PST Minus 1 thru 9 of $payment_date = $result $payment_date2 = $result Any help? Thanks! Hi, Would someone please give me some assistance on how to display random products from my database I need to display a maximum of 6 images and there link in two rows of 3 so; [image] [image] [image] [image] [image] [image] and each image would have something like; <a href="<? echo $row['product_link'] ?>"><img src="<? echo $row['product_image'] ?>"/></a> but i don't know how to display these at random and make sure only 6 appear at a time. Thanks for any help, hope you understand what im trying to explain No errors come up when I run this but it just doesn't delete the entry. <? $rec = $_POST['stock']; if (!$rec){ die ('Please eneter a stock number'); } $link = mysql_connect("xxxx","xxx","xxx"); mysql_select_db('wadkin', $link) or die( "Unable to select database"); mysql_query("DELETE FROM 'wadkin'.'stocklist' WHERE 'stocklist'.'Stock Number' = $rec") or die ('Query failed'); mysql_close($link); ?> Can someone please correct, (btw I have also tried... "DELETE FROM stocklist WHERE 'Stock Number' = $rec") Hello. I have been following a great tutorial that I found here regarding searching a database: Tutorial: http://www.phpfreaks.com/tutorial/simple-sql-search I was very happy to find and implement this as I have been looking to understand this for some time now. When I used this and ran it from my server (doing a search of the database), I bookmarked the page; my question relates to the next step: When I return to the page via the bookmark the actual search has been saved and is displayed, not just the search form. I do not understand this. This is the search page as noted (search term is "kim"): http://bluelinedown.netau.net/new_test.php?search=Kim&body=on&title=on&desc=on&matchall=on&submit=Search! I need it to be so that each time a user goes to this search page, no prior search is displayed and it is, of course, available for a new search. Is this issue related to sessions? And if so, how? Below is the actual code I am using for this search function/page: <?php /***************************** * Simple SQL Search Tutorial by Frost * of Slunked.com ******************************/ $dbHost = 'mysql7.000webhost.com'; // localhost will be used in most cases // set these to your mysql database username and password. $dbUser = '********'; $dbPass = '*******'; $dbDatabase = 'a4542527_test1'; // the database you put the table into. $con = mysql_connect($dbHost, $dbUser, $dbPass) or trigger_error("Failed to connect to MySQL Server. Error: " . mysql_error()); mysql_select_db($dbDatabase) or trigger_error("Failed to connect to database {$dbDatabase}. Error: " . mysql_error()); // Set up our error check and result check array $error = array(); $results = array(); // First check if a form was submitted. // Since this is a search we will use $_GET if (isset($_GET['search'])) { $searchTerms = trim($_GET['search']); $searchTerms = strip_tags($searchTerms); // remove any html/javascript. if (strlen($searchTerms) < 3) { $error[] = "Search terms must be longer than 3 characters."; }else { $searchTermDB = mysql_real_escape_string($searchTerms); // prevent sql injection. } // If there are no errors, lets get the search going. if (count($error) < 1) { $searchSQL = "SELECT id, name, descrip FROM people WHERE "; // grab the search types. $types = array(); $types[] = isset($_GET['id'])?"`id` LIKE '%{$searchTermDB}%'":''; $types[] = isset($_GET['name'])?"`name` LIKE '%{$searchTermDB}%'":''; $types[] = isset($_GET['descrip'])?"`descrip` LIKE '%{$searchTermDB}%'":''; $types = array_filter($types, "removeEmpty"); // removes any item that was empty (not checked) if (count($types) < 1) $types[] = "`name` LIKE '%{$searchTermDB}%'"; // use the body as a default search if none are checked $andOr = isset($_GET['matchall'])?'AND':'OR'; $searchSQL .= implode(" {$andOr} ", $types) . " ORDER BY `name`"; // order by title. $searchResult = mysql_query($searchSQL) or trigger_error("There was an error.<br/>" . mysql_error() . "<br />SQL Was: {$searchSQL}"); if (mysql_num_rows($searchResult) < 1) { $error[] = "The search term provided {$searchTerms} yielded no results."; }else { $results = array(); // the result array $i = 1; while ($row = mysql_fetch_assoc($searchResult)) { $results[] = "{$i}: {$row['id']}<br />{$row['name']}<br />{$row['descrip']}<br /><br />"; $i++; } } } } function removeEmpty($var) { return (!empty($var)); } ?> <html> <title>My Simple Search Form</title> <style type="text/css"> #error { color: red; } </style> <body> <?php echo (count($error) > 0)?"The following had errors:<br /><span id=\"error\">" . implode("<br />", $error) . "</span><br /><br />":""; ?> <form method="GET" action="<?php echo $_SERVER['PHP_SELF'];?>" name="searchForm"> Search For: <input type="text" name="search" value="<?php echo isset($searchTerms)?htmlspecialchars($searchTerms):''; ?>" /><br /> Search In:<br /> Body: <input type="checkbox" name="body" value="on" <?php echo isset($_GET['body'])?"checked":''; ?> /> | Title: <input type="checkbox" name="title" value="on" <?php echo isset($_GET['title'])?"checked":''; ?> /> | Description: <input type="checkbox" name="desc" value="on" <?php echo isset($_GET['desc'])?"checked":''; ?> /><br /> Match All Selected Fields? <input type="checkbox" name="matchall" value="on" <?php echo isset($_GET['matchall'])?"checked":''; ?><br /><br /> <input type="submit" name="submit" value="Search!" /> </form> <?php echo (count($results) > 0)?"Your search term: {$searchTerms} returned:<br /><br />" . implode("", $results):""; ?> </body> </html> Thank-you in advance for any help or explanation as to what to do next. ~Matty Hello PHPfreaks members, I want my PHP coding to read/fetch my database's first attribute/entry like the first number of the client in that first row and then fetch it to be shown on PHP so that it will show '1'. How would I do that? Here's the table of my example database (MySQL) I know the command to select the line via the database is this: SELECT * FROM CUSTOMER WHERE CUST_NO=1; hey guys, I'm getting a problem uploading my csv file to mysql database, the code on the top half just makes sure that I don't import data that I don't want into the database, numbers that are too high or too low on certain rows, and the second half is importing the array that I create from the csv file into the database however I'm getting the following error
Duplicate entry 'Array' for key 'strProductCode'
Now I've never had this error before and I'm not sure what's causing it so any help would be very much appreciated
$data = array(); if (($handle = fopen("stock.csv", "r")) !== FALSE) { while (($row = fgetcsv($handle, 1000, ",")) !== FALSE) { // only add rows to the array where the 4th column value is greater than or equal to 10 if(($row[3] >= 10 && $row[4] >= 5) OR ($row[3] >= 0 AND $row[4] > 5)){ if($row[4] < 1000){ $data[] = $row; } } } foreach ($data as &$value) { mysql_query("INSERT INTO tblProductData (intProductDataId, strProductCode, strProductName, strProductDesc, strProductStock, strProductCost, dtmDiscontinued, dtmAdded, stmTimestamp) VALUES(null, '$data[0]', '$data[1]', '$data[2]', '$data[3]', '$data[4]', 'time', 'added', 'time') ") or die(mysql_error()); } } Hello there,
I would be really grateful if someone could advice please, how do I find this pesky entry in the 'db' table? This is what it says,
"Found an entry in the 'db' table with empty database name; Skipped." MySQL version is 5.5.40
I am pretty much stuck on it. Does it mean the table's name is db? Plus, I am not sure I understand the wording of it too. The empty database name cannot exist by default as it won't allow you to create a database without a name in the first place. I do not even know how and where to begin to look for it because honestly speaking I do not quite understand the phrase itself, because it does not make much sense to me. I would really highly appreciate it if someone could explain and suggest how do I find the... "whatever it says" :-) and to fix it. Many thanks in advance!
P.S. I know this warning may easily and safely be ignored as it is of minor inconvenience and not that important the more so as MySQL is working fine but my curiosity is just running wild for two reasons: 1. I do not really understand what this warning message is trying to tell me and 2. How do I find and adjust it to turn off the warning.
Simple regular things as running myisamchk -r *.MYI on where MySQL is did not help as this warning is actually out of scope of what myisamchk can fix.
And yes, I've Googled it long enough but couldn't seem to come up with anything reasonable solutions.
Thankful for any suggestions / pointers / assistance / comments at all.
Edited by Klaipedaville, 29 October 2014 - 06:17 AM. I'm creating a newsletter and the unsubscribe isn't deleting the database entry like I'm asking it to. Everything else works fine, it even successfully says the user has been removed, but it doesn't actually delete the database entry. I've spent two days trying to figure out why. Here's the code:
Newsletter sign up: <?php //DB Connect Info $servername = ""; $database = ""; $username = ""; $password = ""; // Create connection $conn = mysqli_connect($servername, $username, $password, $database); // Check connection if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } /*$createTable = $conn->prepare ("CREATE TABLE IF NOT EXISTS email_user ( id int(11) NOT NULL AUTO_INCREMENT, email varchar(200) NOT NULL, hash varchar(250) NOT NULL, PRIMARY KEY (id) )"); $createTable->execute(); */ function input_security($data) { $data = trim($data); $data = stripslashes($data); $data = htmlspecialchars($data); return $data; } $email = input_security($_POST['email']); $insertData = input_security($insertData); if(isset($_POST['submit'])) { extract($_POST); if($email!="") : $email=mysqli_real_escape_string($conn,$email); $emailval = '/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$/'; if(preg_match($emailval, $email)) : $db_check=$conn->query("SELECT * FROM email_user WHERE email='$email'"); $count=mysqli_num_rows($db_check); if($count< 1) : $hash=md5($email.time()); $link = '/unsubscribe.php?key='.$hash; // Change your domain $fetch=$conn->query("INSERT INTO email_user(email,hash) VALUES('$email','$hash')"); $to="$email"; //change to ur mail address $strSubject="Maintenance Fee Relief, LLC | Email Subscription"; $message = '<p>Thank you for subscribing with us.</p>' ; $message .= '<p>Click here to unsubscribe your email : <a href="'.$link.'">unsubscribe</p>' ; $headers = 'MIME-Version: 1.0'."\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1'."\r\n"; $headers .= "From: info@"; $mail_sent=mail($to, $strSubject, $message, $headers); $msg_sucess="Your request has been accepted!."; else : $msg="This $email email address is already subscribe with us."; endif; else : $msg="Please enter your valid email id"; endif; else : $msg="Please fill all mandatory fields"; endif; } ?> <div class="newsletter-sign-up-header-form"> <div id="logerror"><?php echo @$msg; ?><?php echo @$msg_sucess; ?></div> <form method="post"> <span><input type="email" name="email" placeholder="Email Address - Join Newsletter" class="newsletter-sign-up-header-email" required></span> <span><button name="submit" value="submit" title="Submit" class="newsletter-sign-up-header-submit-button">Submit</button></span> </form> </div> <?php //DB Connect Info $servername = ""; $database = ""; $username = ""; $password = ""; // Create connection $conn = mysqli_connect($servername, $username, $password, $database); // Check connection if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } ?> <?php if(@$_GET['key']!=""): $hash=mysqli_real_escape_string($conn,$_GET['key']); $fetch=$conn->query("SELECT * FROM email_user WHERE hash = '$hash'"); $count=mysqli_num_rows($fetch); if($count==1) : $row=mysqli_fetch_array($fetch); $conn->query("DELETE email_user WHERE id='$user_id'"); $msg="Your email id unsubscribe with us"; else : $msg="Please click valid link."; endif; else : header("Location:404.php"); endif; ?> <!doctype html> <html lang="en"> <head> <title>Unsubscribe</title> </head> <body> <div align="center"> <h2><?php echo $msg; ?></h2> <a href="https://www.--.com">--.com</a> </div> Quote
I'm making a login area for the hotels in a booking system, where they enter their hotels' information, policy, and room rates but I want to make the room rates when it appears for clients, it appears with a percentage (commission) added to what the Hotel representative will enter So what's better? it should be added in the admin area of the hotels and gets saved in the database with the commission or I should add it in the booking form so the code grab the rate from the database, multiply it by the percentage and echo the result? I am trying to set up a item entry page form.png: Upon submission it shows unsuccessful even though I have checked the fields on mysql table and seem to be good am I missing something? Code: [Select] <form action="" method="post" enctype="multipart/form-data" name="Product_Entry"> <TABLE> <TR> <TD>Product ID</TD><TD><input name="SKU_ProductID" value="<?php if (isset($_post['SKU_ProductID'])) echo $_POST['SKU_ProductID']; ?>" type="text" size="11" maxlength="11" /></TD> </TR> <TR> <TD>Merchant SKU ID</TD><TD><input name="SKU_MerchSKUID" value="<?php if (isset($_post['SKU_MerchSKUID'])) echo $_POST['SKU_MerchSKUID']; ?>" type="text" size="18" maxlength="30" /></TD> </TR> <TR> <TD>Game Title</TD><TD><input name="Game_Title" value="<?php if (isset($_post['Game_Title'])) echo $_POST['Game_Title']; ?>" type="text" size="40" maxlength="40" /></TD> </TR> <TR> <TD>Platform</TD><TD><input name="Platform" value="<?php if (isset($_post['Platform'])) echo $_POST['Platform']; ?>" type="text" size="20" maxlength="20" /></TD> </TR> <TR> <TD>Genre</TD><TD><input name="Genre" value="<?php if (isset($_post['Genre'])) echo $_POST['Genre']; ?>" type="text" size="11" maxlength="11" /></TD> </TR> <TR> <TD>Weight</TD><TD><input name="Weight" value="<?php if (isset($_post['Weight'])) echo $_POST['Weight']; ?>" type="text" size="7" maxlength="7" /></TD> </TR> <TR> <TD>Supplier</TD><TD><input name="Supplier" Value="<?php if (isset($_post['Supplier'])) echo $_POST['Supplier']; ?>" type="text" size="25" maxlength="25" /></TD> </TR> <TR> <TD>Suppliers Price</TD><TD><input name="Supplier_Price" value="<?php if (isset($_post['Supplier_Price'])) echo $_POST['Supplier_Price']; ?>" type="text" size="10" maxlength="12" /></TD> </TR> <TR> <TD>Cashback</TD><TD><input name="Cashback" value="<?php if (isset($_post['Cashback'])) echo $_POST['Cashback']; ?>" type="text" size="6" maxlength="8" /></TD> </TR> <TR> <TD>Cashback Amount</TD><TD><input name="Cashback_Amount" value="<?php if (isset($_post['Cashback_Amount'])) echo $_POST['Cashback_Amount']; ?>" type="text" size="7" maxlength="11" /></TD> </TR> <TR> <TD><input type="hidden" name="submitted" value="true"/></TD><TD><input name="Submit" type="submit" value="Add_Product" /></TD> </TR></form></TABLE> <?php # Product Entry $page_title = 'Product Entry'; if (isset($_POST['Submit'])) { $errors = array(); if (empty($_POST['SKU_ProductID'])) { $errors[] = 'Please enter Product ID.'; } else { $sid = trim($_POST['SKU_ProductID']); } if (empty($_POST['SKU_MerchSKUID'])) { $errors[] = 'Please enter Merchant SKU.'; } else { $mid = trim($_POST['SKU_MerchSKUID']); } if (empty($_POST['Game_Title'])) { $errors[] = 'Please enter Game Title.'; } else { $gt = trim($_POST['Game_Title']); } if (empty($_POST['Platform'])) { $errors[] = 'Please enter Platform.'; } else { $pl = trim($_POST['Platform']); } if (empty($_POST['Genre'])) { $errors[] = 'Please enter Genre.'; } else { $ge = trim($_POST['Genre']); } if (empty($_POST['Weight'])) { $errors[] = 'Please enter Weight.'; } else { $we = trim($_POST['Weight']); } if (empty($_POST['Supplier'])) { $errors[] = 'Please enter Supplier.'; } else { $sup = trim($_POST['Supplier']); } if (empty($_POST['Supplier_Price'])) { $errors[] = 'Please enter Supplier Price.'; } else { $sp = trim($_POST['Supplier_Price']); } if (empty($_POST['Cashback'])) { $errors[] = 'Please enter Cashback %.'; } else { $cb = trim($_POST['Cashback']); } if (empty($_POST['Cashback_Amount'])) { $errors[] = 'Please enter Cashback Amount.'; } else { $cba = trim($_POST['Cashback_Amount']); } if (empty($errors)) { require_once ('connect.php'); [b]$q = "INSERT INTO `Products` (`SKU_ProductID`, `SKU_MerchSKUID`, `Game_Title`, `Platform`, `Genre`, `Weight`, `Supplier`, `Supplier_Price`, `Cashback`, `Cashback_Amount`) VALUES ('$sid', '$mid', '$gt', '$pl', '$ge', '$we', '$sup', '$sp', '$cb', '$cba')"; $r = @mysql_query ($dbc, $q); if ($r) { // If it ran OK. // Print a message: echo '<h1>Thank you!</h1> <p>Product Inserted!</p><p><br /></p>'; } else { // If it did not run OK. // Public message: echo '<h1>System Error</h1> <p class="error">You could not be registered due to a system error. We apologize for any inconvenience.</p>'; // Debugging message: echo '<p>' . mysqli_error($dbc) . '<br /><br />Query: ' . $q . '</p>'; } // End of if ($r) IF. mysqli_close($dbc); // Close the database connection.[/b] // Include the footer and quit the script: include ('includes/footer.html'); exit(); } else { echo '<H1>Error!</H1> <p class="error">The Following error(s) occurred:<br />'; foreach ($errors as $msg) { echo " - $msg<br />\n"; } echo '</p><p>Please try again.</p><p><br /></p>'; } } ?> If there is anything else needed let me know |