homepage Welcome to WebmasterWorld Guest from 54.227.141.230
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Newbie in need of help with MySQL and PHP
StevieMac




msg:1272625
 5:48 pm on Sep 1, 2004 (gmt 0)

Sorry for such a lame question......

I have searched up and down on this site for ideas on how to fix this, however I just cant seem to find an answer.

I want to take a form and POST to a script and return rows from a sql database. From what I am quering on, it has duplicate entry's however, they are not primary.

<html>
<body>

<form name="wifi" method="POST" action="results.php">
<p> SSID: <input name="ssid" type="text" id="ssid">
<p><input type="submit" name="submit" value="submit">
</form>
</body>
</html>

<?
$host = "localhost";
$user = "username";
$pass = "password";
$dbname = "database";
$connection = mysql_connect($host,$user,$pass) or die (mysql_errno().": ".mysql_error()."<BR>");
mysql_select_db($dbname);
$sql = "select * from tablename where SSID = " . $_POST['SSID'] . "'";

$query = mysql_query($sql);
while ($row = mysql_fetch_array($query)) {
echo "<p>",$row['SSID'],": ",$row['BSSID'];
}
?>

When I input something in the textbox and hit submit, I just get a blank screen. I did have an echo as seen in a previous post, and it shows the echo, but nothing else.

Please, any help would be appreciated.....

 

jatar_k




msg:1272626
 7:29 pm on Sep 1, 2004 (gmt 0)

Welcome to WebmasterWorld StevieMac,

my wild guess is that the query isn't working try this to help debug

$query = mysql_query($sql) or die(mysql_error());

StevieMac




msg:1272627
 1:45 am on Sep 2, 2004 (gmt 0)

jatar_k,

Thanks for responding so quickly. I made the change like you suggested and I can't believe that I made that simple of a mistake. However, all I still get is

select * from wifi_ap where SSID ='

On the page. I get that because I put an echo statment in there to also try and debug.

StevieMac

Knowles




msg:1272628
 1:50 am on Sep 2, 2004 (gmt 0)

with what you have above you are missing a ' between SSID = '" . $_POST['

StevieMac




msg:1272629
 3:58 am on Sep 2, 2004 (gmt 0)

Knowles,

That was it.... but now it returns every record in that database. Not the one's that I'm searching for.....

StevieMac

Knowles




msg:1272630
 10:50 am on Sep 2, 2004 (gmt 0)

Well I am not to sure on how case snsitive this stuff is since I am lazy and use lower case. In your form you have ssid in your $_POST you have SSID... it is possible that the difference there is causing you to return all records instead of just the one you want.

ergophobe




msg:1272631
 2:36 pm on Sep 2, 2004 (gmt 0)

A perfect example of why error reporting should always be set to E_ALL for development. You would get a "undefined index" warning if you turned up error reporting (yes, variables, constants and array indices are case sensitive in PHP, even under Windows).

So $_POST['SSID'] should be undefined, so PHP will treat is as an empty string, but that shouldn't return all records unless the SSID column is in fact empty in the data.

Echo out your $SQL var to see what query you're actually sending to the DB server.

To change error reporting, search for error_reporting in your php.ini and change it to E_ALL on your development computer. It will make life much easier in the long run.

Tom

StevieMac




msg:1272632
 9:58 pm on Sep 2, 2004 (gmt 0)

ergophobe,

Understandable about the E_All. I do have that on, it it doesn't say anything. Also the echo of the SQL shows:

select * from wifi_ap where ssid =''

Here is my two lines of code.

$sql = "select * from wifi_ap where ssid ='" . $_POST['SSID'] . "'";
echo $sql;

Thanks

StevieMac




msg:1272633
 10:02 pm on Sep 2, 2004 (gmt 0)

Everyone,

I think that I figured it out. Thanks to you all....

I had the post ssid in CAPS. It was lowercase in the form.

StevieMac

$sql = "select * from wifi_ap where SSID ='" . $_POST['ssid'] . "'";

ergophobe




msg:1272634
 10:54 pm on Sep 2, 2004 (gmt 0)

That's really curious. Normally with E_ALL you should have gotten a notice or warning for undefined index. Are you sure you aren't suppressing errors or notices?

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About
© Webmaster World 1996-2014 all rights reserved