/    Sign up×
Community /Pin to ProfileBookmark

This is a beginner question. Is the query below correct? It does not display anything even if I inputed the correct Id number.

[code=php]
$sql=”SELECT *FROM table1 WHERE id=” . $pangalan;
[/code]

When I use a text query it display the result

[code=php]
$sql=”SELECT *FROM table1 WHERE lname LIKE ‘%” . $pangalan . “%’ “;
[/code]

The id is an integer auto incremented type and is the the primary key.

to post a comment
PHP

6 Comments(s)

Copy linkTweet thisAlerts:
@tirnaJul 05.2010 — then why not try

[CODE]$sql="SELECT *FROM table1 WHERE lname LIKE '" . $pangalan . "' ";[/CODE]

it appears that $pangalan is some type of varchar or text type and not numerical or there is no id = $pangalan in your table.
Copy linkTweet thisAlerts:
@anishgiriauthorJul 05.2010 — This is how pangalan has been assigned a value

[code=php]
<input type="text" name="name" >
$pangalan = $_POST['name'];
[/code]


In my table id field I have a values like 1, 2,3 and so forth. What do you think is the problem?

Also I want the data to be searchable by id.
Copy linkTweet thisAlerts:
@TrollsplattererJul 05.2010 — I suggest to try this one:

$sql="SELECT * FROM table1 WHERE id=" . $pangalan;

If that fails, try:

- displaying the $pangalan before running the query

- displaying the entire query

- running the quiry manually in an SQL Management tool (I suppose you have one on your website).
Copy linkTweet thisAlerts:
@tirnaJul 05.2010 — if lname in your db table is some type of varchar or text data type then $pangalan must be enclosed in quotes in your sql query for it to work properly.
Copy linkTweet thisAlerts:
@anishgiriauthorJul 06.2010 — $pangalan was enclosed by quotes. I determined the problem, when I press the space bar once to move a little further my query on the left side, let say 1, it display the data. But if I did not move my id query a little bit further from the left side, it will not display the data. But with text queries, I don't need to press the space bar.

My input type is image. Once I replace it with input type submit, I don't need to press the space bar for id queries to display the data.
[CODE]

<input type="image" value="Submit" src="images/magnifying.gif" name="submit" >
[/CODE]


So the problem is if I use input type image, I need to press the space bar once for integer (id) queries to work. So what do you think I should do?

I like to add that the text box is floated
[CODE]
<input type="text" name="name" >


{
float:left;
margin-left:20px;

}

[/CODE]
Copy linkTweet thisAlerts:
@anishgiriauthorJul 15.2010 — I figure it out on what to do with my problem. I added [CODE] value=" " [/CODE] on my input type image form.
×

Success!

Help @anishgiri spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...