the below code contains if statements depending on usertype and status. It won't display anything. In the code above i had usertype==1 and status==1 and it is working as it should but this below code won't work. Any suggestions? Please ignore the code i have as i am a beginner and the code is messy.
} else if ($usertype == 2) {
$server1 = "localhost";
$user1 = "r";
$pass1 = "";
$db1 = "";
$db4 = "";
$user5 = $_SESSION['username'];
$mysqli = new Mysqli($server1, $user1, $pass1, $db1) or mysqli_error($mysqli);
$mysqli6 = new Mysqli($server1, $user1, $pass1, $db4) or mysqli_error($mysqli);
$name2= $mysqli6->query("SELECT name FROM head WHERE username= '$user5'")->fetch_object()->name2;
$status2 = $mysqli->query("SELECT status FROM Overrides WHERE head = '$name2'")->fetch_object()->status2;
$headforms = $mysqli->query("SELECT * FROM Overrides WHERE head = '$name2' ");
$num_rows2 = mysqli_num_rows($headforms);
if ($status2 == 2) {
echo "Overrides today: " . $num_rows2;
while($row2 = mysqli_fetch_array($headforms)) {
echo "<br /><br />First Name: " . $row2['name'] . "<br />";
echo "<br />Middle Name: " . $row2['mname'] . "<br />";
echo "<br />Family Name: " . $row2['fname'] . "<br />";
echo "<br />Student ID: " . $row2['sid'] . "<br />";
echo "<br />Scolarship: " . $row2['sc'] . "<br />";
echo "<br />Phone No: " . $row2['phone'] . "<br />";
echo "<br />Email: " . $row2['email'] . "<br />";
echo "<br />Class: " . $row2['class'] . "<br />";
echo "<br />Section: " . $row2['section'] . "<br />";
echo "<br />Semester: " . $row2['semester'] . "<br />";
}
}
?>
Concerning the database entries and data, i have checked them and i'm 100% sure it should display correct info.
I did a test : i tried doing print_r($status2); and print_r($name2); but page is empty, could the problem be with the userype == 2 since it's displaying nothing.
errors:
Notice: Undefined property: stdClass::$name2 in /home/aukwizcq/public_html/override.php on line 310
Notice: Trying to get property of non-object in /home/aukwizcq/public_html/override.php on line 311
Related
So i'm hosting servers and trying to make a table displaying the information server name players etc i have a script that displays this but i suck at css, What i'm trying to get is a little like in this website http://echelon.kthx.at/pubbans.php
<?php
include ("BC2Conn.php");
// opens a connection to gameserver
$BC2Conn = new BC2Conn("31.185.143.136", 48888);
if (!$BC2Conn->isConnected()) {
echo "Connection could not be established. " .
"To debug, set '-d' as 3rd parameter to new connection.<br />" .
"<br />" .
"Example: \$BC2Conn = new BC2Conn(\"127.0.0.1\", 48888, \"-d\");";
return 0; // stop executing this script
}
// secure login
// $BC2Conn->loginSecure("password");
// unsecure login (not salted)
// some random serverinformation
echo "Servername: " . $BC2Conn->getServerName() . "<br />";
echo "Players: " . $BC2Conn->getCurrentPlayers() . "/" . $BC2Conn->getMaxPlayers() . "<br />";
echo "Playmode: " . $BC2Conn->getCurrentPlaymodeName() . "<br />";
echo "Current Map: " . $BC2Conn->getCurrentMapName() . "<br /><br /><br /><u>Players:</u><br /><br />";
// playerlist
$playerNames = $BC2Conn->getPlayerlistNames();
foreach ($playerNames as $key => $content) {
if ($BC2Conn->getPlayerClantag($content) != "") {
echo "[" . $BC2Conn->getPlayerClantag($content) . "]";
}
echo " " . $BC2Conn->getPlayername($content) . " - Kills: ";
echo $BC2Conn->getPlayerKills($content) . " | Deaths: ";
echo $BC2Conn->getPlayerDeaths($content) . " | Score: ";
echo $BC2Conn->getPlayerScore($content) . "<br />";
}
// logout
$BC2Conn->logout();
?>
so i have this error , i downloaded the lastest
geoipcity.inc | geoipregionvars.inc | GeoLiteCity.dat
so here is my code :
<?php
/**
* Querying against GeoIP/Lite City
* This will fetch country along with city information
*/
include("geoipcity.inc");
include("geoipregionvars.php");
$giCity = geoip_open("GeoLiteCity.dat",GEOIP_STANDARD);
$ip = "99.99.99.99";
$record = geoip_record_by_addr($giCity, $ip);
echo "Getting Country and City detail by IP Address <br /><br />";
echo "IP: " . $ip . "<br /><br />";
echo "Country Code: " . $record->country_code . "<br />" .
"Country Code3: " . $record->country_code . "<br />" .
"Country Name: " . $record->country_name . "<br />" .
"Region Code: " . $record->region . "<br />" .
"City: " . $record->city . "<br />" .
"Postal Code: " . $record->postal_code . "<br />" .
"Latitude: " . $record->latitude . "<br />" .
"Longitude: " . $record->longitude . "<br />" .
"Metro Code: " . $record->metro_code . "<br />" .
"Area Code: " . $record->area_code . "<br />" ;
geoip_close($giCity);
?>
and here is my problem that
not all resulst are shown :
Country Code: SA
Country Code3: SA
Country Name: Saudi Arabia
Region Code:
City:
Postal Code:
Latitude: 25
Longitude: 45
Metro Code:
Area Code:
So I'm trying to use the fb graph api to gather some information about facebook friends, and the scope of the project kind of depended on all of the fields here (to create a sorting algorithm based on the data).
Unfortunately when I gather all of the data (which takes forever) several of the fields for the friends data are missing. I expected some to be missing, but over half doesn't give me location information, and the all of the religion information is not showing up. I checked some of the friends individual facebook pages to which the data is there and revealed to me as a friend of theirs (they have a current location for instance). Is there something I am doing wrong, or is it just something I can't do. If there another way to gather this, I am open to suggestions. Any thoughts at all would be great!
$config = array(
'appId' => '###############',
'secret' => '########################',
'allowSignedRequest' => false // optional but should be set to false for non-canvas apps
);
$facebook = new Facebook($config);
$user_id = $facebook->getUser();
?>
<html>
<head></head>
<body>
<?php
if($user_id) {
try {
//User Data
$user_profile = $facebook->api('/me','GET');
$locationId = $user_profile['location']['id'];
$location = $user_profile['location']['name'];
$platform = $facebook->api('/'.$locationId,'GET');
date_default_timezone_set('UTC');
echo "Name: " . $user_profile['name'] . "<br />";
echo "Gender: " . $user_profile['gender'] . "<br />";
echo "Birthday: " . $user_profile['birthday']. "<br />";
$date = explode("/", $user_profile['birthday']);
$age = date("Y") - $date[2];
echo "Age: " . $age . "<br />";
echo "Religion: " . $user_profile['religion']. "<br />";
echo "Hometown: " . $user_profile['hometown']['name']. "<br />";
echo "Location: " . $location . "<br />";
echo "Longitude: " . $platform['location']['longitude']. "<br />";
echo "Latitude: " . $platform['location']['latitude']. "<br />";
//Friend Data
$friends = $facebook->api('/me/friends', 'GET');
echo "<br />";
echo "Friend Test <br />";
foreach($friends["data"] as $value) {
$c_id = $value['id'];
echo $c_id. "<br />";
$c_friend = $facebook->api('/'.$c_id);
echo "Name: ". $c_friend['name'] . "<br />";
echo "Gender: ". $c_friend['gender']. "<br />";
echo "Birthday: ". $c_friend['birthday']. "<br />";
echo "Religion: ". $c_friend['religion']."<br />";
echo "Hometown: ". $c_friend['hometown']['name']. "<br />";
echo "Location: ". $c_friend['location']['name']. "<br />";
$c_locationId = $c_friend['location']['id'];
if($c_locationId)
{
$c_platform = $facebook->api('/'.$c_locationId,'GET');
echo "Longitude: ". $c_platform['location']['longitude']. "<br />";
echo "Latitude: ". $c_platform['location']['latitude']. "<br />";
}
echo "<br />";
}
} catch(FacebookApiException $e) {
// If the user is logged out, you can have a
// user ID even though the access token is invalid.
// In this case, we'll get an exception, so we'll
// just ask the user to login again here.
$login_url = $facebook->getLoginUrl(array("scope" => "user_religion_politics,user_birthday,user_hometown,user_location,friends_religion_politics,friends_birthday,friends_hometown,friends_location"));
echo "Place 1 <br />";
echo 'Please login.';
error_log($e->getType());
error_log($e->getMessage());
}
} else {
// No user, print a link for the user to login
$login_url = $facebook->getLoginUrl(array("scope" => "user_religion_politics,user_birthday,user_hometown,user_location,friends_religion_politics,friends_birthday,friends_hometown,friends_location"));
echo "Place 2<br />";
echo 'Please login.';
}
?>
</body>
</html>
So, I'll post the code below. Beneath the code is where I will pose my question.
if (!empty($_SESSION['username']) && !empty($_SESSION['password']))
{
$server=mysql_real_escape_string($_POST['server']);
$teamname=mysql_real_escape_string($_POST['teamname']);
$creator=$_SESSION['username'];
$verify = mysql_real_escape_string($_POST['verify']);
$date = date("F j, Y, g:i a");
if (!empty($teamname)) {
// if ($verify == "wookie" ||
// $verify == "Wookie" ||
// $verify == "WOOKIE")
// {
$sql="INSERT INTO rated_teams (server, name, creator, created, players, win, loss)
VALUES ('$server', '$teamname', '$creator','$date', '', '', '')";
if (mysql_query($sql,$con))
{
echo "<p>Added ". $teamname . " on " . $server . " by " . $creator . " on " . $date ." <br /><a href='myprofile.php'>Return to Profile</a></p>";
}
else
{
echo $sql . "<br />";
echo "<br /><h1>Error</h1>";
echo "<p><a href='myprofile.php'>Sorry, your team registration has failed. Please go back and try again.</a></p>
<br />" . $teamname . " on " . $server . " by " . $creator . " on " . $date;
}
//} else { echo "That isn't how you spell Wookie!"; }
} else { echo "Team Name is empty, <a href='myprofile.php'>go back and give yourself a Team Name</a>"; }
} else { echo "You must be <a href='login.php'>logged in</a>!"; }
This issue is that the line "if (mysql_query($sql,$con))" goes directly to the ELSE. I'm assuming the problem lies with my $sql but I can't pinpoint where it is. Another pair of eyes would really help. Thanks a bunch!
To trace errors with mysql_query() , you should use mysql_error(). Here's an example, inspired of one of the PHP mysql_error() doc
$sql="INSERT INTO rated_teams (server, name, creator, created, players, win, loss)
VALUES ('$server', '$teamname', '$creator','$date', '', '', '')";
mysql_query($sql,$con);
if (mysql_errno()) {
$error = "MySQL error ".mysql_errno().": ".mysql_error()."\n<br>When executing:<br>\n$sql\n<br>";
// Your stuff
echo $sql . "<br />";
echo "<br /><h1>Error</h1>";
echo "<p><a href='myprofile.php'>Sorry, your team registration has failed. Please go back and try again.</a></p>
<br />" . $teamname . " on " . $server . " by " . $creator . " on " . $date;
}
else {
echo "<p>Added ". $teamname . " on " . $server . " by " . $creator . " on " . $date ." <br /><a href='myprofile.php'>Return to Profile</a></p>";
}
Also, you should use PDO or mysqli, since mysql_* are deprecated since PHP 5.x
Uploading an image into a directory, it seems to always try upload "" which is nothing. Rather then an actual image. What am I doing below. I know the value is "" because of what it inserts into the database.
<li class="formProductImage">
<span>Image:</span>
<input type="file" name="productImage" />
</li>
and the php:
if ($_FILES["productImage"]["error"] > 0)
{
echo "Return Code: " . $_FILES["productImage"]["error"] . "<br />";
}
else
{
echo "Upload: " . $_FILES["productImage"]["name"] . "<br />";
echo "Type: " . $_FILES["productImage"]["type"] . "<br />";
echo "Size: " . ($_FILES["productImage"]["size"] / 1024) . " Kb<br />";
echo "Temp file: " . $_FILES["productImage"]["tmp_name"] . "<br />";
$filename = mysql_real_escape_string($_FILES['productImage']['name']);
$query = "UPDATE products SET image = '$filename' WHERE name = '$name'";
$result = mysql_query($query);
if (mysql_affected_rows() == 1) {
// Show thank you message
echo '<span style="color:green;">Your image was added to database correctly.</span>';
if (file_exists("uploaded/" . $_FILES["productImage"]["name"]))
{
echo $_FILES["productImage"]["name"] . " already exists. ";
}
else
{
move_uploaded_file($_FILES["productImage"]["tmp_name"],
"uploaded/" . $_FILES["productImage"]["name"]);
echo "Stored in: " . "uploaded/" . $_FILES["productImage"]["name"];
}
} else {
echo '<font color="red">Image note inserted into database.</font>';
echo mysql_error();
}
}
}
}
Make sure you have enctype="multipart/form-data" in the <form> tag.
change this line:
$filename = mysql_real_escape_string($_FILES['file']['name']);
to :
$filename = mysql_real_escape_string($_FILES['productImage']['name']);