Auzzie's Profile
Reputation: 43
Craftsman
- Group:
- Authors
- Active Posts:
- 572 (0.36 per day)
- Joined:
- 20-January 09
- Profile Views:
- 7,998
- Last Active:
Feb 24 2012 02:36 PM- Currently:
- Offline
Previous Fields
- Country:
- GB
- OS Preference:
- Linux
- Favorite Browser:
- FireFox
- Favorite Processor:
- Intel
- Favorite Gaming Platform:
- Playstation
- Your Car:
- Who Cares
- Dream Kudos:
- 275
Latest Visitors
-
darek9576 
17 Aug 2012 - 14:23 -
John008 
17 Aug 2012 - 06:51 -
BonKerzzz 
11 Aug 2012 - 04:48 -
parthmody90 
26 Jan 2012 - 05:24 -
EnvXOwner 
29 Dec 2011 - 09:11
Posts I've Made
-
In Topic: Search/view help
Posted 16 Nov 2011
all you need to do is change line 28 to the following:
$sql = "SELECT * FROM customers WHERE lastName = '$name'";
and move line 32 onto line 27.... So the code would look like this:
<?php include '../view/header.php'; ?> <?php require('../model/database.php'); require('../model/customer_db.php'); ?> <div id="main"> <h1>Customer Search</h1> <div id="content"> <!-- display a table of products --> <form method="post" action="search.php?go" id ="searchform"> <label>Last Name:</label> <input type="text" name="lastName"> <input type="submit" name ="submit" value="Search"> </form> <?php if(isset($_POST['submit'])) { if(isset($_GET['go'])) { if(preg_match("/^[A-za-z]+/", $_POST['lastName'])){ //connect $db = mysql_connect("localhost", "username", "password") or die ('I cannot connect to the database because: ' . mysql_error()); //select $mydb=mysql_select_db("dbname"); $name=$_POST['lastName']; // $sql = "SELECT * FROM customers WHERE lastName = '$name'"; //my tablename "customers" //run $result = mysql_query($sql); //Create a while loop while ($row = mysql_fetch_array($result)){ $lastName = $row['lastName']; $firstName = $row['firstName']; $email = $row['email']; $city = $row['city']; //display echo "<tr> <th>Last Name,</th> <th>First Name</th> <th>Email</th> <th>City</th> <th></th></tr>"; echo "<u1>\n"; echo "<li>" . "<a href=\"search.php?id=$row\">" .$lastName . " " . $firstName . " " . $email . " " . $city . "</li>\n"; echo "</ul>"; } // close table> echo "</table>"; } } } else { echo "<p>Please input a valid name</p>"; } ?> } </div> </div> <?php include '../view/footer.php'; ?>
Your issue was you never gave mysql a condition so it would always pull all customers.
EDIT: also, look up mysql_real_escape_string() to help sanitize your data before using against a database -
In Topic: MySQL Query issue when using a string.
Posted 16 Nov 2011
New issue now:
Warning: mysqli_stmt::bind_param(): Undefined fieldtype 0 (parameter 2) in /srv/www/htdocs/framework/system/library/db_mysqli.php on line 103 Warning: mysqli_stmt::bind_param(): Undefined fieldtype 1 (parameter 2) in /srv/www/htdocs/framework/system/library/db_mysqli.php on line 103 Notice: Trying to get property of non-object in /srv/www/htdocs/framework/system/application/controllers/blog_controller.php on line 42 Notice: Trying to get property of non-object in /srv/www/htdocs/framework/system/application/controllers/blog_controller.php on line 43 Notice: Trying to get property of non-object in /srv/www/htdocs/framework/system/application/controllers/blog_controller.php on line 44 Notice: Trying to get property of non-object in /srv/www/htdocs/framework/system/application/controllers/blog_controller.php on line 45
EDIT: I also noticed I was querying against title not entry_title but changing it made no different -
In Topic: MySQL Query issue when using a string.
Posted 16 Nov 2011
and when I do so I get the following (without using your suggestion yet codeprada)
string(159) "SELECT b.entry_title, b.date_time, u.username, b.poster, b.entry FROM blog_post b INNER JOIN user u ON u.id = b.poster WHERE b.title = 'this is a test'
-
In Topic: MySQL Query issue when using a string.
Posted 16 Nov 2011
I var_dump'd it, sorry I forgot to mention, when echo'd the SQL Query was exactly how it should have been.
string(175) "SELECT b.entry_title, b.date_time, u.username, b.poster, b.entry FROM blog_post b INNER JOIN user u ON u.id = b.poster WHERE b.entry_title = 'this is a test' AND published = 1"
-
In Topic: MySQL Query issue when using a string.
Posted 16 Nov 2011
it is in blog_post, i did try it as b.title but the same issue is present
My Information
- Member Title:
- D.I.C Addict
- Age:
- 22 years old
- Birthday:
- June 6, 1990
- Gender:
- Location:
- England
- Interests:
- Shooting Running Drinking and of course Sexercise :P
- Full Name:
- Marc Towler
- Years Programming:
- 1
- Programming Languages:
- PHP, ASM, ASP, CSS, XHTML, PERL, PHP-GTK, C#
Contact Information
- E-mail:
- Click here to e-mail me
- MSN:
-
killer_auzzie@hotmail.co.uk
- Website URL:
-
http://www.acidavengers.co.uk
- Yahoo:
-
killerauzzie
- Facebook:
- http://lite.facebook.com/p/Marc-Towler/1311431524/
- Twitter:
- marctowler
Friends
|
|


Find Topics
Find Posts
View Reputation Given


|
Comments
Auzzie has no profile comments yet. Why not say hello?