Jump to content

tom11011

New Members
  • Posts

    5
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

tom11011's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. I got a 500 error and the data did not insert. The page redirected to /includes/customersfunctions.php which I did not expect.
  2. Hello, I am a newbie to php. I am trying to figure out how to call a function when a user clicks submit on a form. I have a sample script that I am writing where the user inputs there name, address, etc.. and then clicks submit and it inserts into the mysql database. I have successfully done this with form action to my adduser.php file, but I would rather have a single function file with adduser, delete a user, edit a user, etc.. here is my form <form action="includes/customersfunctions.php?add" method="post"> name: <input type="text" name="name" /><br /> address: <input type="text" name="address" /><br /> city: <input type="text" name="city" /><br /> state: <input type="text" name="state" /><br /> zip: <input type="text" name="zip" /><br /> <input type="submit" /> </form> Here is my function <?php function add() { include("config.php"); mysql_query("INSERT INTO customers (name,address,city,state,zip) VALUES ('name','address','city','state','zip') ") or die(mysql_error()); echo "added"; mysql_close($con); } ?> The function will have delete, update, etc.. later Thanks for your help in advance!
  3. Basically, there are 2 required fields, but if other fields have data in them, it should query them.  Thenks in advance. [code] $query = "SELECT * FROM table WHERE sl = '$sl' and state = '$state'";                 if (strlen($type) > 0) {                         $query = $query + " and type = '$type'";                         }                 if (strlen($city) > 0) {                         $query = $query + " and city = '$city'";                         }                 if (strlen($zip) > 0) {                         $query = $query + " and zip = '$zip'";                         }                 if (strlen($status) > 0) {                         $query = $query + " and status = '$status'";                         }                 if (strlen($pricemin) > 0) {                         $query = $query + " and price >= '$pricemin'";                         }                 if (strlen($pricemax) > 0) {                         $query = $query + " and price <= '$pricemax'";                         }                 if (strlen($squarefeetmin) > 0) {                         $query = $query + " and squarefeet >= '$squarefeetmin'";                         }                 if (strlen($squarefeetmax) > 0) {                         $query = $query + " and squarefeet <= '$squarefeetmax'";                         }                 if (strlen($ppsfmin) > 0) {                         $query = $query + " and ppsfmin >= '$ppsfmin'";                         }                 if (strlen($ppsfmax) > 0) {                         $query = $query + " and ppsfmax <= '$ppsfmax'";                         }                 $query = $query + " ORDER BY price;"; [/code]
  4. Hi all, I have a form that I use that posts to a php page.  I use mysql as my backend. I am having trouble figuring out how I should query and display the results.  My criteria are as follows: My searchable fields include type, state, city, zip, pricemin, pricemax, squarefeetmin, and squarefeetmax. The field name for pricemin and pricemax is price. The field name for squarefeetmin and squarefeetmax is squarefeet. type and state are required fields.  The other fields are not required to be entered, but if they are, I would like the search narrowed on that criteria. Could someone help me with my code?  I have gotten as far as running the query based on the required fields, but don't know how best to show the data based on the other non-required fields.  Here is my code. [code] <?PHP session_start(); ?> <!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=ISO-8859-1" /> <title>Search Results</title> </head> <body> <?PHP mysql_pconnect("10.1.1.35", "test", "test1") or die(mysql_error()); mysql_select_db("property") or die(mysql_error()); $type = $_POST['type']; $state = $_POST['state']; $city = $_POST['city']; $zip = $_POST['zip']; $pricemin = $_POST['pricemin']; $pricemax = $_POST['pricemax']; $squarefeetmin = $_POST['squarefeetmin']; $squarefeetmax = $_POST['squarefeetmax']; if(!isset($sl) || !isset($state)) {         echo "Please fill in all of the fields required"; } else {         $result = mysql_query("SELECT * FROM properties WHERE type='$type' and state='$state' ORDER BY price");         while($row = mysql_fetch_array($result)) { (I'm missing a ton of logic here)                         echo "<B>Name</B>: ".$row['name'];                         echo "<br><B>Type of Property</B>: ".$row['type']."<br />";                         echo "<B>State</B>: ".$row['state']."<br />";                         echo "<B>Price</B>: ".$row['price']."<br />";                         echo "<B>Square feet</B>: ".$row['squarefeet']."<br /><br />";         }         } ?> </body> </html> [/code]
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.