Welcome to WebmasterWorld Guest from 23.20.241.155

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Newbie in need of help with MySQL and PHP

     
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.....

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

WebmasterWorld Administrator jatar_k is a WebmasterWorld Top Contributor of All Time 10+ Year Member



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());

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

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

10+ Year Member



with what you have above you are missing a ' between SSID = '" . $_POST['
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

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

10+ Year Member



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.
2:36 pm on Sep 2, 2004 (gmt 0)

WebmasterWorld Administrator ergophobe is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



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

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

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'] . "'";

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

WebmasterWorld Administrator ergophobe is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



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?
 

Featured Threads

Hot Threads This Week

Hot Threads This Month