Solved

PHP - Using textbox value in SQL where clause

Posted on 2011-09-12
4
602 Views
Last Modified: 2012-05-12
Hi Experts,

Im creating a PHP page that resturns database values, I went the WHERE clause of my SQL statement to pick up the value in a textbox.

In VB id do something like...

WHERE (PrtNumber = '" & FlxMestecReport(RowCount, 17) & "')"

How do you guys do it?

Thanks,
Dean.
0
Comment
Question by:deanlee17
  • 2
4 Comments
 
LVL 82

Expert Comment

by:Dave Baldwin
ID: 36521526
$sql = "... WHERE `PrtNumber` = '$textboxvalue'";
0
 
LVL 82

Expert Comment

by:Dave Baldwin
ID: 36521530
You didn't say which SQL you are using and which driver...
0
 
LVL 108

Accepted Solution

by:
Ray Paseur earned 500 total points
ID: 36521690
By "textbox" do you mean a form <input> control?  If so, you might have something like this

// THE ACTION SCRIPT
$x = mysql_real_escape_string($_GET["x"];
$q = "SELECT thing FROM mytable WHERE PrtNumber = '$x' LIMIT 1";
$r = mysql_query($q) or die( mysql_error() );
$n = mysql_num_rows($r);
if ($n) echo "I GOT ONE";
if (!$n) die( "I DID NOT FIND ANYTHING EQUAL TO $x" );
$s = mysql_fetch_assoc($r);
var_dump($s);

// THE FORM INPUT
<form>
<input name="x" />
<input type="submit" />
</form>
0
 

Author Comment

by:deanlee17
ID: 36522786
Thats great, thanks guys. Ray gave the best answer I think,
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

'Between' is such a common word we rarely think about it but in SQL it has a very specific definition we should be aware of. While most database vendors will have their own unique phrases to describe it (see references at end) the concept in common …
These days socially coordinated efforts have turned into a critical requirement for enterprises.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now