I have a form that inputs data into my database. The table is called "profile" and it has 3 fields... "ip" "name" and "bio" the data goes into the database great, but it’s just how to display it is the problem... I want to be able to display the name and the bio, just by using the ip address, for you to understand this a bit better, this is my attempt... $currentuserinfo = mysql_query( "SELECT * FROM profile WHERE ip = $ip and show bio + name " ) ; Code (markup): There will be a new page for this... So if you went to http://mysite.com/index.php?ip=34.433.2344 I want that to show the users bio and name. Oh and 1 other thing, on my form it creates a profile for the user when submitted. But rather than having duplicate ip's in my database i want it to update the data if the ip address is already in my database, rather than adding a new user under that ip everytime something is changed. This is my current code for adding a new profile, but i need it to be able to update it instead of just adding new profiles even for the same ip.. $query = "UPDATE and INSERT INTO profile VALUES ('$ip','$name','$bio')"; Code (markup): The above 2 codes do not work there just to try and better illustrate what I need done. If you could help me out here it would be greatly appreciated!!
Your pretty far off. Its hard to help without seeing everything though. The first query would be something like.. $query = mysql_query( "SELECT * FROM profile WHERE ip = $ip " ) ; PHP: This will return all the data in profile. Thats what the SELECT * is (* = all). If you wanted just IP you would SELECT IP. So it returns bio and name also. But now you have to get that info. This would go right below the other line. $result = mysql_query($query) or die(mysql_error()); $row = mysql_fetch_array($result) or die(mysql_error()); echo $row['bio']. " - ". $row['name']; PHP: I dont know what your fields are called but when you want the info its $row['fieldname']. Try that. If it dont work then read http://www.tizag.com/mysqlTutorial/mysqlquery.php http://www.tizag.com/mysqlTutorial/mysqlfetcharray.php http://www.tizag.com/mysqlTutorial/mysqlselect.php
Thanks for your time +rep I added that code to the correct section but my site is now saying "Query was empty" when loaded. I'm going to study those links you sent me and try and find out the source of the problem. thanks again
Changed a few things around and your code works great! thanks. any idea for a solution to the second problem?
u need some queries for second problem: 1. select by ip. 2. if result of query !=0 then next query update. if result of query =0 then next query add.