Jump to content

Recommended Posts

I am trying to update the info now and when I click update on the form, it is not updating still and redirects to profile.php instead of profile.php?id={$_SESSION['user_id']}

 



<?php
ini_set('display_startup_errors',1);
ini_set('display_errors',1);
error_reporting(-1);

require_once("functions.php");
require_once("db-const.php");

if (logged_in() == false) {
redirect_to("login.php");
exit;
} else {
if (isset($_GET['id']) && $_GET['id'] != "") {
$id = $_GET['id'];
} else {
$id = $_SESSION['user_id'];
}

$db = mysqli_connect("" , "", "") or die("Check connection parameters!");
// Optionally skip select_db and use: mysqli_connect(host,user,pass,dbname)
mysqli_select_db($db,"") or die(mysqli_error($db));

if (mysqli_connect_error()) {
die ('Failed to connect to MySQL');
}
}

// Prepared statements are better, but at least escape things before tossing them into a query
$id = mysqli_real_escape_string($db, $id);

$sql = "UPDATE u.id, u.name, u.email, u.address1, u.address2, u.town, u.county, u.postcode,
u.telnumber, u.mobnumber, u.model, u.numplate, DATE_FORMAT(r.renewal_date, '%e %M %Y') AS renewal,
i.description
users AS u
INNER JOIN renewal AS r ON u.id = r.id
INNER JOIN item AS i on r.item_id = i.item_id
WHERE u.id= {$id}";

$query = mysqli_query($db, $sql) or die (mysqli_error($db));

header("location:profile.php?id={$_SESSION['user_id']}");
?>

Edited by ianhaney50
Link to comment
https://forums.phpfreaks.com/topic/297140-update-php-issue/
Share on other sites

I would guess that the script is never reaching the bottom part, where you perform the query and redirect.

 

Unrelated but this caught my eye:

// Prepared statements are better, but at least escape things before tossing them into a query
$id = mysqli_real_escape_string($db, $id);
If you know you have an integer ID, you can just typecast it instead of escaping it. 

$id = (int) $id;
Edited by scootstah
Link to comment
https://forums.phpfreaks.com/topic/297140-update-php-issue/#findComment-1515366
Share on other sites

sorry got a update now I added session_start() in as I forgot to include it

 
the edit-page.php now outputs the error
 
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(r.renewal_date, '%e %M %Y') AS renewal, i.description users AS u ' at line 2
 
below is the whole code
 
<?php
ini_set('display_startup_errors',1);
ini_set('display_errors',1);
error_reporting(-1);

require_once("functions.php");
require_once("db-const.php");

include 'includes/header.php';

if (logged_in() == false) {
    redirect_to("login.php");
    exit;
} else {
    if (isset($_GET['id']) && $_GET['id'] != "") {
        $id = $_GET['id'];
    } else {
        $id = $_SESSION['user_id'];
    }

$db = mysqli_connect("176.32.230.22" , "", "") or die("Check connection parameters!");
    // Optionally skip select_db and use: mysqli_connect(host,user,pass,dbname)  
    mysqli_select_db($db,"") or die(mysqli_error($db));

    if (mysqli_connect_error()) {
        die ('Failed to connect to MySQL');
    }
}

// Prepared statements are better, but at least escape things before tossing them into a query
$id = mysqli_real_escape_string($db, $id);

$sql = "UPDATE u.id, u.name, u.email, u.address1, u.address2, u.town, u.county, u.postcode, 
        u.telnumber, u.mobnumber, u.model, u.numplate, DATE_FORMAT(r.renewal_date, '%e %M %Y') AS renewal,
        i.description
    users AS u
    INNER JOIN renewal AS r ON u.id = r.id
    INNER JOIN item AS i on r.item_id = i.item_id
    WHERE u.id= {$id}";

$query = mysqli_query($db, $sql) or die (mysqli_error($db));

header("location:profile.php?id={$_SESSION['user_id']}");
?>
Link to comment
https://forums.phpfreaks.com/topic/297140-update-php-issue/#findComment-1515367
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.