Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

What is procedure to update & display login user table when manually add a table to uf_users #120

Closed
johanvena opened this issue Sep 14, 2014 · 30 comments
Labels
use and extension Misc feature request

Comments

@johanvena
Copy link

I have manually add a table to uf_users to hold an url (manually insert a url to see if echo will display using below code).

user_id,'url'); ?>

Receive Fatal error: Using $this when not in object context in ............................

Which files do I need to edit? or can I post directly to login user url table or do I need to use ....... action="update_user.php" method="post">

What is the code to update via a form the url table for login user and
What is code to echo table url for login user

Thanxs in advance

@alexweissman
Copy link
Member

fetchUserField is actually broken right now (I'll remove it in the next push). But, you shouldn't need to use it. Instead, you should update the fetchUser and fetchAllUsers functions to grab the new field along with the other fields. You should also update createUser and updateUser as well to accept the additional field when creating/updating a user.

Once you have that working, you can update the API pages: create_user.php, update_user.php, and get them to accept the extra field from the POST request.

Finally, you'll want to update forms/form_user.php and forms/table_users.php to render the new fields as you like. They use the bootsole templating system, so check out the README over there for more details.

Let me know if you run into a problem at any of these stages, we can try to walk you through it.

@alexweissman alexweissman added the use and extension Misc feature request label Sep 14, 2014
@johanvena
Copy link
Author

Can you please check if following code for extra table url correct. Before I implement. Line No. are estimate as some places I might have added extra line space

======= models/db_functions.php ===========
==========> insert line 117 ==========>

//Check if an url exists in the DB
function urlExists($url) {
return valueExists('url', 'url', $url);
}

==========> edit line 230 ==========>

$query = "select {$db_table_prefix}users.id as user_id, user_name, display_name, email, url, title, sign_up_stamp, last_sign_in_stamp, active, enabled, primary_group_id from {$db_table_prefix}users";

========== api/register.php ==========
==========> insert after line 104 ==========>

      <div class="row form-group">
        <label class="col-sm-4 control-label">Url</label>
        <div class="col-sm-8">
            <div class="input-group">
                <span class='input-group-addon'><i class='fa fa-url'></i></span>
                <input type="url" class="form-control" placeholder="Url" name='url' data-validate='{"url": true, "minLength": 1, "maxLength": 100, "label": "Url" }'>
            </div>
        </div>
      </div>

========== api/register.php ==========
==========> edit line 43 add following code ==========>

// POST: user_name, display_name, email, url, title, password, passwordc, [admin, add_groups, skip_activation, csrf_token]

==========> after line 86 add following code ==========>

$url = str_normalize($validator->requiredPostVar('url'));

==========> edit line 132 add following code ==========>

if ($new_user_id = createUser($user_name, $display_name, $email, $url, $title, $password, $passwordc, $require_activation, $admin)){

======== api/update_user.php =================
==========> after line 47 add following code ==========>

$url = str_normalize($validator->optionalPostVar('url'));

==========> after line 117 add following code ==========>

//Update url if specified and different from current value
if ($url && $userdetails['url'] != $url){
if (!updateUserUrl($user_id, $url)){
$error_count++;
} else {
$success_count++;
}
}

============= forms/form_user.php ==================
==========> after line 145 add following code ==========>

    'url' => [
    'type' => 'text',
    'label' => 'Url',
    'display' => 'disabled',
    'icon' => 'fa fa-phone',
        'validator' => [
        'minLength' => 10,
        'maxLength' => 100,
        'email' => true,
        'label' => 'Url'
    ],
    'placeholder' => 'Url goes here'
],

==========> after line 339 add following code ==========>

{{url}}

@alexweissman
Copy link
Member

Hang on, I'm confused. Is url a new table, a new field in the users table, or both?

@johanvena
Copy link
Author

url is a new field in uf_user table

@alexweissman
Copy link
Member

Ok so if you're trying to check if a url exists, you'd do:

function urlExists($url) {
return valueExists('users', 'url', $url);
}

Everything else looks pretty good, just remember that str_normalize will lowercase your URLs, if that's what you want.

@alexweissman
Copy link
Member

Oh and don't forget to update widget-users.js to pass the new field over from the form.

I'll be updating that soon to use serialize on the form, which will automatically get all the values from the form. But for now, you need to explicitly pass it in.

@johanvena
Copy link
Author

I have created manually a field url in uf_user table. Then via upload.php I want to upload logo.png and write url in field url whichI want to display in sidebar above dashboard link

@johanvena
Copy link
Author

What is the code for post to new url field for logged in user and echo for logged in user

@alexweissman
Copy link
Member

To load a field into the logged-in user, you'll need to modify api/process_login.php. Maybe we can find a way to make this happen automatically in future versions?

@johanvena
Copy link
Author

OK, will play around with code tomorrow writing exams wiil come back with any issues

@alexweissman
Copy link
Member

Cool, good luck on the exams!

@alexweissman
Copy link
Member

Just patched it to use serialize, so you don't need to update the JS anymore.

@johanvena
Copy link
Author

Thanxs, Alex

Got the whole process working, but it works now from the registration page. I don’t want it in the registration page I want the logged in user to upload their logo in their dashboard. I just want to add a form in the dashboard to upload their logo to images directory which I have created within UF and displaying it in dashboard in sidebar

Thanxs for the previous help I have used it to add a cellphone number to registration page and it works 100% within db

From: Alex Weissman [mailto:[email protected]]
Sent: 17 September 2014 19:50
To: alexweissman/UserFrosting
Cc: johanvena
Subject: Re: [UserFrosting] What is procedure to update & display login user table when manually add a table to uf_users (#120)

Just patched it to use serialize, so you don't need to update the JS anymore.


Reply to this email directly or view it on GitHub #120 (comment) . https://github.com/notifications/beacon/8571962__eyJzY29wZSI6Ik5ld3NpZXM6QmVhY29uIiwiZXhwaXJlcyI6MTcyNjU5NTQyMiwiZGF0YSI6eyJpZCI6NDI0MzIxMTh9fQ==--c3f709fc5b5102e9ed1d7d59f046fc804c00f774.gif


This email is free from viruses and malware because avast! Antivirus protection is active.
http://www.avast.com

@alexweissman
Copy link
Member

Nice, glad it's working for you. If you want to create a new form, I would just copy form_users.php and start from there. Unfortunately, bootsole doesn't have a file type field yet; I'll put that on the list of fields we need to support in the future. In the meantime, you can skip the templating and just directly create the field in your new form.

@johanvena
Copy link
Author

I'm running in circles, and maybe it is just something simple to do with session & variables.
This is my form I use in account/dashboard.php. Everything is working ( file get uploaded and display except the upload file url is not written in current login user url field. I have created 2 fields url and date in uf_users

This is my upload.php file which

connect_errno){ echo "Error
".$sp->error; } $path="images/"; if(isset($_POST['upload'])) { $path=$path. $_SESSION['user_id'].$_FILES['file_upload']['name']; if(move_uploaded_file($_FILES['file_upload']['tmp_name'],$path)) { echo " ".basename($_FILES['file_upload']['name'])." has been uploaded
"; echo '

'; $img=$_FILES['file_upload']['name']; ``` $query="insert into uf_users (url, date) values('$img',now())"; if($sp->query($query)){ echo "
Inserted to DB also"; }else{ echo "Error
".$sp->error; } ``` } else { echo "There is an error,please retry or ckeck path"; } } ?>

@alexweissman
Copy link
Member

First of all, don't use mysqli_connect. Use the connection pattern found in models/db_functions.php. You should also try to use the same error-handling procedure as used in the api directory.

@johanvena
Copy link
Author

OK, done updated db_functions.php and api/update_use and remove mysqli_connect in my update.php file

Still receive following error

Call to a member function query() on a non-object in /home/realesta/public_html/witbank/admin/account/uploadnew.php on line 18

How do I call a query to add the url in my database in my update.php

I see you use

I use

Due to image upload and just wan’t to know how to adjust my code

$query="insert into uf_users (avatar, date) values('$img',now())";

if($sp->query($query)){

 echo "<br/>Inserted to DB also";   

}else{

    echo "Error <br/>".$sp->error;       

}

}

else

{

echo "There is an error,please retry or ckeck path";

}

}


This email is free from viruses and malware because avast! Antivirus protection is active.
http://www.avast.com

@alexweissman
Copy link
Member

The problem is that you're trying to use insert, when you should be using update. You need something like:

$db = pdoConnect();
$query = "UPDATE uf_users SET avatar = :img, date = NOW() WHERE id = :user_id";
$stmt = $db->prepare($query);
$sqlVars = array(
   ":img" => $img,
   ":user_id" => $loggedInUser->user_id
);
$stmt = execute($sqlVars);

@johanvena
Copy link
Author

Thanxs Alex

Do I need to add this to my file as per all your files or not:

Ok I have tried it with and without and receive following error:-

Fatal error: Call to undefined function pdoConnect() in /home/realesta/public_html/witbank/admin/account/uploadnew.php on line 16

Here is my complete uploadnew.php file with your new code

"; echo '

'; $img=$_FILES['file_upload']['name']; $db = pdoConnect(); $query = "UPDATE uf_users SET avatar = :img, date = NOW() WHERE id = :user_id"; $stmt = $db->prepare($query); $sqlVars = array( ":img" => $img, ":user_id" => $loggedInUser->user_id ); $stmt = execute($sqlVars); ``` if($sp->query($query)){ echo "
Inserted to DB also"; }else{ echo "Error
".$sp->error; } ``` } else { echo "There is an error,please retry or ckeck path"; } } ?>

From: Alex Weissman [mailto:[email protected]]
Sent: 19 September 2014 16:36
To: alexweissman/UserFrosting
Cc: johanvena
Subject: Re: [UserFrosting] What is procedure to update & display login user table when manually add a table to uf_users (#120)

The problem is that you're trying to use insert, when you should be using update. You need something like:

$db = pdoConnect();
$query = "UPDATE uf_users SET avatar = :img, date = NOW() WHERE id = :user_id";
$stmt = $db->prepare($query);
$sqlVars = array(
":img" => $img,
":user_id" => $loggedInUser->user_id
);
$stmt = execute($sqlVars);


Reply to this email directly or view it on GitHub #120 (comment) . https://github.com/notifications/beacon/8571962__eyJzY29wZSI6Ik5ld3NpZXM6QmVhY29uIiwiZXhwaXJlcyI6MTcyNjc1NjU4NiwiZGF0YSI6eyJpZCI6NDI0MzIxMTh9fQ==--af9718c3b3b541d37152b859032b2281dbb69c50.gif


This email is free from viruses and malware because avast! Antivirus protection is active.
http://www.avast.com

@lilfade
Copy link
Contributor

lilfade commented Sep 20, 2014

Add global $pdoConnect(); after setrefferalpage.
On Sep 19, 2014 4:03 PM, "johanvena" [email protected] wrote:

Thanxs Alex

Do I need to add this to my file as per all your files or not:

Ok I have tried it with and without and receive following error:-

Fatal error: Call to undefined function pdoConnect() in
/home/realesta/public_html/witbank/admin/account/uploadnew.php on line 16

Here is my complete uploadnew.php file with your new code

"; echo ''; $img=$_FILES['file_upload']['name']; $db = pdoConnect(); $query = "UPDATE uf_users SET avatar = :img, date = NOW() WHERE id = :user_id"; $stmt = $db->prepare($query); $sqlVars = array( ":img" => $img, ":user_id" => $loggedInUser->user_id ); $stmt = execute($sqlVars); if($sp->query($query)){ echo "
Inserted to DB also"; }else{ echo "Error
".$sp->error; } } else { echo "There is an error,please retry or ckeck path"; } } ?>

From: Alex Weissman [mailto:[email protected]]
Sent: 19 September 2014 16:36
To: alexweissman/UserFrosting
Cc: johanvena
Subject: Re: [UserFrosting] What is procedure to update & display login
user table when manually add a table to uf_users (#120)

The problem is that you're trying to use insert, when you should be using
update. You need something like:

$db = pdoConnect();
$query = "UPDATE uf_users SET avatar = :img, date = NOW() WHERE id =
:user_id";
$stmt = $db->prepare($query);
$sqlVars = array(
":img" => $img,
":user_id" => $loggedInUser->user_id
);
$stmt = execute($sqlVars);

Reply to this email directly or view it on GitHub <
https://github.com/alexweissman/UserFrosting/issues/120#issuecomment-56185420>
. <
https://github.com/notifications/beacon/8571962__eyJzY29wZSI6Ik5ld3NpZXM6QmVhY29uIiwiZXhwaXJlcyI6MTcyNjc1NjU4NiwiZGF0YSI6eyJpZCI6NDI0MzIxMTh9fQ==--af9718c3b3b541d37152b859032b2281dbb69c50.gif>


This email is free from viruses and malware because avast! Antivirus
protection is active.
http://www.avast.com

Reply to this email directly or view it on GitHub
#120 (comment)
.

@johanvena
Copy link
Author

I am not sure if I had to delete rest of line or kept it after adding-: global $pdoConnect(); but still error even If I delete:- (getAbsoluteDocumentPath(FILE));

Parse error: syntax error, unexpected 'global' (T_GLOBAL) in /home/realesta/public_html/witbank/admin/account/uploadtest.php on line 13

New Code

"; echo '

'; $img=$_FILES['file_upload']['name']; $db = pdoConnect(); $query = "UPDATE uf_users SET avatar = :img, date = NOW() WHERE id = :user_id"; $stmt = $db->prepare($query); $sqlVars = array( ":img" => $img, ":user_id" => $loggedInUser->user_id ); $stmt = execute($sqlVars); ``` if($sp->query($query)){ echo "
Inserted to DB also"; }else{ echo "Error
".$sp->error; } ``` } else { echo "There is an error,please retry or ckeck path"; } } ?>

From: Bryson [mailto:[email protected]]
Sent: 20 September 2014 03:08
To: alexweissman/UserFrosting
Cc: johanvena
Subject: Re: [UserFrosting] What is procedure to update & display login user table when manually add a table to uf_users (#120)

Add global $pdoConnect(); after setrefferalpage.
On Sep 19, 2014 4:03 PM, "johanvena" <[email protected] mailto:[email protected] > wrote:

Thanxs Alex

Do I need to add this to my file as per all your files or not:

Ok I have tried it with and without and receive following error:-

Fatal error: Call to undefined function pdoConnect() in
/home/realesta/public_html/witbank/admin/account/uploadnew.php on line 16

Here is my complete uploadnew.php file with your new code

"; echo ''; $img=$_FILES['file_upload']['name']; $db = pdoConnect(); $query = "UPDATE uf_users SET avatar = :img, date = NOW() WHERE id = :user_id"; $stmt = $db->prepare($query); $sqlVars = array( ":img" => $img, ":user_id" => $loggedInUser->user_id ); $stmt = execute($sqlVars); if($sp->query($query)){ echo "
Inserted to DB also"; }else{ echo "Error
".$sp->error; } } else { echo "There is an error,please retry or ckeck path"; } } ?>

From: Alex Weissman [mailto:[email protected]]
Sent: 19 September 2014 16:36
To: alexweissman/UserFrosting
Cc: johanvena
Subject: Re: [UserFrosting] What is procedure to update & display login
user table when manually add a table to uf_users (#120)

The problem is that you're trying to use insert, when you should be using
update. You need something like:

$db = pdoConnect();
$query = "UPDATE uf_users SET avatar = :img, date = NOW() WHERE id =
:user_id";
$stmt = $db->prepare($query);
$sqlVars = array(
":img" => $img,
":user_id" => $loggedInUser->user_id
);
$stmt = execute($sqlVars);

Reply to this email directly or view it on GitHub <
https://github.com/alexweissman/UserFrosting/issues/120#issuecomment-56185420>
. <
https://github.com/notifications/beacon/8571962__eyJzY29wZSI6Ik5ld3NpZXM6QmVhY29uIiwiZXhwaXJlcyI6MTcyNjc1NjU4NiwiZGF0YSI6eyJpZCI6NDI0MzIxMTh9fQ==--af9718c3b3b541d37152b859032b2281dbb69c50.gif>


This email is free from viruses and malware because avast! Antivirus
protection is active.
http://www.avast.com

Reply to this email directly or view it on GitHub
#120 (comment)
.


Reply to this email directly or view it on GitHub #120 (comment) . https://github.com/notifications/beacon/8571962__eyJzY29wZSI6Ik5ld3NpZXM6QmVhY29uIiwiZXhwaXJlcyI6MTcyNjc5NDQ4NiwiZGF0YSI6eyJpZCI6NDI0MzIxMTh9fQ==--d3db87ba9933657207f68e92e86a7237a044eb9b.gif


This email is free from viruses and malware because avast! Antivirus protection is active.
http://www.avast.com

@lilfade
Copy link
Contributor

lilfade commented Sep 20, 2014

setReferralPage(getAbsoluteDocumentPath(FILE));

global $pdoConnect();

Sorry about that haha I ment like so.
On Sep 20, 2014 1:38 AM, "johanvena" [email protected] wrote:

I am not sure if I had to delete rest of line or kept it after adding-:
global $pdoConnect(); but still error even If I delete:-
(getAbsoluteDocumentPath(FILE));

Parse error: syntax error, unexpected 'global' (T_GLOBAL) in
/home/realesta/public_html/witbank/admin/account/uploadtest.php on line 13

New Code

"; echo ''; $img=$_FILES['file_upload']['name']; $db = pdoConnect(); $query = "UPDATE uf_users SET avatar = :img, date = NOW() WHERE id = :user_id"; $stmt = $db->prepare($query); $sqlVars = array( ":img" => $img, ":user_id" => $loggedInUser->user_id ); $stmt = execute($sqlVars); if($sp->query($query)){ echo "
Inserted to DB also"; }else{ echo "Error
".$sp->error; } } else { echo "There is an error,please retry or ckeck path"; } } ?>

From: Bryson [mailto:[email protected]]
Sent: 20 September 2014 03:08
To: alexweissman/UserFrosting
Cc: johanvena
Subject: Re: [UserFrosting] What is procedure to update & display login
user table when manually add a table to uf_users (#120)

Add global $pdoConnect(); after setrefferalpage.
On Sep 19, 2014 4:03 PM, "johanvena" <[email protected] <mailto:
[email protected]> > wrote:

Thanxs Alex

Do I need to add this to my file as per all your files or not:

Ok I have tried it with and without and receive following error:-

Fatal error: Call to undefined function pdoConnect() in
/home/realesta/public_html/witbank/admin/account/uploadnew.php on line
16

Here is my complete uploadnew.php file with your new code

"; echo ''; $img=$_FILES['file_upload']['name']; $db = pdoConnect(); $query = "UPDATE uf_users SET avatar = :img, date = NOW() WHERE id = :user_id"; $stmt = $db->prepare($query); $sqlVars = array( ":img" => $img, ":user_id" => $loggedInUser->user_id ); $stmt = execute($sqlVars); if($sp->query($query)){ echo "
Inserted to DB also"; }else{ echo "Error
".$sp->error; } } else { echo "There is an error,please retry or ckeck path"; } } ?>

From: Alex Weissman [mailto:[email protected]]
Sent: 19 September 2014 16:36
To: alexweissman/UserFrosting
Cc: johanvena
Subject: Re: [UserFrosting] What is procedure to update & display login
user table when manually add a table to uf_users (#120)

The problem is that you're trying to use insert, when you should be
using
update. You need something like:

$db = pdoConnect();
$query = "UPDATE uf_users SET avatar = :img, date = NOW() WHERE id =
:user_id";
$stmt = $db->prepare($query);
$sqlVars = array(
":img" => $img,
":user_id" => $loggedInUser->user_id
);
$stmt = execute($sqlVars);

Reply to this email directly or view it on GitHub <

https://github.com/alexweissman/UserFrosting/issues/120#issuecomment-56185420>

. <

https://github.com/notifications/beacon/8571962__eyJzY29wZSI6Ik5ld3NpZXM6QmVhY29uIiwiZXhwaXJlcyI6MTcyNjc1NjU4NiwiZGF0YSI6eyJpZCI6NDI0MzIxMTh9fQ==--af9718c3b3b541d37152b859032b2281dbb69c50.gif>


This email is free from viruses and malware because avast! Antivirus
protection is active.
http://www.avast.com

Reply to this email directly or view it on GitHub
<
https://github.com/alexweissman/UserFrosting/issues/120#issuecomment-56235100>

.

Reply to this email directly or view it on GitHub <
https://github.com/alexweissman/UserFrosting/issues/120#issuecomment-56252521>
. <
https://github.com/notifications/beacon/8571962__eyJzY29wZSI6Ik5ld3NpZXM6QmVhY29uIiwiZXhwaXJlcyI6MTcyNjc5NDQ4NiwiZGF0YSI6eyJpZCI6NDI0MzIxMTh9fQ==--d3db87ba9933657207f68e92e86a7237a044eb9b.gif>


This email is free from viruses and malware because avast! Antivirus
protection is active.
http://www.avast.com

Reply to this email directly or view it on GitHub
#120 (comment)
.

@alexweissman
Copy link
Member

@johanvena yes, you always need to include the config.php file.

@lilfade
Copy link
Contributor

lilfade commented Sep 20, 2014

Well I don't think I'll be replying via email anymore gets confusing fast lol.

@johanvena
Copy link
Author

Ok, just added but receive following error and image does not upload

Parse error: syntax error, unexpected '(', expecting ',' or ';' in /home/realesta/public_html/witbank/admin/account/uploadnew.php on line 35

Line 35 = global $pdoConnect();

If I remove 2 added lines it upload images but gives following error

Fatal error: Call to undefined function execute() in /home/realesta/public_html/witbank/admin/account/uploadnew.php on line 56

Line 56 = $stmt = execute($sqlVars);

@joshblevins
Copy link

I was wondering if you could point me in the right direction to learn user
frosting. I am building a site with lots of forms a db usage
On Sep 22, 2014 12:13 AM, "johanvena" [email protected] wrote:

Ok, just added but receive following error and image does not upload

Parse error: syntax error, unexpected '(', expecting ',' or ';' in
/home/realesta/public_html/witbank/admin/account/uploadnew.php on line 35

Line 35 = global $pdoConnect();

If I remove 2 added lines it upload images but gives following error

Fatal error: Call to undefined function execute() in
/home/realesta/public_html/witbank/admin/account/uploadnew.php on line 56

Line 56 = $stmt = execute($sqlVars);


Reply to this email directly or view it on GitHub
#120 (comment)
.

@alexweissman
Copy link
Member

Guys, I've made a flowchart that explains the overall data flow paradigm for UserFrosting:
userfrosting data flow overview

I'll try to put it up on the website soon, with a more detailed explanation of how it works. My advice would be to start with something like account/user_details.php and see how it loads the user form via the forms API.

I know we need to update the website, as a number of things have changed in version 0.2.1. Hopefully I'll have some time in a few weeks.

@johanvena
Copy link
Author

Thanxs, I have missed some steps will go through my code and see which step I have missed

@johanvena
Copy link
Author

Ok, the only place I didn't update my code for avatar and date was in models/secure_functions.php
but still get above mentioned error if you can help I will highly appreciate or I will wait for more detailed explanation if you haven't got time now

@alexweissman
Copy link
Member

Well its hard to say without seeing the code, but I noticed you did:

$stmt = execute($sqlVars); 

execute is not a standalone function. It is a member of the PDO::PDOStatement class. You need to be doing something like:

$stmt = $db->prepare(...);
$stmt->$execute($params);

I'd recommend carefully looking through the documentation for PDO: http://php.net/manual/en/book.pdo.php and also following the pattern we use in models/db_functions.php.

You can also post your code in a private gist and email me a link, and I can try to take a look. But, please make sure you are understanding the basics of PDO first.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
use and extension Misc feature request
Projects
None yet
Development

No branches or pull requests

4 participants