<?php
if (isset($_GET['id']) && filter_var($_GET['id'], FILTER_VALIDATE_INT)) {
$id=$_GET['id'];
}else{
header('HTTP/1.0 404 Not Found');
exit("<h1>Not Found</h1>\n<p>The submitted data is not valid.</p>");
}
$query = "SELECT * FROM all_parks WHERE id = $id";
$result = mysqli_query($conn, $query) or die ("Error querying database.");
$row = mysqli_fetch_array($result);
$state = $row['state'];
$type = $row['type'];
$name = $row['name'];
$short_intro = $row['short_intro'];
$long_description = $row['long_description'];
$parkimage = $row['image_url'];
$allowed = $row['allowed'];
$not_allowed = $row['not_allowed'];
$warnings = $row['warnings'];
$more_details = $row['more_details'];
$neighboring_parks = ['neighboring_parks'];
$website = ['website'];
$camping = ['camping'];
$hiking = ['hiking'];
$volunteer = ['volunteer'];
$map = ['google_map_location'];
$telephone = ['telephone'];
$email = ['email'];
?>
$map, $website, $camping, $hiking is giving a 404 error for the link
$parkimage is not showing
$volunteer, $donate, $neighboring_parks is echoing 'Array' on the page
you forgot to write $row , Use this code-
<?php
if (isset($_GET['id']) && filter_var($_GET['id'], FILTER_VALIDATE_INT)) {
$id=$_GET['id'];
}else{
header('HTTP/1.0 404 Not Found');
exit("<h1>Not Found</h1>\n<p>The submitted data is not valid.</p>");
}
$query = "SELECT * FROM all_parks WHERE id = $id";
$result = mysqli_query($conn, $query) or die ("Error querying database.");
$row = mysqli_fetch_array($result);
$state = $row['state'];
$type = $row['type'];
$name = $row['name'];
$short_intro = $row['short_intro'];
$long_description = $row['long_description'];
$parkimage = $row['image_url'];
$allowed = $row['allowed'];
$not_allowed = $row['not_allowed'];
$warnings = $row['warnings'];
$more_details = $row['more_details'];
$neighboring_parks = $row['neighboring_parks'];
$website = $row['website'];
$camping = $row['camping'];
$hiking = $row['hiking'];
$volunteer = $row['volunteer'];
$map = $row['google_map_location'];
$telephone = $row['telephone'];
$email = $row['email'];
?>
It Will Work.
Use while ($row = mysqli_fetch_array($result)), it will work.
Related
Title.... The if statement below isn't working, i added to console log to check what the condition is returning and it checks out. Anyone know whats wrong with it? the variable $check is created in another file not here. If the variable check wasn't putting out the correct value it would obviously not work but it does put out the right value.
session.php
<?php
// mysqli_connect() function opens a new connection to the MySQL server.
$conn = mysqli_connect("localhost", "root", "", "sports world");
session_start();// Starting Session
// Storing Session
$user_check = $_SESSION['login_user2'];
$p = $_SESSION['login_user3'];
$check = $_SESSION['check'];
?>
<script> let check = "<?php echo $check; ?>";
console.log(check)</script>
<?php
if ($check === 'user') {
// SQL Query To Fetch Information Of User
$query = "SELECT Username from staff where Username = '$user_check'";
$ses_sql = mysqli_query($conn, $query);
$row = mysqli_fetch_assoc($ses_sql);
$login_session = $row['Username'];
// SQL Query To Fetch Information Of User
$query2 = "SELECT StaffCode from staff where Username = '$user_check' AND Password = '$p'";
$ses_sql2 = mysqli_query($conn, $query2);
$row2 = mysqli_fetch_assoc($ses_sql2);
$cust = $row2['StaffCode'];
$_SESSION['CustCode'] = $cust;
// SQL Query To Fetch Information Of User
$query3 = "SELECT StaffGivenName As 'Given Name', StaffSurname As 'Surname' from staff where StaffCode = '$cust'";
$ses_sql3 = mysqli_query($conn, $query3);
$row3 = mysqli_fetch_assoc($ses_sql3);
$name1 = $row3['Given Name'];
$name2 = $row3['Surname'];
$_SESSION['Given Name'] = $name1;
$_SESSION['Surname'] = $name2;
// SQL Query To Fetch Information Of User
$queryAccountDeatils = "SELECT StaffDob As 'Date of Birth', StaffGender As 'Gender', StaffAddress1 As 'Address', StaffAddress2 As 'Region', StaffPostCode As 'Post Code', StaffPhone As 'Phone Number', StaffEmail As 'Email', StaffTFN As 'Message Preferences', StaffEmerConName As 'Member Type', StaffEmerConPhone As 'Sports' from staff where StaffCode = '$cust'";
$ses_sql4 = mysqli_query($conn, $queryAccountDeatils);
$row4 = mysqli_fetch_assoc($ses_sql4);
$Dob = $row4['Date of Birth'];
$Address = $row4['Address'];
$Gender = $row4['Gender'];
$Region = $row4['Region'];
$PostCode = $row4['Post Code'];
$PhoneNumber = $row4['Phone Number'];
$Email = $row4['Email'];
$MessagePref = $row4['Message Preferences'];
$MemberType = $row4['Member Type'];
$Sports = $row4['Sports'];
$_SESSION['Date of Birth'] = $Dob;
$_SESSION['Address'] = $Address;
$_SESSION['Gender'] = $Gender;
$_SESSION['Region'] = $Region;
$_SESSION['Post Code'] = $PostCode;
$_SESSION['Phone Number'] = $PhoneNumber;
$_SESSION['Email'] = $Email;
$_SESSION['Message Preferences'] = $MessagePref;
$_SESSION['Member Type'] = $MemberType;
$_SESSION['Sports'] = $Sports;
} else if ($check === 'staff') {
// SQL Query To Fetch Information Of User
$query = "SELECT Username from login where Username = '$user_check'";
$ses_sql = mysqli_query($conn, $query);
$row = mysqli_fetch_assoc($ses_sql);
$login_session = $row['Username'];
// SQL Query To Fetch Information Of User
$query2 = "SELECT CustCode from login where Username = '$user_check' AND Password = '$p'";
$ses_sql2 = mysqli_query($conn, $query2);
$row2 = mysqli_fetch_assoc($ses_sql2);
$cust = $row2['CustCode'];
$_SESSION['CustCode'] = $cust;
// SQL Query To Fetch Information Of User
$query3 = "SELECT CustGivenName As 'Given Name', CustSurname As 'Surname' from customers where CustCode = '$cust'";
$ses_sql3 = mysqli_query($conn, $query3);
$row3 = mysqli_fetch_assoc($ses_sql3);
$name1 = $row3['Given Name'];
$name2 = $row3['Surname'];
$_SESSION['Given Name'] = $name1;
$_SESSION['Surname'] = $name2;
// SQL Query To Fetch Information Of User
$queryAccountDeatils = "SELECT CustDob As 'Date of Birth', CustGender As 'Gender', CustAddress1 As 'Address', CustAddress2 As 'Region', CustPostCode As 'Post Code', CustPhone As 'Phone Number', CustEmail As 'Email', CustMsgPref As 'Message Preferences', CustMemberType As 'Member Type', CustSports As 'Sports' from customers where CustCode = '$cust'";
$ses_sql4 = mysqli_query($conn, $queryAccountDeatils);
$row4 = mysqli_fetch_assoc($ses_sql4);
$Dob = $row4['Date of Birth'];
$Address = $row4['Address'];
$Gender = $row4['Gender'];
$Region = $row4['Region'];
$PostCode = $row4['Post Code'];
$PhoneNumber = $row4['Phone Number'];
$Email = $row4['Email'];
$MessagePref = $row4['Message Preferences'];
$MemberType = $row4['Member Type'];
$Sports = $row4['Sports'];
$_SESSION['Date of Birth'] = $Dob;
$_SESSION['Address'] = $Address;
$_SESSION['Gender'] = $Gender;
$_SESSION['Region'] = $Region;
$_SESSION['Post Code'] = $PostCode;
$_SESSION['Phone Number'] = $PhoneNumber;
$_SESSION['Email'] = $Email;
$_SESSION['Message Preferences'] = $MessagePref;
$_SESSION['Member Type'] = $MemberType;
$_SESSION['Sports'] = $Sports;
}
Well.... this is embarrassing, the condition staff and user were on the wrong statements just had to switch them.
The $imagedoes not get assigned any thing. The alert displays an empty string. The update query is working perfectly.
<?php
if(isset($_POST['EditProfilebu']))
{
$id = $_GET['id'];
$username = $_POST['Name'];
$Email = $_POST['Email'];
$PostalCode = $_POST['PostalCode'];
$Address = $_POST['Address'];
$text = $_POST['text'];
$image = $_FILES['image']['name'];
$image_tmp = $_FILES['image']['tmp_name'];
move_uploaded_file($image_tmp,"images/$image");
echo "<script>alert('$image')</script>";
move_uploaded_file($image_tmp,"images/$image");
$query = "update users set UserName='$username',UserEmail='$Email',Picture='$image',PostalCode='$PostalCode',Address='$Address',Text='$text' where UserId='$id'";
$run = mysqli_query($mysqli,$query);
if($run)
{
echo "<script>alert('Updated')</script>";
}
}
?>
When I tried to update some data in my library management system, the data doesn't update. It just keep on saving the same data. Here's the code:
if(isset($_POST['submit'])){
$postID = #$_POST['stud_id'];
$getID = #$_GET['stud_id'];
$postFullName = $_POST['fullname'];
$postEmail = $_POST['email'];
$postContact = $_POST['contact'];
$postSection =$_POST ['section'];
$postUsername = $_POST['username'];
$postPassword = $_POST['password'];
$postType = $_POST['type'];
$postStatus = $_POST['status'];
$rs3 = $db->query("SELECT * FROM users WHERE stud_id = '$postID' ");
$check = $rs3->num_rows;
if ($check > 0)
{
if ($action == "edit")
{
$edit = $db -> query("UPDATE users SET stud_id='$postID', fullname = '$postFullName', email = '$postEmail' , contact = '$postContact', section = '$postSection',username = '$postUsername',password = '$postPassword',type = '$postType', status = '$postStatus' WHERE user_id = '$postID' ");
echo "Record Updated.";
}
else
{
$edit = $db -> query("UPDATE users SET stud_id='$postID', fullname = '$postFullName', email = '$postEmail' , contact = '$postContact', section = '$postSection',username = '$postUsername',password = '$postPassword',type = '$postType', status = '$postStatus' WHERE user_id = '$postID' ");
echo "Record Updated.";
}
}
ill like to remove the sha1 encryption on this code so i can store my password as typed in the database instead of the encrypted code. Am new to coding so I need help
The code (settings_model.php)
<?php
$settings = new Datasettings();
if(isset($_GET['q'])){
$settings->$_GET['q']();
}
class Datasettings {
function __construct(){
if(!isset($_SESSION['id'])){
header('location:../../');
}
}
function changepassword(){
include('../../config.php');
$username = $_GET['username'];
$password = $_GET['password'];
$current = sha1($_POST['current']);
$new = sha1($_POST['new']);
$confirm = sha1($_POST['confirm']);
$q = "select * from userdata where username='$username' and password='$current'";
$r = mysqli_query($db,$q);
if(mysqli_num_rows($r) > 0){
if($new == $confirm){
$r2 = mysqli_query($db,"update userdata set password='$new' where username='$username' and password='$current'");
header('location:../settings.php?msg=success&username='.$username.'');
}else{
header('location:../settings.php?msg=error&username='.$username.'');
}
}else{
header('location:../settings.php?msg=error&username='.$username.'');
}
}
function addaccount(){
include('../../config.php');
$level = $_GET['level'];
$id = $_GET['id'];
$q = "select * from $level where id=$id";
$r = mysqli_query($db,$q);
$row = mysqli_fetch_array($r);
if($level == 'student'){
$username = $row['studid'];
$fname = $row['fname'];
$lname = $row['lname'];
$password = sha1($username.'-'.$fname);
}else{
$username = $row['teachid'];
$fname = $row['fname'];
$lname = $row['lname'];
$password = sha1($username.'-'.$fname);
}
$verify = $this->verifyusername($username);
if($verify){
$q2 = "insert into userdata values(null,'$username','$password','$fname','$lname','$level')";
mysqli_query($db,$q2);
header('location:../'.$level.'list.php?r=added an account');
}else{
header('location:../'.$level.'list.php?r=updated');
}
}
function verifyusername($user){
$q = "select * from userdata where username='$user'";
$r = mysql_query($q);
if(mysql_num_rows($r) < 1){
return true;
}else{
return false;
}
}
function getuser($search){
include('../config1.php');
$user = $_SESSION['id'];
$q = "select * from userdata where username !='$user' and username like '%$search%' order by lname asc";
$r = mysqli_query($db, $q);
return $r;
}
function addaccounts(){
include('../../config1.php');
extract($_POST);
$q = "select * from $level where id=$id";
$r = mysqli_query($db,$q);
$row = mysqli_fetch_array($r);
if($level == 'student'){
$username = $row['studid'];
$fname = $row['fname'];
$lname = $row['lname'];
$password = sha1($username.'-'.$fname);
}else{
$username = $row['teachid'];
$fname = $row['fname'];
$lname = $row['lname'];
$password = sha1($username.'-'.$fname);
}
$verify = $this->verifyusername($username);
if($verify){
$q2 = "insert into userdata values(null,'$username','$password','$fname','$lname','$level')";
mysqli_query($db,$q2);
header('location:../'.$level.'list.php?r=added an account');
}else{
header('location:../'.$level.'list.php?r=updated');
}
}
}
?>
please help need an answer soon. thanks.
just change this line
$confirm = sha1($_POST['confirm']);
to this
$confirm = $_POST['confirm'];
I'm working on Android apps that showing the output of table in SQL from PHP file, the problem is this PHP file won't show anything in output.
I have tried to find the solution all over Internet but can't find any.
This is the source code:
<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$email = $_POST['user_email'];
require_once 'DB_Connect.php';
$db = new DB_Connect();
$response = array();
$sql = ("SELECT * FROM white_list WHERE user_email = '" . $email . "'");
$result = mysqli_query($db->connect(), $sql) or die(mysqli_error());
$no_of_rows = mysqli_num_rows($result);
if ($no_of_rows > 0) {
$response["white_list"] = array();
while ($row = mysqli_fetch_array($result)) {
$white_list = array();
$white_list["name"] = $row["wl_name"];
$white_list["hp"] = $row["wl_hp"];
$white_list["address"] = $row["wl_address"];
$white_list["link"] = $row["wl_link"];
array_push($response["white_list"], $white_list);
}
$response["success"] = 1;
echo json_encode($response);
} else {
$response["success"] = 0;
$response["message"] = "No Data";
echo json_encode($response);
}
}