Welcome Guest [Log In] [Register]
Add Reply
(resolved)If statements in php
Topic Started: Apr 20 2009, 06:53 PM (205 Views)
cyrus709

Alright this question may seem simple but im missing something here, and i dont know what it is. But the code is not working.

Code: HTML
 

<?php
// Check to see if session is not registered, if it is not redirect the user back to the notloggedin.php file.
// Put this code in first line of every web page that you only want logged-in users to see.
session_start();
if($_SESSION['logged'] != 1){ header("location:home.php"); }
?>
<html>
<head>
</head>
<body>
<h1><?php echo $_GET ['x']; ?> </h1><br><br>
</body>
</html>
<?php
//converts the session variable into another variable
$change= $_GET ['x'];

//connects to server
$con = mysql_connect("hostname", "username", "password");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("DB_NAME", $con );

//displays results

$result = mysql_query("SELECT * FROM TABLE
WHERE coords=$change");
$row = mysql_fetch_array($result);
$png = $row['image'];
if($png = "Images/MapBG.png")
{
mysql_query("UPDATE map SET image = 'Images/blob.png' WHERE coords = '$change'");
}
else
{
print ("Sorry these coordinates are already in use");
}

?>


alright here is what that code is doing:

1) starts a session

2)it then gets information with the GET function

3) it then changes the get variable into another variable, this might not have been necessary but i did it anyways.

4)it then connects to the server, obviously i have taken out DBnames, and DBpass etc.

5) The next part selects the column, and the name.

6) now we are at the "if" statement. It selectcs from the "image" column to see if "Images/MapBG.png" is the image, if it is then it updates the DB.
if not it it runs the else statement and prints that the coordinates are already taken, Once it actually prints it, then i will change the print command to a the DIE() function.



Now the problem is that my else statement is not working.
I can switch whats in the parameters of the if statement and it still runs the IF statement.
i can print $png (which is the variable inside of the if statement) so i know that it is not the variable. The only thing that i can think of is i messed up my if statement, and thus my else statement?[/QUOTE]

[merged double post]
Sorry i found my error, i should have put "==" instead of "=". I ended up rewriting the whole thing, as there were multiple errors in this script.
Edited by Darksorrow131, Apr 21 2009, 05:52 PM.
Therapy is expensive, poppin' bubble wrap is cheap! You choose.
Offline Profile Quote Post Goto Top
 
1 user reading this topic (1 Guest and 0 Anonymous)
« Previous Topic · Web-Based Programming Support · Next Topic »
Add Reply

Banner and Logo by TheKeith