I'm using php for a profiles site that I'm working on and I need to check that the profile id doesn't equal the member id. So I have this:
<?php
$get_personal_sql = "SELECT * FROM members WHERE username = '$thisuser'";
$get_personal_res = mysqli_query($con, $get_personal_sql);
while ($personal = mysqli_fetch_assoc($get_personal_res)){
$yourid = $personal['id'];
$yourtype = $personal['type'];
$yoursubtype = $personal['subtype'];
$yourusername = $personal['username'];
$youremail = $personal['email'];
$yourname = $personal['name'];
$youractive = $personal['active'];
$yourpro = $personal['pro'];
$yourdel = $personal['del'];
$yourdate = $personal['date'];
}
?>
<?php
$get_member_sql = "SELECT * FROM members WHERE username = '$thismember'";
$get_member_res = mysqli_query($con, $get_member_sql);
$count_member = mysqli_num_rows($get_member_res);
if($count_member == 0){
header("Location: notfound.php");
}
while ($member = mysqli_fetch_assoc($get_member_res)){
$memberid = $member['id'];
$membertype = $member['type'];
$membersubtype = $member['subtype'];
$memberusername = $member['username'];
$memberemail = $member['email'];
$membername = $member['name'];
$memberactive = $member['active'];
$memberpro = $member['pro'];
$memberdel = $member['del'];
$memberdate = $member['date'];
}
?>
<?php
if($memberid === $yourid){
$yourprofile = "true";
}
else{
$yourprofile = "false";
}
?>
I have echoed both $memberid & $yourid in the page and they are Completely different, yet when I echo $yourprofile it displays "true". Can anyone see why this might be?
Related
My first page is owner details then I send id and show owner wise driver in driver details page if I select particular driver and show information in third page for select driver. In this page selected driver information show currently but when I perform update query so data not updated what I do. My problem is that show and update in same page and how to pass id of select item
<?php
include("config.php");
$d_idd = $_GET['d_id'];
$_SESSION['d_id'] = $d_idd;
$d_id = $_SESSION['d_id'];
//print_r("select * from tbl_multiple_driver where Id = '$d_id'");
die();
$driverUpdate = sqlsrv_query($conn,"select * from tbl_multiple_driver where Id = '$d_id'");
while($driverdetails = sqlsrv_fetch_array($driverUpdate)){
$id = $driverdetails['Id'];
$name = $driverdetails['driver_name'];
$mobile = $driverdetails['driver_mobile'];
$dob = $driverdetails['driver_birth_date'];
$address = $driverdetails['driver_address'];
$location = $driverdetails['location'];
$city = $driverdetails['city'];
$pincode = $driverdetails['driver_pincode'];
$pick_up_area = $driverdetails['PickUp_Area'];
$vehicle_no = $driverdetails['vehicle_reg_no'];
$vehicle_company = $driverdetails['V_id'];
$vehicle_module = $driverdetails['V_id'];
$user_name = $driverdetails['username'];
$reg_date = $driverdetails['reg_date'];
$vehicle = "SELECT * FROM Vehicle where id = '$vehicle_company'";
$vehicleDisplay = sqlsrv_query($conn,$vehicle);
while($vehicleDetails = sqlsrv_fetch_array($vehicleDisplay)){
$vehicleModel = $vehicleDetails['Vehicle_Model_id'];
}
$vehicleMod = "SELECT * FROM Vehicle_Modle where id = '$vehicleModel'";
$vehicleModDisplay = sqlsrv_query($conn,$vehicleMod);
while($vehicleModDetails = sqlsrv_fetch_array($vehicleModDisplay)){
$vehicleId = $vehicleModDetails['vehicle_id'];
$vehicleModName = $vehicleModDetails['vehicle_modle_Name'];
}
$Mainvehicle = "SELECT * FROM MainVehicle where id = '$vehicleId'";
$mainvehicleDisplay = sqlsrv_query($conn,$Mainvehicle);
while($mainvehicleDetails = sqlsrv_fetch_array($mainvehicleDisplay)){
$vehiclename = $mainvehicleDetails['vehicle_company'];
}
}
?>
<?php
if(isset($_POST['btnUpdate'])){
//$id = $_POST['Id'];
$dName = $_POST['txtDriverName'];
$dMobile = $_POST['txtMobileNumber'];
$dDob = $_POST['txtDob'];
$dAddress = $_POST['txtDriverAddress'];
$dLocation = $_POST['Location'];
$dCity = $_POST['city'];
$dPincode = $_POST['pincode'];
$dPickUp = $_POST['txtPickup'];
$dVehicleNo = $_POST['txtVehicleNo'];
//print_r("update tbl_multiple_driver set driver_name = '$dName',driver_mobile='$dMobile',driver_birth_date='$dDob',driver_address='$dAddress',location='$dLocation', city='$dCity',driver_pincode='$dPincode',PickUp_Area='$dPickUp', vehicle_reg_no='$dVehicleNo' where Id= '$id' "); die();
$driver_update = "update tbl_multiple_driver set driver_name = '$dName',driver_mobile='$dMobile',driver_birth_date='$dDob',driver_address='$dAddress',location='$dLocation', city='$dCity',driver_pincode='$dPincode',PickUp_Area='$dPickUp', vehicle_reg_no='$dVehicleNo' where Id= '$id' ";
$res = sqlsrv_query($conn,$driver_update);
if($res){
echo '<script language="javascript">';
echo 'window.location.href = Details.php';
echo '</script>';
}
// header('location:Details.php');
}
?>
On user select you have to pass id again and then update info on base of this id:
$driver_update = "update tbl_multiple_driver set driver_name = '$dName',
driver_mobile='$dMobile',driver_birth_date='$dDob',driver_address='$dAddress',
location='$dLocation', city='$dCity',driver_pincode='$dPincode',
PickUp_Area='$dPickUp', vehicle_reg_no='$dVehicleNo' where Id='".$isession['d_id']."' ";
I'm trying to get something output from a SQLite database using PHP. So far I'm able to output the field from the database but I'm only looking for a specific portion of that field to be output. Is there anyway to tailor the output before echoing the row?
Here's my code so far:
<?php
$DatabaseFile = (string)"STHS.db";
$Team = (integer)0;
$Query = (string)"";
$Title = (string)"";
$TeamName = (string)"";
if($_GET){$Team = $_GET['Team'];}
If (file_exists($DatabaseFile) == false){
$LeagueName = "Unknown League";
$LeagueOwner = "Unknown League Owner";
$Title = "Unknown League";
$Team == 0;
$TeamName = "Database File Not Found";
}else{
$db = new SQLite3($DatabaseFile);
$LeagueName = $db->querySingle('Select Name FROM LeagueGeneral');
$LeagueOwner = $db->querySingle('Select LeagueOwner FROM LeagueGeneral');
$MainQuery = "SELECT Name FROM TeamProInfo WHERE Number = '$Team'" ;
$TeamName = $db->querySingle($MainQuery);
}
{
$TeamQuery = "SELECT * FROM TeamLog WHERE Team = '$Team'";
$TeamTrans = $db->query($TeamQuery);
$TeamTextQuery = "SELECT * FROM TeamLog WHERE Team = '$Team' AND Text LIKE '%TRADE : FROM $TeamName%' ";
$TeamText = $db->query($TeamTextQuery);
}
?>
<body>
<?php echo $TeamName ?>
<?php while ($row1 = $TeamText ->fetchArray()) { ?>
<?php echo $row1['Text'] ?>
<?php } ?>
I am trying to set a session variable from page to another. It was working on my localhost but then I uploaded it to my server and now it fails. I have done some basic bug tests, and it will print at specific points, I have labeled them in the code. Here is the code the code I am using
//PAGE 1
session_start();
if(isset($_REQUEST['id'])){
$_SESSION['id'] = $_REQUEST['id'];
//prints here just fine then fails after
header('location: app.php');
}elseif($_POST){
if(isset($_SESSION['error'])){
unset($_SESSION['error']);
}
$questions = array();
for($i = 1; $i <= 11; $i++){
$questions['q'.$i] = $_POST['q'.$i];
}
$check = "";
foreach($questions as $key => $val){
$check .= $val;
}
$metreq = strcmp($check, "1111-1-1-1-11-1-1");
if(!$metreq){
$_SESSION['questionaire'] = $questions;
header("location: app.php");
}else{
header('location: nq.php');
}
}
///PAGE 2
<?php
error_reporting(E_ALL); ini_set('display_errors', 1);
session_start();
require_once('inc/state_list_options.php');
if(isset($_SESSION['questionaire']) || isset($_SESSION['id'])){
$id = $first_name = $middle_name = $last_name = $suffix = $address = $city = $state = $zip = $phone_area = $phone_exch =
$phone_num = $phone2_area = $phone2_exch = $phone2_num = $email_address = $birth_month = $birth_day = $birth_year =
$job = $referred = "";
$selected = "selected";
$questions = array();
//here we will generate a session id that is the code passed from the link clicked by the user
$conn = mysql_connect('host', 'user', 'password');
mysql_select_db('db', $conn);
if($conn){
if(isset($_SESSION['id'])){
$id = $_SESSION['id'];
$q = "SELECT * FROM eagle.pre_application WHERE id = '$id'";
$r = mysql_query($q, $conn);
$row = mysql_fetch_assoc($r);
$first_name = $row['first_name'];
$middle_name = $row['middle_name'];
$last_name = $row['last_name'];
$suffix = $row['suffix'];
$address = $row['address'];
$city = $row['city'];
$state = $row['state'];
$zip = $row['zip'];
$phone_area = $row['phone_area'];
$phone_exch = $row['phone_exch'];
$phone_num = $row['phone_num'];
$phone2_area = $row['phone2_area'];
$phone2_exch = $row['phone2_exch'];
$phone2_num = $row['phone2_num'];
$email_address = $row['email_address'];
$birth_month = $row['birth_month'];
$birth_day = $row['birth_day'];
$birth_year = $row['birth_year'];
$questions['q1'] = $row['q1'];
$questions['q2'] = $row['q2'];
$questions['q3'] = $row['q3'];
$questions['q4'] = $row['q4'];
$questions['q5'] = $row['q5'];
$questions['q6'] = $row['q6'];
$questions['q7'] = $row['q7'];
$questions['q8'] = $row['q8'];
$questions['q9'] = $row['q9'];
$questions['q10'] = $row['q10'];
$questions['q11'] = $row['q11'];
$_SESSION['questionaire'] = $questions;
}
$q2 = "SELECT job_posting.id, job_posting.title, location.city, location.state
FROM eagle.job_posting
LEFT JOIN eagle.location
ON job_posting.location__Id = location.id";
$j = mysql_query($q2, $conn);
?>
<!-- job application goes ehre -->
<?
}else{
$_SESSION['error'] = "Please fill out the questionaire before completing the applicationn.";
header('location: index.php');
exit;
}
}else{
echo "There is an error";
}
?>
I'm not 100% sure where to go from this point forward. I was thinking that it was the headers causing and issue, but that has never appeared so at this poitn I am baffled. Please let me know what you think about this. If you need additional code or further examples please let me know and I can provide them for you. Thank you in advance to anyone who stops by to help!
EDITS/DEVELOPMENTS/UPDATES
9:07 AM: Using developer's tools on chrome it is now receiving a 500 server error when submitting to page 2
9:16 AM Removed errors found with the require_once(''); There was an error in the path. Now it just automatically goes to the redirect on page 2 even if a variable is manually passed in the header via the address bar. I'm stumped still. code updated to reflect changes
I'm building a website to learn PHP and have just built a membership app.
Here's my code to get the user cookies that I set when the user logs in, then take the business id they are associated with, called biz and look up all the details for the business with the id equal to biz, in the table named company: (btw, I know I'm using mysql but when I finalize my app, I'll switch to PDO or mysqli)
<?
$auth = $_COOKIE["auth"];
if ($auth != "1"){
header("Location: ./signin.php");
}
//Grab all the cookies
$firstname = $_COOKIE['firstname'];
$id = $_COOKIE['id'];
$fname = ucwords($_COOKIE['firstname']);
$lname = ucwords($_COOKIE['lastname']);
$email = $_COOKIE['email'];
$city = ucwords($_COOKIE['city']);
$biz = $_COOKIE['biz'];
if(!empty($biz)){
$donthaveabizyet = "false";
}
else{
include("./config.php");
$result = mysql_query("SELECT * FROM company WHERE id = '$biz'") or mysql_error();
while($row = mysql_fetch_array($result))
{
$business_name = $row['name'];
$business_phone = $row['phone'];
$business_website = $row['website'];
$business_phone = $row['phone'];
$business_cat1 = $row['cat1'];
$business_cat2 = $row['cat2'];
$business_cat3 = $row['cat3'];
$business_subcat1 = $row['subcat1'];
$business_subcat2 = $row['subcat2'];
$business_subcat3 = $row['subcat3'];
$business_email = $row['email'];
$business_product1 = $row['product1'];
$business_product2 = $row['product2'];
$business_product3 = $row['product3'];
$business_product4 = $row['product4'];
$business_product5 = $row['product5'];
$business_product6 = $row['product6'];
$business_product7 = $row['product7'];
$business_noaddress = $row['noaddress'];
$business_address = $row['address'];
$business_address2 = $row['address2'];
$business_zipcode = $row['zipcode'];
$business_city = $row['city'];
}
$result = mysql_query("SELECT * FROM company_secondary WHERE company_id = '$biz'") or mysql_error();
while($row = mysql_fetch_array($result))
{
$business_description = $row['company_description'];
$business_since = $row['phone'];
$business_logo = $row['logo'];
$business_since = $row['since'];
$business_smoking = $row['smoking'];
$business_delivery = $row['delivery'];
$business_alcohol = $row['alcohol'];
$business_kids = $row['kids'];
$business_wheelchair = $row['wheelchair'];
$business_twitter = $row['twitter'];
$business_facebook = $row['facebook'];
$business_youtube = $row['youtube'];
$business_creditcards = $row['creditcards'];
$business_outdoor = $row['outdoor'];
$business_featured = $row['featured'];
}
}
?>
Now I show a link to claim.php if the user's business id is equal to 0, or if the user's business id is set, I show the name of the business.
<?php
if($donthaveabizyet != "false")
{
echo "<br/><br/>You haven't claimed a business yet. <a href='claim.php'>Click here to claim one now.</a>";
}
else
{
echo $business_name;
}
?>
Unfortunately, $business_name isn't displaying, and the error is Notice: Undefined variable: business_name. Why is business_name not set?
Big thanks for all help!!
while($row = mysql_fetch_array($result))
{
is causing your problem. Change it to
while($row = mysql_fetch_assoc($result))
{
This is because fetch_array creates an array with numeric indexes ($array[1], $array[2], etc.). fetch_assoc makes the indexes the same as the column names ($array['this'], $array['that'], etc.)
I need help with this code, i need it to add an array in Gangs
under members and seperate them with -
I need every member in the Gang to be listed under Members and separated with -
so i can explode them below.
This is the line that adds the members to gangs but its without - and i think it erases members that are already there.
$result = mysql_query("UPDATE Gangs SET members='".$name."'WHERE name='".mysql_real_escape_string($_POST['gang_name'])."'")
or die(mysql_error());
full code
if(isset($_POST['creategang'])){
if(empty($_POST['gang_name'])){
echo "Enter a Gang Name.";
} else {
if (strlen($_POST['gang_name']) > "20"){
echo "The username may not consist out of more then 20 characters.";
}else{
if (ereg('[^A-Za-z0-9]', $_POST['gang_name'])) {
echo "Invalid Name only A-Z,a-z and 0-9 is allowed.";
}else{
$sql = "SELECT name FROM Gangs WHERE name='".mysql_real_escape_string($_POST['gang_name'])."'";
$query = mysql_query($sql) or die(mysql_error());
$m_count = mysql_num_rows($query);
if($m_count >= "1"){
echo 'This name has already been used.!';
}else{
$sql = "INSERT INTO Gangs SET name = '".$_POST['gang_name']."' , owner= '$name'";
$res = mysql_query($sql);
$result = mysql_query("UPDATE users SET gang='".mysql_real_escape_string($_POST['gang_name'])."' WHERE id='" .mysql_real_escape_string($_SESSION['user_id']). "'")
or die(mysql_error());
$result = mysql_query("UPDATE Gangs SET members='".$name."'WHERE name='".mysql_real_escape_string($_POST['gang_name'])."'")
or die(mysql_error());
echo 'Gang successfully created!';
}
}
}
}
}
?>
this is the code i will use to separate the array
$Gang_array = explode("-", $Gang_members);
Thanks for viewing my question and thanks in advance for helping me
new code to add to gang
<? include_once("connect.php"); ?>
<?
if(isset($_SESSION['user_id'])) {
// Login OK, update last active
$sql = "UPDATE users SET lastactive=NOW() WHERE id='".mysql_real_escape_string($_SESSION['user_id'])."'";
mysql_query($sql);
}else{
header("Location: index.php");
exit();
}
$sql = "SELECT * FROM users WHERE id='".mysql_real_escape_string($_SESSION['user_id'])."'";
$query = mysql_query($sql) or die(mysql_error());
$row = mysql_fetch_object($query);
$id = htmlspecialchars($row->id);
$userip = htmlspecialchars($row->userip);
$name = htmlspecialchars($row->name);
$sitestate = htmlspecialchars($row->sitestate);
$password = htmlspecialchars($row->password);
$mail = htmlspecialchars($row->mail);
$money = htmlspecialchars($row->money);
$exp = htmlspecialchars($row->exp);
$rank = htmlspecialchars($row->rank);
$health = htmlspecialchars($row->health);
$points = htmlspecialchars($row->points);
$profile = htmlspecialchars($row->profile);
$gang = htmlspecialchars($row->gang);
?>
<?php
$sql = "SELECT * FROM Gangs WHERE name='".mysql_real_escape_string($_GET['name'])."'";
$query = mysql_query($sql) or die(mysql_error());
$row = mysql_fetch_object($query);
$Gang_name = htmlspecialchars($row->name);
$Gang_owner = htmlspecialchars($row->owner);
$Gang_money = htmlspecialchars($row->money);
$Gang_exp = htmlspecialchars($row->exp);
$Gang_level = htmlspecialchars($row->level);
$Gang_members = htmlspecialchars($row->members);
$Gang_array = explode("-", $Gang_members);
$Gang_profile = htmlspecialchars($row->profile);
?>
<div id="content" class="profile">
<h2>Gang Profile</h2>
<form method="post" >
<input type="submit" name="Petition" id="Petition" value="Petition">
</form>
<center>
<h1><?php echo $Gang_name; ?></h1>
Owner: <?php echo $Gang_owner; ?><br>
Gang Cash: $<?php echo $Gang_money; ?><br>
Gang Exp: <?php echo $Gang_exp; ?><br>
Gang Level: <?php echo $Gang_level; ?><br>
Gang Members: <?php echo $Gang_array; ?><br>
</center><br>
<p>Gang Quote</p>
<div id="UserText">
<?php
$Gang_profile = htmlentities($Gang_profile);
$Gang_profile = nl2br($Gang_profile);
$Gang_profile = stripslashes($Gang_profile);
echo $Gang_profile; ?>
</div>
</div>
<?
if (isset($_POST['Petition'])) {
$result = mysql_query("SELECT members FROM Gangs
WHERE name='".$Gang_name."'");
if ($result) {
while($row = mysql_fetch_assoc($result)) {
$members = $row['members'];
}
}
if ($members != '') $members .= '-'.$name;
else $members = $name;
$result = mysql_query("UPDATE Gangs SET members='".$members."' WHERE name='".$Gang_name."'");
}
If I understand your question correctly. You can try this :
Get the members first :
$result = mysql_query("SELECT members FROM Gangs
WHERE name='".mysql_real_escape_string($_POST['gang_name'])."'");
if ($result) {
while($row = mysql_fetch_assoc($result)) {
$members = $row['members'];
}
}
Then add new member and do update :
//This is to check whether $name is already in the gangs
if (strpos($members,$name) !== false) {
if ($members != '') $members .= '-'.$name;
else $members = $name;
//Update to gangs
$result = mysql_query("UPDATE Gangs SET members='".$members."' WHERE name='".mysql_real_escape_string($_POST['gang_name'])."'");
}
else sprintf("%s is in the gangs already",$name);
Hope it helps.
Pseudo code, but this should probably work:
$result = mysql_query("UPDATE Gangs SET members = members + '-' + '".$name."'WHERE name='".mysql_real_escape_string($_POST['gang_name'])."'")
or die(mysql_error());