PHP - Having Trouble Searching Database With This Code
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> Similar Tutorialsso 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 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 } ?> 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 />"; } ?> 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. 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 i basically have a php search form on a property website, and depending on what area/type of property/number of bedrooms and price range the search form should bring up results based on that. at the moment it just bring up everything. how would i make it bring up the correct results depending on the search made? here my php code: Code: [Select] <!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> <title>Mumtaz Properties</title> <link rel="stylesheet" href="cutouts/style.css"/> </head> <body> <!--Main Div Tag--> <div id="wrapper"> <div id="header"> <div id="logo"><a href="index.html"><img src="cutouts/Homepage/logo.png" alt=""/></a></div> </div> <div id="navigation"> <a id="Home" href="index.html" title="home"><span>home</span></a> <a id="Sale" href="forsale.html" title="for sale"><span>for sale</span></a> <a id="Rent" href="forrent.html" title="for rent"><span>for rent</span></a> <a id="Contact" href="contact.html" title="contact us"><span>contact us</span></a> </div> <div id="main"> <div id="results"><img src="cutouts/Homepage/results.png"></div> <?php $server = ""; // Enter your MYSQL server name/address between quotes $username = ""; // Your MYSQL username between quotes $password = ""; // Your MYSQL password between quotes $database = ""; // Your MYSQL database between quotes $con = mysql_connect($server, $username, $password); // Connect to the database if(!$con) { die('Could not connect: ' . mysql_error()); } // If connection failed, stop and display error mysql_select_db($database, $con); // Select database to use // Query database $result = mysql_query("SELECT * FROM Properties"); if (!$result) { echo "Error running query:<br>"; trigger_error(mysql_error()); } elseif(!mysql_num_rows($result)) { // no records found by query. echo "No records found"; } else { $i = 0; echo '<div style="font-family:helvetica; font-size:14px; padding-left:15px; padding-top:20px;">'; while($row = mysql_fetch_array($result)) { // Loop through results $i++; echo '<img class="image1" src="'. $row['images'] .'" />'; //image echo "<span style=\"color:#63be21;\">Displaying record $i<br>\n<br></span>"; echo "<b>Location:</b> ". $row['Location'] . "<br>\n"; // Where 'location' is the column/field title in the database echo "<b>Property Type:</b> ". $row['Property_type'] . "<br>\n"; // as above echo "<b>Bedrooms:</b> ". $row['Number_of_bedrooms'] . "<br>\n"; // .. echo "<b>Purchase Type:</b> ". $row['Purchase_type'] . "<br>\n"; // .. echo "<b>Price:</b> ". $row['Price_range'] . "<br>\n"; // .. } echo '</div>'; } mysql_close($con); // Close the connection to the database after results, not before. ?> </div> </div> </body> </html> Would like to thank you in advance. I'm trying to do something that I thought was very simple about 2 weeks ago :-( I want to put a form on my site and link it to a database so when a user types a surname into the form they can search the db and the page will only display the surnames that match the search criteria. I got the db set up using phpmyadmin in about 2 minutes flat, but keep getting error messages when I write the php. I'm currently working with the below script, which keeps giving me the error 'unexpected T_string' on line 176 I've searched every forum and help site I can find, and the mysql and php manuals are just mind-boggling. I'm sure I'm making some really amateur mistake, but I'd really appreciate help with this! thanks all! <html> <head> <title>SEARCH RECORDS</title> </head> <body> <FORM NAME ="Search" METHOD ="POST" ACTION = "test3"> <INPUT TYPE = "TEXT" VALUE ="surname" NAME = "surname"> <INPUT TYPE = "Submit" Name = "Search" VALUE = "Search"> </FORM> </body> </html> <? $user_name = "*****"; $password = "*****"; $database = "*****"; $server = "localhost"; $db_handle = mysql_connect($server, $user_name, $password); $db_found = mysql_select_db($database, $db_handle); if ($db_found) { $SQL = "SELECT * FROM *****" WHERE surname=$_POST['surname']; $result = mysql_query($SQL); while ($db_field = mysql_fetch_assoc($result)) { print $db_field['Grave'] . "<BR>"; print $db_field['Surname'] . "<BR>"; print $db_field['Forenames'] . "<BR>"; print $db_field['Death_Date'] . "<BR>"; print $db_field['Birth_Year'] . "<BR>"; } mysql_close($db_handle); } else { print "Database NOT Found "; mysql_close($db_handle); } ?> Hey guys I am trying to read my xml file and itterate through the list. I am having trouble.
<?xml version="1.0" encoding="UTF-8"?> <stock> <itemPlace id="1"> <name>null</name> <image>null</image> <wholeSale>44</wholeSale> <retailPrice>null</retailPrice> <quantity>null</quantity> <location>null</location> <color>null</color> <size>null</size> <weight>null</weight> <description>null</description> <itemType>null</itemType> <date>null</date> </itemPlace> <itemPlace id="2"> <name>null</name> <image>null</image> <wholeSale>55</wholeSale> <retailPrice>null</retailPrice> <quantity>null</quantity> <location>null</location> <color>null</color> <size>null</size> <weight>null</weight> <description>null</description> <itemType>null</itemType> <date>null</date> </itemPlace> </stock> <?php $xml = simplexml_load_file('stock.xml'); foreach ($xml->xpath('itemPlace') as $eq) { echo "<p><a class='inline' href=\"#inline_content\"> {$eq->name}</a></p>"; echo '<br>'; echo " <div style='display:none'>"; echo " <div id='inline_content' style='padding:10px; background:#fff;'>"; echo " <p>"; echo " <strong>{$eq->wholeSale}</strong>"; echo "</div></div>";Is there a way I can look up the object through the itemPlace id="#" and call out the parameters of the item? Like the name price, etc? I know how to mySQL query but not XML, and this is a project that needs to use xml... FML..I have been looking for a few hours so any help would be appreciated! Never worked with GoDaddy before... Can't get my config script to connect to the database. Here's my code (I'm sure all the login info is correct, except maybe the host name but I copied that from GoDaddy too...) <?php ob_start(); // MySQL connection settings $db_host = "anakdesigns.db.2089823.hostedresource.com"; $db_user = "********"; $db_pass = "********"; $db_name = "********"; // Connect to the database $con = mysql_connect($db_host, $db_user, $db_pass) or die("Cannot connect to DB"); mysql_select_db($db_name) or die("Error accessing DB"); ?> http://www.anakdesigns.com/dev Hi guys, i am currently working on a project that queries an inventory database through the use of radio buttons, for example; If the first button FOR THE Item(HAMMERS)is clicked, the output should be the name of the item, the number sold and the total profit(calculations) into a table. the way i have it now, when io click on the radio button my output comes back as the results for all the items in the table, i want it to display only the information about hammers, then only about each individual item when the corresponding radio button is clicked. any help would be greatly appreciated!!! Hey guys, I have made an admin page for a game Im working on to quickly allow me to update many aspects of the game. My form is sending the correct data because i can echo the $_post but for some reason it isnt updating my database. I just get a blank white page. Could anyone see what i have done wrong. Thanks Code: [Select] <?php require($DOCUMENT_ROOT . "/game/includes/connection.php"); require($DOCUMENT_ROOT . "/game/includes/settings.php"); ?> <?php $name = $_POST['admin_name']; $img = $_POST['admin_img']; $current_hp = $_POST['admin_current_hp']; $max_hp = $_POST['admin_max_hp']; $current_energy = $_POST['admin_current_energy']; $max_energy = $_POST['admin_max_energy']; $level = $_POST['admin_level']; $exp_total = $_POST['admin_exp_total']; $exp = $_POST['admin_exp']; $exp_level = $_POST['admin_exp_level']; $pos_x = $_POST['admin_pos_x']; $pos_y = $_POST['admin_pos_y']; $potion = $_POST['admin_potion']; $ether = $_POST['admin_ether']; $elixir = $_POST['admin_elixir']; $zenni = $_POST['admin_zenni']; $sector = $_POST['admin_sector']; $battle = $_POST['admin_battle']; ?> <?php $sql_1 = "UPDATE game_character SET name='$name', img='$img', current_hp='$current_hp', max_hp='$max_hp', current energy='$current_energy', max_energy='$max_energy', level='$level', exp_total='$exp_total', exp='$exp', exp_level='$exp_level', pos_x='$pos_x', pos_y='$pos_y', potion='$potion', ether='$ether', elixir='$elixir', zenni='$zenni' WHERE id=1"; $sql_2 = "UPDATE game_status SET sector='$sector', battle='$battle' WHERE id=1"; $statement_1 = $dbh->prepare($sql_1); $statement_2 = $dbh->prepare($sql_2); $statement_1->execute(); $statement_2->execute(); ?> <SCRIPT LANGUAGE="JavaScript"> redirTime = "1"; redirURL = "<?php echo $r_admin ?>"; function redirTimer() { self.setTimeout("self.location.href = redirURL;",redirTime); } </script> <BODY onLoad="redirTimer()"> First time poster, and very amateur php coder. I am trying to delete items that in a list using ajax. I can't figure out what I am doing wrong. Any help would be greatly appreciated!
Here is a snippet of my javascript... $('.delete-item').click(function() { var itemID = $(this).data('itemID'); var clear = 1; $.ajax({ url: 'includes/delete-item.php', method: 'POST', data: { itemid:itemID, clear:1 }, success: function(data) { $('.content').load('includes/lists.php') } }) })
and here is the relevant php... $item = $_POST['itemid']; $clear = $_POST['clear']; $clearSQL = "DELETE FROM `List_Items` WHERE `item_ID` = $item"; $cleared = mysqli_query($connect, $clearSQL); I have a textbox which i want users to be able to search the database for zipcodes, I can't seem to make it work my IDE doesn't show any errors but when I test the code everything goes blank, the mysql credentials are all correct the code is, any suggestions would help <form action="index.php" method="post"> <label for="search2" style="color:#FFF;background-color:#0A016D"><b>Search Homes by Zipcode</b></label><br> zipcode: <input type="text" name="zipcode"><br> <button type="submit" name="submit" value="submit"/> </form> <?php $zipcode= @$_post['zipcode']; require("myconn.php"); mysql_select_db("phplogin")or die(mysql_error()); $sql= mysql_query("SELECT * FROM users WHERE zipcode='$zipcode' "); $numrow= mysql_num_rows($sql); while($row= mysql_fetch_assoc($sql)) { echo "zipcode: ".$row['zipcode']." city :".$row['city']."<br/>"; } ?> Hello. Many thanks for your help. I am writing a PHP/MySQL dating-site and have hit a programming impass. I have a database full of members and a search form consisting of checkboxes. So to search, a member ticks say...gender: female; age: 21,22,23,24,25,26; height: 5'4",5'5",5'6",5'7"; county: cornwall,devon,somerset How can a run a check on the database selecting all entries that fall into the selected criteria. For example a 23 year old female of 5'5" living in Cornwall and a 26 year old female of 5'4" living in Somerset? The key index of my database is 'id' and the fields a age,height,county The names of the form checkboxes a Gender: male, female; Age: 21,22,23,24 etc; Height: 5_4,5_5,5_6 etc; county: cornwall,devon etc I need help trying to figure out why my form won't write the database it is supposed to - i checked the connection to the database and it works and the user seems to have permission to edit database - the error I get is "Error: User not added to database." from "register.php". Can someone please look over my code and see if the problem is coming from somewhere within?
I created a connection file (connect.php)
<? session_start(); // Replace the variable values below // with your specific database information. $host = "localhost"; $user = "master"; $pass = "hidden"; $db = "user"; // This part sets up the connection to the // database (so you don't need to reopen the connection // again on the same page). $ms = mysql_pconnect($host, $user, $pass); if ( !$ms ) { echo "Error connecting to database.\n"; } // Then you need to make sure the database you want // is selected. mysql_select_db($db); ?>Then there is the php script (register.php): <?php session_start(); // connect.php is a file that contains your // database connection information. This // tutorial assumes a connection is made from // this existing file. require('connect.php'); // If the values are posted, insert them into the database. if (isset($_POST['email']) && isset($_POST['password'])){ $firstname = $_POST['firstname']; $lastname = $_POST['lastname']; $email = $_POST['email']; $password = $_POST['password']; $query = "INSERT INTO `member` (firstname, lastname, email, password) VALUES ('$firstname', '$lastname', '$email' '$password')"; $result = mysql_query($query); if ( !mysql_insert_id() ) { die("Error: User not added to database."); } else { // Redirect to thank you page. Header("Location: surveylanding_no-sidebar.html"); } } ?>Here is the HTML form: <form name="htmlform" method="post" class="form" action="register.php"> <p class="firstname"> <input type="text" name="firstname" id="firstname" /> <label for="firstname">First Name</label> </p> <p class="lastname"> <input type="text" name="lastname" id="lastname" /> <label for="lastname">Last Name</label> </p> <p class="email"> <input type="email" name="email" id="email" /> <label for="email">Email</label> </p> <p class="Password"> <input type="password" name="password" id="password" /> <label for="password">Password</label> </p> <p class="submit"> <input type="submit" value="Register"/> </p> </form> Hello Everyone, I am pretty new to the forums and was curious if i could get some help here. Basically, in a nutshell, i have PayPal integrated into my website. I will use this to collect money from clients. when a client logs into his/her account they see their balance (which is pulled from the database to correspond with the user that's logged-in). Now, everytime a payment is submitted a notify_url is contacted after payment has been verified, that notify_url is the code written below. What I am trying to execute here is when this notify_url is called the current balance is reduced from the amount paid through paypal. In the second If condition, you will see that the word success is being entered into the paypal.txt file, which is working perfectly fine. Now, you will also see the variable $update_balance; which is suppose to update the original balance with the balance paid through PayPal BUT IT'S NOT!! WHY?? LOL Thank You in advance! <?php ob_start(); session_start(); include_once ('/home/rdewebde/public_html/includes/paypal.php'); $myPaypal = new Paypal(); $myPaypal->ipnLog = TRUE; include_once "/home/rdewebde/public_html/includes/_config.php"; $username = "".$_SESSION['username'].""; $users_data = mysql_query("SELECT * FROM `members` WHERE `username`='".$username."'"); $user_info = mysql_fetch_array($users_data); $current_amount = $user_info['balance']; $deduct_amount = $myPaypal->ipnData['payment_gross']; $new_amount = $current_amount - $deduct_amount; $update_balance = mysql_query("UPDATE `members` SET `balance` = '$new_amount' WHERE `username` = '".$username."'"); if ($myPaypal->validateIpn()) { if ($myPaypal->ipnData['payment_status'] == 'Completed') { $update_balance; file_put_contents('/home/rdewebde/public_html/lounge/paypal.txt', 'SUCCESS'); } else { file_put_contents('/home/rdewebde/public_html/lounge/paypal.txt', "FAILURE\n\n" . $myPaypal->ipnData); } } ?> I am very new to php and am trying to create a simple application that uploads a PDF file to a database. I have one field for the Volume Number and on file field for the PDF to be uploaded. My issue is i can't get the PDF to upload or insert the name of the pdf (eg volume1.pdf) into the data base. I would also like to point out that I know i have a low post count, but i only seek help when i truly need it and have exhausted all other resources... Here is what i have, please go easy on me this is my first round at php: Code: [Select] <?php if(isset($_POST['submit'])){ $vol_num = $_POST['vol_num']; $pdf = $_FILES['pdf']['name']; $path = '../pdf/'.$_FILES['pdf']['name']; move_uploaded_file($_FILES["pdf"]["tmp_name"], $path); mysql_query("INSERT INTO volumes set vol_num='$vol_num', vol_link='$pdf'") or die (mysql_error()); echo "<script>location.href='add_volume.php'</script>"; } ?> what am i doing wrong here? Thanks in advance Hi All, First time posting here. I've googled the problem, but can't seem to find a response that's the same. All I want to do is have a list of id numbers and for each id number in the array, submit a MySQL query to retrieve information relating to the id number. When I execute the code below however, I end up with only the last item in the array being printed in the echo statement. Any clues? Thanks, Code: [Select] // get array of ids $ids = getIDs($ids); // loop through input list foreach ($ids as &$id) { getVarDetails($id); } function getVarDetails($local) { $con = mysql_connect('localhost:3306', 'root', '********'); if (!$con) { die('Could not connect: ' . mysql_error()); } // set database as Ensembl mysql_select_db("Ensembl", $con); $result = mysql_query("SELECT * FROM variations WHERE name = '$local' LIMIT 1"); $row = mysql_fetch_array($result) while($row = mysql_fetch_array($result)) { echo $row['name'] . " " . $row['id']; echo "<br />"; } // close connection mysql_close($con); } Advance thank you. Can you help please. The error..... Warning: mysql_fetch_assoc() expects parameter 1 to be resource, string given in C:\wamp\www\test_dabase.php on line 24 code. Code: [Select] <?php //database connection. $DB = mysql_connect("localhost","root") or die(mysql_error()); if($DB){ //database name. $DB_NAME="mysql"; //select database and name. $CON=mysql_select_db($DB_NAME,$DB)or die(mysql_error()."\nPlease change database name"); // if connection. }if($CON){ //show tables. $mysql_show="SHOW TABLES"; //select show and show. $mysql_select2="mysql_query(".$mysql_show.") or die(mysql_error())"; } //if allowed to show. if($mysql_select2){ //while it and while($data=mysql_fetch_assoc($mysql_select2)){ //show it. echo $data; } } ?> |