Solved

PHP - Using textbox value in SQL where clause

Posted on 2011-09-12
4
613 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 83

Expert Comment

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

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to dynamically set the form action using jQuery.

920 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

15 Experts available now in Live!

Get 1:1 Help Now