Rother2005 Posted January 15, 2007 Share Posted January 15, 2007 hi im trying to do a search within my db and display the result any help?[code]<?phpinclude('connect1.inc');?><html><head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><title>Booze Cruise Reg</title></head><body><?php if(!$_POST['register']){echo'<p align="center"><strong>Member Registration</strong></p><form name="form1" method="POST" action=""><p align="center">Username: <input type="text" name="username" maxlength="10"></p><p align="center"><input type="submit" name="register" value="Enter Details"></p></form>';} //27else{//checks if user has input textif(isset($_POST['username']) && !empty($_POST['username'])){ // valid $username = $_POST['username'];}else{ // not valid die ("No Username Input");}$sql = "SELECT * FROM MEMBER,NEWSLETTER WHERE MEMBER.Username='$username' = NEWSLETTER.Username='$username'";mysql_query($sql) or die(mysql_error());//50echo ($sql);}?></body></html>[/code] Link to comment https://forums.phpfreaks.com/topic/34333-echo-results/ Share on other sites More sharing options...
owenjh Posted January 15, 2007 Share Posted January 15, 2007 Try:[CODE]or die(mysql_error());//50$var = mysql_fetch_assoc($sql);print_r($var);}?>[/CODE] Link to comment https://forums.phpfreaks.com/topic/34333-echo-results/#findComment-161532 Share on other sites More sharing options...
Rother2005 Posted January 15, 2007 Author Share Posted January 15, 2007 tried that lolWarning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in C:\Program Files\xampp\htdocs\2QRY.PHP on line 37 ??? ??? ???any ideas? Link to comment https://forums.phpfreaks.com/topic/34333-echo-results/#findComment-161547 Share on other sites More sharing options...
fert Posted January 15, 2007 Share Posted January 15, 2007 you need to save the result mysql_query returns Link to comment https://forums.phpfreaks.com/topic/34333-echo-results/#findComment-161548 Share on other sites More sharing options...
Rother2005 Posted January 15, 2007 Author Share Posted January 15, 2007 im sorry but how do you do that??? Link to comment https://forums.phpfreaks.com/topic/34333-echo-results/#findComment-161554 Share on other sites More sharing options...
Rother2005 Posted January 15, 2007 Author Share Posted January 15, 2007 help anyone Link to comment https://forums.phpfreaks.com/topic/34333-echo-results/#findComment-161565 Share on other sites More sharing options...
fert Posted January 15, 2007 Share Posted January 15, 2007 $result=@mysql_query($sql) or die(mysql_error()); Link to comment https://forums.phpfreaks.com/topic/34333-echo-results/#findComment-161578 Share on other sites More sharing options...
Rother2005 Posted January 16, 2007 Author Share Posted January 16, 2007 still no joy[code]$sql = "SELECT * FROM MEMBER,NEWSLETTER WHERE MEMBER.Username='$username' = NEWSLETTER.Username='$username'";$result=@mysql_query($sql) or die(mysql_error());$var = mysql_fetch_assoc($sql);print_r($var);}?>[/code] Link to comment https://forums.phpfreaks.com/topic/34333-echo-results/#findComment-161582 Share on other sites More sharing options...
fert Posted January 16, 2007 Share Posted January 16, 2007 http://us3.php.net/manual/en/function.mysql-fetch-array.php Link to comment https://forums.phpfreaks.com/topic/34333-echo-results/#findComment-161583 Share on other sites More sharing options...
Rother2005 Posted January 16, 2007 Author Share Posted January 16, 2007 rite ive got the form showing but even when i put the right data in (e.g. a user that is in the db) its showing the error msg[code]<?php$conn=mysql_connect("localhost","root","");if (!$conn) { echo "Unable to connect to DB: " . mysql_error(); exit;} if (!mysql_select_db("booze")) { echo "Unable to select booze: " . mysql_error(); exit;}if(!$_POST['register']){echo'<p align="center"><strong>check Newsletter Reg</strong></p><form name="form1" method="POST" action=""><p align="center">Username: <input type="text" name="username" maxlength="10"></p><p align="center"><input type="submit" name="register" value="Enter Details"></p></form>';} //16else{$sql = "SELECT * FROM MEMBER,NEWSLETTER WHERE MEMBER.Username='$username' = NEWSLETTER.Username='$username'";$result = mysql_query($sql);if (!$result) { echo "Could not successfully run query ($sql) from DB: " . mysql_error(); exit;}if (mysql_num_rows($result) == 0) { echo "No rows found, nothing to print so am exiting"; exit;}// While a row of data exists, put that row in $row as an associative arraywhile ($row = mysql_fetch_assoc($result)) { echo $row["username"]; echo $row["email"];}mysql_free_result($result);}?> [/code] Link to comment https://forums.phpfreaks.com/topic/34333-echo-results/#findComment-161588 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.