
mainelydesign
Members-
Posts
13 -
Joined
-
Last visited
Never
Profile Information
-
Gender
Not Telling
mainelydesign's Achievements

Newbie (1/5)
0
Reputation
-
Sorry for the confusion. SEECT * FROM $table_name works fine without the where statement. However what i meant to state (more clearly) was the WHERE dog_breed = '*' does not work as a method to grab all entries in that field. My end goal is to have a series of drop down select fields allowing users to select an option or all. if all is selected then the query needs to pull all of the entries in the specific field. Using the WHERE function as an .= addition for the earlier suggestions, did not produce a result other then a syntax error each time. So I have moved backward a little to an if else variable but am unable to declare ALL so that it grabs all of the entries.
-
I have worked out a rough solution but am having trouble tying the last piece of the idea together. here it is: $dogbrd = $_POST['breed']; if ($dogbrd =="ALL"){ $dog = 'pitbull, boxer, shitzu'; }else{ $dog = $_POST['breed']; } $get_contacts_in = "SELECT id, bname, dog_breed FROM $table_name WHERE dog_breed = '$dog' ORDER BY bname"; What i need to be able to do is have multiple breed types in the all variable so that dog_breed = pitbull and boxer and shitzu thus pulling all the field entries and displaying them. I tried the * as SELECT * FROM $table_name pulls everything in the DB but it does not work right (prob a dumb attempt LOL). is there a command that can be used like dog_breed = ALL? Thanks
-
The connection is fine, tested that already. I have tried echoing the $sql down but the syntax error is preventing it. Will post back after some exxperimenting.
-
No it is still having issues LOL. I keep getting this: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '=' at line 1 Not sure why it does not like the equals. I am viewing it out of Aptana atm, might that be an issue? And again thanks for the assistance Chris
-
This is cleaned up a little: <? include 'connection.php'; $breed = $_POST['slctbreed']; //build and issue query $sql = "SELECT count(id) FROM $table_name"; $result = @mysql_query($sql, $connection) or die(mysql_error()); $count = @mysql_result($result, 0, "count(id)") or die(mysql_error()); //get birthday count $get_dog_count = "SELECT count(id) FROM $table_name"; if($breed!="all") $get_dog_count.=" WHERE dog_breed = '$breed'"; $dog_count_res = @mysql_query($get_dog_count, $connection) or die(mysql_error()); $dog_count = mysql_result($dog_count_res, 0, "count(id)"); //create a list,based on a postive result if ($dog_count > 0) { $dog_string = "<ul>"; $get_dogs = "SELECT id, bname, dog_breed FROM $table_name"; if($breed!="all") $get_dogs.=" WHERE dog_breed = '$breed'"; $get_dogs.="ORDER BY bname"; $dog_res = @mysql_query($get_dogs, $connection) or die(mysql_error()); while ($doggy = mysql_fetch_array($dog_res)) { $dog_id = $doggy['id']; $dog_bname = $doggy['bname']; $dog_brd = $doggy['dog_breed']; $dog_string .= "<li><a href=\"show_breed.php?id=$dog_id\">$dog_bname $dog_brd</a>"; } $dog_string .= "</ul>"; } //build menu block $display_block = " <P><strong>Miscellaneous</strong></P> <ul> <li>All breeds in DB:<strong>$count</strong> <li>$breed types:<strong>$dog_count</strong> $dog_string </ul>"; ?> <HTML> <HEAD> <TITLE>Dog Breeds</TITLE> </HEAD> <BODY> <? echo "$display_block"; ?> <p> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" name="submit" method="post"> <select name="slctbreed" size="1"> <option value="all">all</option> <option value="pitbull">Pitbull</option> <option value="boxer">Boxer</option> <option value="shitzu">Shitzu</option> </select> <input type="submit" name="Submit"value="Submit"> </form> </p> </BODY> </HTML> Now I am setting the field in the WHERE string rather then in a variable.
-
Here is the Full Code <? include 'connection.php'; $dog = "dog_breed"; $breed = $_POST['slctbreed']; //build and issue query $sql = "SELECT count(id) FROM $table_name"; $result = @mysql_query($sql, $connection) or die(mysql_error()); $count = @mysql_result($result, 0, "count(id)") or die(mysql_error()); //get dog count $get_dog_count = "SELECT count(id) FROM $table_name"; if($breed!="all") $get_dog_count.=" WHERE $dog = '$breed'"; $dog_count_res = @mysql_query($get_dog_count, $connection) or die(mysql_error()); $dog_count = mysql_result($dog_count_res, 0, "count(id)"); //create a list,based on a postive result if ($dog_count > 0) { $dog_string = "<ul>"; $get_dogs = "SELECT id, bname, dog_breed FROM $table_name ORDER BY bname"; if($breed!="all") $get_dogs.=" WHERE $dog = '$breed' ORDER BY bname"; $dog_res = @mysql_query($get_dogs, $connection) or die(mysql_error()); while ($doggy = mysql_fetch_array($dog_res)) { $dog_id = $doggy['id']; $dog_bname = $doggy['bname']; $dog_brd = $doggy['dog_breed']; $dog_string .= "<li><a href=\"show_breed.php?id=$dog_id\">$dog_bname $dog_brd</a>"; } $dog_string .= "</ul>"; } //build menu block $display_block = " <P><strong>Miscellaneous</strong></P> <ul> <li>All breeds in DB:<strong>$count</strong> <li>$breed types:<strong>$dog_count</strong> $dog_string </ul>"; ?> <HTML> <HEAD> <TITLE>Dog Breeds</TITLE> </HEAD> <BODY> <? echo "$display_block"; ?> <p> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" name="submit" method="post"> <select name="breed" size="1"> <option value="all">all</option> <option value="pitbull">Pitbull</option> <option value="boxer">Boxer</option> <option value="shitzu">Shitzu</option> </select> <input type="submit" name="Submit"value="Submit"> </form> </p> </BODY> </HTML> Basically I am using a drop down menu in a for to identify the breed value and am using a set variable for the field. I probably should just put the field in the string instead of a variable that says what it is.
-
That makes sense now that I look at. Still getting the syntax error from the = in the WHERE string. if($breed!="all") $get_dog_count.=" WHERE $dog = '$breed'"; Now when i use the could in its original stated before adding the all option and condition then the script runs and searches approriately based on the selection form the drop down. Not sure why the = is an issue now as the error message doesnt suggest more then a syntax error.
-
Thanks, was just reading up on SQL injections as i am a novice. Thanks for the heads up, After i get this working (on my local machine) i will start focusing on proper protection form SQL Injection. Again Thanks
-
I have tried making the query conditional, however I am getting a syntax error revolving aroundthe use of $dog = '$breed'. Here is the revised code: $get_dog_count = "SELECT count(id) FROM $table_name"; if($breed!="all") $get_dog_count.=" WHERE $dog = '$breed'"; $dog_count_res = @mysql_query($get_dog_count, $connection) or die(mysql_error()); $dog_count = mysql_result($dog_count_res, 0, "count(id)"); //create a list,based on a postive result if ($dog_count > 0) { $dog_string = "<ul>"; $get_dogs = "SELECT id, bname, dog_breed FROM $table_name ORDER BY bname"; if($breed!="all") $get_dogs.=" WHERE $dog = '$breed' ORDER BY bname"; $dog_res = @mysql_query($get_dogs, $connection) or die(mysql_error()); while ($doggy = mysql_fetch_array($dog_res)) { $dog_id = $doggy['id']; $dog_bname = $doggy['bname']; $dog_brd = $doggy['dog_breed']; $dog_string .= "<li><a href=\"show_breed.php?id=$dog_id\">$dog_bname $dog_brd</a>"; } $dog_string .= "</ul>"; }
-
Thanks Chris I am trying that now, appreciate the help.
-
I am creating a search function to call from my DB to display certain information. I am using a series of drop downs atm and need to be able to have an All option to call every entry in that field. Here is the code as it stands: <? include 'connection.php'; $dog = "dog_breed"; $breed = $_POST['slctbreed']; //build and issue query $sql = "SELECT count(id) FROM $table_name"; $result = @mysql_query($sql, $connection) or die(mysql_error()); $count = @mysql_result($result, 0, "count(id)") or die(mysql_error()); //get birthday count $get_dog_count = "SELECT count(id) FROM $table_name WHERE $dog = '$breed'"; $dog_count_res = @mysql_query($get_dog_count, $connection) or die(mysql_error()); $dog_count = mysql_result($dog_count_res, 0, "count(id)"); //create a list,based on a postive result if ($dog_count > 0) { $dog_string = "<ul>"; $get_dogs = "SELECT id, bname, dog_breed FROM $table_name WHERE $dog = '$breed' ORDER BY bname"; $dog_res = @mysql_query($get_dogs, $connection) or die(mysql_error()); while ($doggy = mysql_fetch_array($dog_res)) { $dog_id = $doggy['id']; $dog_bname = $doggy['bname']; $dog_brd = $doggy['dog_breed']; $dog_string .= "<li><a href=\"show_breed.php?id=$dog_id\">$dog_bname $dog_brd</a>"; } $dog_string .= "</ul>"; } //build menu block $display_block = " <P><strong>Miscellaneous</strong></P> <ul> <li>All breeds in DB:<strong>$count</strong> <li>$breed types:<strong>$dog_count</strong> $dog_string </ul>"; ?> <HTML> <HEAD> <TITLE>Dog Breeds</TITLE> </HEAD> <BODY> <? echo "$display_block"; ?> <p> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" name="submit" method="post"> <select name="breed" size="1"> <option value="all">all</option> <option value="pitbull">Pitbull</option> <option value="boxer">Boxer</option> <option value="shitzu">Shitzu</option> </select> <input type="submit" name="Submit"value="Submit"> </form> </p> </BODY> </HTML> Where I am having difficulty is determining a value for when ALL is selected to be placed in the WHERE string so that is $dog which is my field in the DB is equal to get everything in that field. I tried using a if then and it wasn't close to working. Any suggestions would be appreciated. Thanks in advance.
-
Thanks for the feed back, it is moving along now the way i want it to. appreciate the feed back.
-
I have a script i started in which I am trying to validate required fields before passing onto the next page/process. It is for what will become a multistep form. Here is the code: <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title>Required Form Fields</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> </head> <body> <?php # Script 4.1 - register.php /* This page creates a registration form * which is then validated using various functions. */ if (isset($_POST['submitted'])) { // Handle the form. // Store errors in an array: $errors = array(); // Check for non-empty name: if (!isset($_POST['name']) OR empty($_POST['name'])) { $errors[] = 'name'; } // Validate the email address using eregi(): if (!eregi('^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$', $_POST['email'])) { $errors[] = 'email address'; } // Check for non-empty comments: if (!isset($_POST['comments']) OR empty($_POST['comments'])) { $errors[] = 'comments'; } if ( empty($errors)) { // Success! // Print a message and quit the script: /*echo '<p>You have successfully registered (but not really).</p></body></html>';*/ $action = "post_req_form.php"; exit(); } else { // Report the errors. echo '<p>Problems exist with the following field(s):<ul>'; foreach ($errors as $error) { echo "<li>$error</li>\n"; } echo '</ul></p>'; } } // End of $_POST['submitted'] IF. // Show the form. ?> <form action="<?php echo $action;?>" method="post"> <fieldset> <legend> Registration Form </legend> <p> <STRONG>Name:</STRONG> <input type="text" name="name" size="50" maxlength="50" value=""> </p> <p> <STRONG>E-Mail:</STRONG> <input type="text" name="email" size="50" maxlength="200"> </p> <p> <STRONG>Comments:</STRONG> <br/> <textarea name="comments" rows="5" cols="40"> </textarea> </p> <input type="hidden" name="submitted" value="true" /><input type="submit" name="submit" value="Submit" /> </fieldset> </form> </body> </head> The hang up is when I try to use and echo statement into the action field of the form. it takes me to file/$action rather then file/process_req_form.php and any help would be appreciated.