I apologise if this question has been asked, I have looked and can't find an answer that fits but if I'm wrong please tell me!
I've created a login form and when the user logs in they can see their Name, E-mail, Phone and Availability. At the moment this is just echoing / printing the information from the MySQL database. What I was wondering is how I make this editable so that the logged in user can update their own information?
Thanks an absolute bunch to everyone by the way, I'm new to this site and everyone has been extremely helpful. I'm not a developer by trade and very much learning as I go on this project so it is appreciated! :)
<?php
session_start();
$sessData = !empty($_SESSION['sessData'])?$_SESSION['sessData']:'';
if(!empty($sessData['status']['msg'])){
$statusMsg = $sessData['status']['msg'];
$statusMsgType = $sessData['status']['type'];
unset($_SESSION['sessData']['status']);
}
?>
<div class="container">
<?php
if(!empty($sessData['userLoggedIn']) && !empty($sessData['userID'])){
include 'user.php';
$user = new User();
$conditions['where'] = array(
'id' => $sessData['userID'],
);
$conditions['return_type'] = 'single';
$userData = $user->getRows($conditions);
?>
<h2>Welcome <?php echo $userData['first_name']; ?>!</h2>
Logout
<div class="regisFrm">
<p><b>Name: </b><?php echo $userData['first_name'].' '.$userData['last_name']; ?></p>
<p><b>Email: </b><?php echo $userData['email']; ?></p>
<p><b>Phone: </b><?php echo $userData['phone']; ?></p>
<p><b>Available: </b><?php echo $userData['available']; ?></p>
<li><a href=profile.php>Update Profile<a></li><br>
<form action="change.php" method="post">
Are you available this weekend?<br>
<input type="radio" name="available" value="yes"> Yes<br>
<input type="radio" name="available" value="no"> No<br>
<input type="submit" value="Submit">
</form>
</div>
<?php }else{ ?>
<h2>Login to Your Account</h2>
<?php echo !empty($statusMsg)?'<p class="'.$statusMsgType.'">'.$statusMsg.'</p>':''; ?>
<div class="regisFrm">
<form action="userAccount.php" method="post">
<input type="email" name="email" placeholder="EMAIL" required="">
<input type="password" name="password" placeholder="PASSWORD" required="">
<div class="send-button">
<input type="submit" name="loginSubmit" value="LOGIN">
</div>
</form>
<p>Don't have an account? Register</p>
</div>
<?php } ?>
</div>
I am a newbie to php programming as well, so I very well could be wrong. I apologize in advance if this doesn't work.
From what I understand of your question, why can't you make a form?
I was in a similar situation before, and I just made a form asking for their details they wish to change and a password field.
Transfer the data from the form to a .php file (using action='filename.php'), where you can make queries to update your mysql database.
Hope it helps.
Related
This is a hopeful question. I am really, really PHP inexperienced. But I am trying to teach myself a thing or two. The organization I work for uses a WP site. I regularly work on it. I mostly do HTML and CSS (stuff I know about) but I was just digging around in the background and came across something I don't understand at all.
I made a test page here: http://all4ed.org/webinar-event/test-2/
There are two forms on the page. The first ends in a "submit button," the second ends in a "Register Button."
So far so good. I dug around the backend of the WP files, and found the content-webinar.php file and saw that it pulled the form in as an include with:
// The registration form. ?>
<?php if ($registration_required == 'yes'): ?>
<?php include ('assets/includes/webinar/inc-block-registration-form.php'); ?>
<?php endif;
Good, so far.
I went to the "inc-block-registration-form.php" file and here's where it gets weird:
The first form is done with this code:
<form class="webinar-registration" action="<?= $_SERVER["REQUEST_URI"] ?>" method="get">
<div>
<p>
<label for="token">Token</label>
<input type="text" name="token" />
</p>
<p>
<button>Submit</button>
</p>
</div>
</form>
This looks exactly like I thought it would. The second form is written like this:
<form class="webinar-registration" action="<?= $_SERVER["REQUEST_URI"] ?>" method="post">
<div>
<?php if ($webinars->error) : ?>
<p class="error"><?= $webinars->error ?></p>
<?php endif; ?>
<?php foreach ($webinars->form_data as $data) : ?>
<p><?= $webinars->build($data) ?></p>
<?php endforeach; ?>
<p>
<button>Register</button>
<input type="hidden" name="webinars_registration_submitted" value="<?= $post->ID ?>" />
<input type="hidden" name="webinars_registration_title" value="<?= get_the_title() ?>" />
<input type="hidden" name="webinars_registration_url" value="<?= get_permalink() ?>" />
<!-- fields necessary for AA -->
<input type="hidden" name="webinars_user_id" value="<?= get_current_user_id() ?>" />
<input type="hidden" name="webinars_type" value="<?= get_field('webinar_type') ?>" />
<input type="hidden" name="webinars_post_id" value="<?= get_the_ID () ?>" />
</p>
</div>
</form>
Huh???? Where is the "Your Name", "Your E-mmail Address," "Organization," "City, State," or "Question (This is optional)"
How does this work? Where is it pulling those fields from. Any insight would be appreciated. Thanks.
Seems, that I can't add password protection to the script: it should allow to login with the pass and to submit data from the form to mysql. Login looks fine, but if I try to press submit, it returns me to login page. Seems, that session is dropped or overwritten, but is not clear, how:
//login area
<?php
$password = "test";
session_start();
$_SESSION['txtPassword']= $_POST['txtPassword'] ;
if ( $_SESSION['txtPassword']!=$password ) {
?>
<form name="form" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<p><label for="txtPassword">Password:</label>
<br /><input type="text" title="Enter your password" name="txtPassword" /></p>
<p><input type="submit" name="Submit" value="Login" /></p>
</form>
<?
}
elseif ( $_SESSION['txtPassword']=$password ) {
echo $_SESSION['txtPassword'] ; // tried to print password, result is correct: test
//my db connection, just in case:
include "config.php";
$connect = mysqli_connect(HOST, USER, PASSWORD, NAME);
// data which should be inserted to db
if
(#$_POST['posted']=='1' $_POST['posted'])) {
$sSQL = "UPDATE users SET user_login='".mysqli_real_escape_string($connect, $_POST['usern'])."',user_pass='".mysqli_real_escape_string($connect, dohashpw($_POST['passw']))."' WHERE ID=1";
mysqli_query($connect, $sSQL) or print(mysql_error());
print ' <div class="container"> <p class="pstype">Password updated! </p>';
...
//input form
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"><input type="hidden" name="posted" value="1" />
<div class="col-xs-3">
<label for="ex2">New Username: </label>
<input type="text" class="form-control input-lg" name="usern" >
</div>
<div class="col-xs-3">
<label for="ex2">New Password: </label>
<input type="password" class="form-control input-lg" name="passw" >
</div>
<div class="col-xs-3">
<input type="submit" value="Submit" onclick="<? mysqli_query ($connect, $sSQL);?>; ">
</div>
</form>
I am able to login this page, but when I fill the form and click Submit, I get login area again. If echo $_SESSION show a correct result, I think that it was established, but data are lost after for submit. Could you please help to find my error?
You are assigning and not comparing here :
elseif ( $_SESSION['txtPassword']=$password ) {
this is better
elseif ( $_SESSION['txtPassword']==$password ) {
but thats a bad idea anyway, passwords should not be stored in session variables like this, and you have to hash them once the user submit them and only manipulate and store the hashed passwords in your code and database
<?php
$password = "test";
session_start();
$_SESSION['txtPassword']= $_POST['txtPassword'] ;
if($_SESSION['txtPassword']!=$password ){
?>
<form name="form" method="post" action="<?php echo $_SERVER['PHP_SELF']; ? >">
<p><label for="txtPassword">Password:</label></p>
</br>
<p><input type="text" title="Enter your password" name="txtPassword"/> </p>
<p><input type="submit" name="Submit" value="Login"/></p>
</form>
<?php
}
else{
echo $_SESSION['txtPassword'];
}
?>
i am not understanding why the elseif stands for? you are already checking inside the if condition which both are not equal?.
I have been banging my head against the wall on this for about 2 hours now and I cannot figure out what im doing wrong. I am simply trying to update a MySQL database with new information. but when I click "Update Information" nothing is happening.
<div id="tabs-1">
<?php
//update main informaion
if(isset($_POST["toolnameupdate"])){
$companyname1 = "";
$toolname1 = "";
include_once("../php_includes/db_connect.php");
$companyname1 = $_POST['clientname'];
$toolname1 = $_POST['webtoolname'];
$sql = "UPDATE siteinformation SET clientname = $companyname1, srcname = $toolname1";
$query = mysqli_query($db_connect, $sql);
error_reporting(E_ALL);
header('Location: user.php');
}
?>
<form method="post" action="">
<fieldset>
<legend><strong>Main Title Information</strong></legend>
<div id="prompt">Client Company Name:</div><div id="answer"><input type="text" name="clientname" id="clientname" value="<? echo $companyname; ?>"/></div>
<div id="prompt">Web Tool Name:</div><div id="answer"><input type="text" name="webtoolname" id="webtoolname" value="<? echo $toolname; ?>"/></div>
<div id="prompt"><input type="submit" id="toolnameupdate" name="toolnameupdate" value="Update Information" /></div><div id="answer"> </div>
<div id="prompt"> </div><div id="answer"> </div>
</fieldset>
</form>
</div>
Can anyone see where it is missing information?
Thanks
I am not sure if this is the complete code. But form fields should be included in <form> tags.
<form method="post" action="">
<fieldset>
<legend><strong>Main Title Information</strong></legend>
<div id="prompt">Client Company Name:</div><div id="answer"><input type="text" name="clientname" id="clientname" value="<? echo $companyname; ?>"/></div>
<div id="prompt">Web Tool Name:</div><div id="answer"><input type="text" name="webtoolname" id="webtoolname" value="<? echo $toolname; ?>"/></div>
<div id="prompt"><input type="submit" id="toolnameupdate" name="toolnameupdate" value="Update Information" /></div><div id="answer"> </div>
<div id="prompt"> </div><div id="answer"> </div>
</fieldset>
</form>
also the correct syntax is $_POST['..'], and not with parenthesis.
and also move error_reporting(E_ALL); to the top of the file, otherwise it won't be too useful.
$_POST('clientname') should be $_POST['clientname']. And the same with the rest of the posts. Also read Aris's answer about the form tags.
After you revised your code you removed the quotes around the variables, they need to stay.
$sql = "UPDATE siteinformation SET clientname = '$companyname1', srcname = '$toolname1'";
I'm no too used to or familiar with the Joomla system. SO I kind of need your help here. Here's my problem.
I'm building a site, but the template came with problems and the template makers refuse to accept they made a mistake. AS Templates Don't buy from these guys unless you don't care about being on your own if something happens.
Anyway, basically, the site's buttons are all out of alignment. I tried fixing them through CSS but no luck. Some things can't be fixed in the CSS files because they belong to the HTML part of it. But as some of you may know, Joomla is PHP not HTML. So my question is how do I fix an HTML line of code in Joomla?
To be specific:
I have this code in my site
<form name="logoutForm" method="post" action="/">
<button class="btl-buttonsubmit"onclick="document.logoutForm.submit();" name="Submit" style="">Log out</button>
<input type="hidden" value="com_users" name="option">
<input type="hidden" value="user.logout" name="task">
<input type="hidden" value="aW5kZXgucGhwP0l0ZW1pZD0xMDE=" name="return">
<input type="hidden" value="1" name="7b6cc3e246acff3e3943410a6f4919cf">
</form>
Since this is not PHP code or CSS I cant find it anywhere
Here are the screenshots of my two trouble areas
and
Thanks again
I'm re-editing this to add the code for the search results. Please review for me, refer to the screenshot as well to see what I see or go to my site and search for anything
<?php
defined('_JEXEC') or die;
$lang = JFactory::getLanguage();
$upper_limit = $lang->getUpperLimitSearchWord();
JHtml::_('bootstrap.tooltip');
?>
<form id="searchForm" action="<?php echo JRoute::_('index.php?option=com_search');?>" method="post">
<div class="btn-toolbar">
<div class="btn-group pull-left">
<input type="text" name="searchword" placeholder="<?php echo JText::_('COM_SEARCH_SEARCH_KEYWORD'); ?>" id="search-searchword" size="30" maxlength="<?php echo $upper_limit; ?>" value="<?php echo $this->escape($this->origkeyword); ?>" class="inputbox" />
</div>
<div class="btn group pull-left">
<button name="Search" onclick="this.form.submit()" class="button btn btn hasTooltip" title="<?php echo JText::_('COM_SEARCH_SEARCH');?>"><span class="icon-search"></span></button>
</div>
<input type="hidden" name="task" value="search" />
<div class="clearfix"></div>
</div>
<div class="searchintro<?php echo $this->params->get('pageclass_sfx'); ?>">
<?php if (!empty($this->searchword)):?>
<p><?php echo JText::plural('COM_SEARCH_SEARCH_KEYWORD_N_RESULTS', '<span class="badge badge-info">'. $this->total. '</span>');?></p>
<?php endif;?>
</div>
<fieldset class="phrases">
<legend><?php echo JText::_('COM_SEARCH_FOR');?>
</legend>
<div class="phrases-box">
<?php echo $this->lists['searchphrase']; ?>
</div>
<div class="ordering-box">
<label for="ordering" class="ordering">
<?php echo JText::_('COM_SEARCH_ORDERING');?>
</label>
<?php echo $this->lists['ordering'];?>
</div>
</fieldset>
<?php if ($this->params->get('search_areas', 1)) : ?>
<fieldset class="only">
<legend><?php echo JText::_('COM_SEARCH_SEARCH_ONLY');?></legend>
<?php foreach ($this->searchareas['search'] as $val => $txt) :
$checked = is_array($this->searchareas['active']) && in_array($val, $this->searchareas['active']) ? 'checked="checked"' : '';
?>
<label for="area-<?php echo $val;?>" class="checkbox">
<input type="checkbox" name="areas[]" value="<?php echo $val;?>" id="area-<?php echo $val;?>" <?php echo $checked;?> >
<?php echo JText::_($txt); ?>
</label>
<?php endforeach; ?>
</fieldset>
<?php endif; ?>
<?php if ($this->total > 0) : ?>
<div class="form-limit">
<label for="limit">
<?php echo JText::_('JGLOBAL_DISPLAY_NUM'); ?>
</label>
<?php echo $this->pagination->getLimitBox(); ?>
</div>
<p class="counter">
<?php echo $this->pagination->getPagesCounter(); ?>
</p>
<?php endif; ?>
</form>
mmm yea I can see what you mean. The template does have some issues. And that is not only your problem there are many places were you need to edit your stylesheet. But it's very hard to eyeball all of them and wrap all the solutions in one answer.
But as an advice you can use firebug if you are using firefox or google developer tools by pressing ctrl shift j to open them. You can edit some of your content live and see the changes that are needed to be done in specific places and then you just do them.
For example I found at the section CONTACT the upper right banner has it title popping out of the template. The fix is located in /templates/as002035/css/tmpl.custom.css line 11 by setting the padding to 0 0 20px.
When Creating an account a modal box splashes into my face. You need to fix that by editing the width and the height of that window again by using those tools.
Finally i cant see the logout button " form " since I can't register to your website due to the mail that was not sent in my e-mails. So probably you need a developer to fix all of these things.
I hope I helped a bit.
Besides the (good) advice already provided, there is a missing answer to your question: where does the HTML markup come from?
You will find it in one of two places: first check your template overrides (which I think is the case looking at your question), which would be located in
/templates/as002035/html/com_users/login/default_logout.php (logout component)
/templates/as002035/html/mod_login/ (login|logout module)
if they are not present, then the default Joomla layouts are in
/components/com_users/views/...
/modules/mod_login/tmpl
Added after clarification below, this is the answer the the comments.
you're missing a class "button" so the line of the module should be:
<input type="submit" value="Log out" class="button btn btn-primary" name="Submit">
instead of
<input type="submit" value="Log out" class="btn btn-primary" name="Submit">
(see the added "button"?). Did you find the template ? is it in the overrides? if you can just make that change you'll get the module fixed. As for the component logout form, http://www.guhlmotors.com/index.php?option=com_users
<button class="button btn" type="submit">Log out</button>
instead of
<button class="button" type="submit">Log out</button>
<div class="content clearfix">
<div class="left">
<!--info-->
</div>
<?php
if(!$_SESSION['id']):
?>
<div class="left">
<!-- Login Form -->
<form class="clearfix" action="" method="post">
<h2>Login</h2>
<?php
if($_SESSION['msg']['login-err'])
{
echo '<div class="err">'.$_SESSION['msg']['login-err'].'</div>';
unset($_SESSION['msg']['login-err']);
}
?>
<input class="field" type="text" name="username" id="username" value="User" size="23" onFocus="clearText(this)" />
<input class="field" type="password" name="password" id="password" value="Pass" size="23" onFocus="clearText(this)" />
<label><input name="rememberMe" id="rememberMe" type="checkbox" checked="checked" value="1" /> Remember me</label>
<div class="clear"></div>
<input type="submit" name="submit" value="Login" class="bt_login" />
</form>
</div>
<div class="left right">
<!-- Register Form -->
<form action="" method="post">
<h2>Sign Up!</h2>
<?php echo $id; ?>
<?php
if($_SESSION['msg']['reg-err'])
{
echo '<div class="err">'.$_SESSION['msg']['reg-err'].'</div>';
unset($_SESSION['msg']['reg-err']);
}
if($_SESSION['msg']['reg-success'])
{
echo '<div class="success">'.$_SESSION['msg']['reg-success'].'</div>';
echo $_SESSION['id'];
unset($_SESSION['msg']['reg-success']);
}
?>
I basically want to output the version of the $_SESSION['id']; into html upon submission so that it can be grabbed from the page as a user navigates the site. So, if a user were to go to index2.php and logged in successfully, their ID (the PK for their username and pass combo) would be outputted to HTML so the code could grab that if say they go to prof.php next, that session var ID from $_SESSION['id']; could be grabbed by the page and used on prof.php if a user were to submit the form on prof.php
Can someone please help me be able to reuse this ID over and over as pages are navigated?
Thanks
It sounds to me like you want the id variable to be accessible across all of the pages a user visits.
That is exactly what session is designed to do. You don't want to be writing the value to the page, since unless you put it in a form, and resubmit the form, the server side will never receive it again.
Check out this reference