Okay, so this script displays all the rows in the table using a while loop. However, once I added the IF statement to see if the user's IP matches the one in the database and post an Edit link accordingly, it doesn't display ANYTHING. Once I take the IF statement out it works just fine.
I also tested to see if the IP match works and it does. Does anyone know what I'm doing wrong?
<?php
mysql_connect("sql1.phpnet.us","user","pass");
mysql_select_db("product_line");
$result = mysql_query("select * from products_view");
$matchip = $_SERVER['REMOTE_ADDR'];
while($r=mysql_fetch_array($result))
{
//the format is $variable = $r["nameofmysqlcolumn"];
//modify these to match your mysql table columns
$user_name=$r["user_name"];
$prod=$r["product_name"];
$description=$r["description"];
$image_url=$r["image_url"];
$ip=$r["ip"];
$id=$r["id"];
if($matchip == $ip){
echo "Product: $prod <br> Description: $description <br>Picture: <br><img src=\"$image_url\"></img><br>Submitted By: $user_name - <a href=\edit.php?q=$id\>Edit Listing</a><hr>";
} else {
echo "Product: $prod <br> Description: $description <br>Picture: <br><img src=\"$image_url\"></img><br>Submitted By: $user_name<hr>";
}
?>
Edit: Mods please delete this thread if you'd like.
I ended up figuring it out on my own. I don't know what the { 's are called but I used too many of them. I assume they are the 'open' and 'close' of certain statements? My apologies.
Fixed code:
<?php
mysql_connect("sql1.phpnet.us","user","pass");
mysql_select_db("product_line");
$result = mysql_query("select * from products_view");
$matchip = $_SERVER['REMOTE_ADDR'];
while($r=mysql_fetch_array($result))
{
//the format is $variable = $r["nameofmysqlcolumn"];
//modify these to match your mysql table columns
$user_name=$r["user_name"];
$prod=$r["product_name"];
$description=$r["description"];
$image_url=$r["image_url"];
$ip=$r["ip"];
$id=$r["id"];
if($matchip == $ip)
echo "Product: $prod <br> Description: $description <br>Picture: <br><img src=\"$image_url\"></img><br>Submitted By: $user_name - <a href=\edit.php?q=$id\>Edit Listing</a><hr>";
else
echo "Product: $prod <br> Description: $description <br>Picture: <br><img src=\"$image_url\"></img><br>Submitted By: $user_name<hr>";
}
?>