Jump to content

ianhaney

Members
  • Posts

    330
  • Joined

  • Last visited

  • Days Won

    1

Everything posted by ianhaney

  1. Hi Is not as such of a coding help question but was unsure what category to put the question in but what is the best way to integrate Google Analytics in to my own admin backend panel rather than having to log in to Google's Analytics I did look it up but the guides I was following had bits in that I could not find on the Google side Sorry if is in the wrong category
  2. I think I will look or try to build one using PDO rather than mysqli
  3. Hi I need bit of help if ok with a php mysqli stats coding I have put in my includes/header.php file as want it on every page but for some reason it is displaying 0 users online, the data is being added to the database but not being retrieved for some reason as thought it would say 1 user online as I am on the site and refreshing it, below is the coding I have on usersonline.php file <?php //Put your basic server info here $server = "localhost"; //normally localhost $db_user = ""; //your MySQL database username $db_pass = ""; //your MySQL database password $database = ""; $timeoutseconds = 300; //this is where PHP gets the time $timestamp = time(); $timeout = $timestamp - $timeoutseconds; //connect to database //$server = localhost probably //$db_user = your MySQL database username //$db_pass = //your MySQL database password $mysqli = new mysqli($server, $db_user, $db_pass, $database); //insert the values $insert = "INSERT INTO useronline VALUES (?, ?, ?)"; $stmt = $mysqli->prepare( $insert ); $stmt->bind_param( 'iss', $timestamp, $_SERVER['REMOTE_ADDR'],$_SERVER['PHP_SELF'] ); if(!$stmt->execute()) { print "Useronline Insert Failed > "; } //delete values when they leave $delete = "DELETE FROM useronline WHERE timestamp < ?"; $stmt = $mysqli->prepare( $delete ); $stmt->bind_param( 'i', $timeout ); if(!$stmt->execute()) { print "Useronline Delete Failed > "; } //grab the results $result = "SELECT DISTINCT ip FROM useronline WHERE file = ?"; $stmt = $mysqli->prepare( $result ); $stmt->bind_param( 's', $_SERVER['PHP_SELF'] ); if(!$stmt->execute()) { print "Useronline Select Error > "; } //number of rows = the number of people online $user = $stmt->num_rows; //spit out the results $mysqli->close(); if($user == 1) { print("$user user online\n"); } else { print("$user users online\n"); } ?> then in my header.php file I have the following <?php require_once("usersonline.php"); ?> Sorry I have tried to work the issue out but I am not getting any errors so bit stuck on what to fix?
  4. Sorry is all working now
  5. I will sort the SQL injections and got a good idea about that but for now fo r some reason, the login page don't log in no more, it just loads the login page again when I click submit <?php session_start(); ob_start(); ?> <?php ini_set('display_startup_errors',1); ini_set('display_errors',1); error_reporting(-1); ?> <?php $title = "Affiliate Login - IT Done Right"; $pgDesc="IT Done Right are an Laptop repair company based in Pitsea covering Basildon, Laindon and more..."; $pgKeywords="laptop repair Pitsea, laptop repair Basildon, laptop repairs Pitsea, laptop repairs Basildon"; include ( 'includes/header.php' ); ?> <!--CONTENT--> <div id="column-whole"> <h2 class="title">Affiliate Login</h2> <hr class="carved" /> <form action="" method="post" class="signup"> <h2>Name*:</h2> <input type="text" name="username" /> <br> <h2>Password*:</h2> <input type="password" name="password" /> <br> <input type="submit" value="Login" id="submit" /> <a href="reset-pass.php">Forgot Password?</a> | <a href="new-affiliate-signup.php">Register</a> </form> <?php include'config-db.php'; if(!empty($_POST['username']) && !empty($_POST['password'])) { $username = $_POST['username']; $password = md5($_POST['password']); //$id = $_GET['id']; Can't do this, because you don't pass the ID through GET. You can't really, as you don't know the ID when the user logs in. //check data //Cant check the ID here either, as you don't know it yet $sql = "SELECT * FROM affiliates WHERE username='$username' AND password ='$password'"; $result = $conn->query($sql); if ($result->num_rows > 0){ while($row = $result->fetch_assoc()) { $username = $row["username"]; //Store the name in the session $_SESSION['username'] = $username; //You should be getting the ID HERE, as this is where you know who the User is. $id = $row['id']; header("location:affiliate-profile.php?id=$id"); } } else { echo "<h2>Incorrect Username/Password</h2>"; } } ?> </div> <!--CONTENT--> <?php include( 'includes/footer.php' ); ?>
  6. Sorry am winning slowly I have the info displayed on the page now but for some reason, the page is not showing the header and footer.php files which should be as have includes/header.php as to the updated coding below on the affiliate-profile.php <? session_start(); if($_SESSION['userperson']==''){ header("Location:affiliate-login.php"); }else{ include("config-db.php"); $sql=$conn->prepare("SELECT * FROM affiliates WHERE id=?"); $sql->execute(array($_SESSION['userperson'])); while($r=$sql->fetch()){ ?> <?php $title = "Affiliate Profile - IT Done Right"; $pgDesc="IT Done Right are an Laptop repair company based in Pitsea covering Basildon, Laindon and more..."; $pgKeywords="laptop repair Pitsea, laptop repair Basildon, laptop repairs Pitsea, laptop repairs Basildon"; include ( 'includes/header.php' ); ?> <!--CONTENT--> <div id="column-whole"> <br /> <?php echo "<div class='home-content'>"; echo "<center><h2 class='welcome'>Hello, ".$r['username']."</h2>"; echo "<br><br>"; echo "<div style='float: left;'><a href='logout.php'>Log Out</a></div></center>"; echo "</div>"; echo "<br><br>"; } } ?> <h2 class="title">Your Affiliate Information</h2> <hr class="carved" /> <?php // connect to the database include('connect-db.php'); if ($result = $mysqli->query("SELECT id, username, amount_earned FROM affiliates WHERE id = '$_GET[id]'")) { // display records if there are records to display if ($result->num_rows > 0) { echo "<table class='affiliate'>"; echo "<tr>"; echo "<th>Affiliate ID</th>"; echo "<th>Name</th>"; echo "<th>Amount Earned</th>"; echo "</tr>"; while ($row = $result->fetch_object()) { // set up a row for each record echo "<tr>"; echo "<td>" . $row->id . "</td>"; echo "<td>" . $row->username . "</td>"; echo "<td>" . '£' . $row->amount_earned . "</td>"; echo "</tr>"; } echo "</table>"; } // if there are no records in the database, display an alert message else { echo "No results to display!"; } } // show an error if there is an issue with the database query else { echo "Error: " . $mysqli->error; } // close database connection $mysqli->close(); ?> </div> <!--CONTENT--> <?php include( 'includes/footer.php' ); ?>
  7. Sorry was my fault not explaining it properly regarding the id of the user I got that id number now in the url but just displays your affiliate information and nothing else On the page it should be displaying the following info id and name I have the following on the page www.it-doneright.co.uk/afiliate-profile.php?id=11 <? session_start(); if($_SESSION['userperson']==''){ header("Location:affiliate-login.php"); }else{ include("config-db.php"); $sql=$conn->prepare("SELECT * FROM affiliates WHERE id=?"); $sql->execute(array($_SESSION['userperson'])); while($r=$sql->fetch()){ ?> <?php $title = "Affiliate Profile - IT Done Right"; $pgDesc="IT Done Right are an Laptop repair company based in Pitsea covering Basildon, Laindon and more..."; $pgKeywords="laptop repair Pitsea, laptop repair Basildon, laptop repairs Pitsea, laptop repairs Basildon"; include ( 'includes/header.php' ); ?> <!--CONTENT--> <div id="column-whole"> <br /> <?php echo "<div class='home-content'>"; echo "<center><h2 class='welcome'>Hello, ".$r['username']."</h2>"; echo "<br><br>"; echo "<div style='float: left;'><a href='logout.php'>Log Out</a></div></center>"; echo "</div>"; echo "<br><br>"; } } ?> <h2 class="title">Your Affiliate Information</h2> <hr class="carved" /> <?php // connect to the database include('config-db.php'); if ($result = $mysqli->query("SELECT id, username, amount_earned FROM affiliates WHERE id = '$_GET[id]'")) { // display records if there are records to display if ($result->num_rows > 0) { echo "<table class='affiliate'>"; echo "<tr>"; echo "<th>Affiliate ID</th>"; echo "<th>Name</th>"; echo "<th>Amount Earned</th>"; echo "</tr>"; while ($row = $result->fetch_object()) { // set up a row for each record echo "<tr>"; echo "<td>" . $row->id . "</td>"; echo "<td>" . $row->username . "</td>"; echo "<td>" . '£' . $row->amount_earned . "</td>"; echo "</tr>"; } echo "</table>"; } // if there are no records in the database, display an alert message else { echo "No results to display!"; } } // show an error if there is an issue with the database query else { echo "Error: " . $mysqli->error; } // close database connection $mysqli->close(); ?> </div> <!--CONTENT--> <?php include( 'includes/footer.php' ); ?>
  8. Sorry lost me, I am confused now I can't put id=11 as other users will be signing up which will have different ids I have taken off AND id = '$id' from the query now and it is now redirecting to the following page but still no id number is pulled from the database http://www.it-doneright.co.uk/affiliate-profile.php?id= below is my affiliate-profile.php file code <? session_start(); if($_SESSION['username']==''){ header("Location:affiliate-login.php"); }else{ include("config-db.php"); $sql=$dbh->prepare("SELECT * FROM affiliates WHERE id=?"); $sql->execute(array($_SESSION['username'])); while($r=$sql->fetch()){ ?> <?php $title = "Affiliate Profile - IT Done Right"; $pgDesc="IT Done Right are an Laptop repair company based in Pitsea covering Basildon, Laindon and more..."; $pgKeywords="laptop repair Pitsea, laptop repair Basildon, laptop repairs Pitsea, laptop repairs Basildon"; include ( 'includes/header.php' ); ?> <!--CONTENT--> <div id="column-whole"> <br /> <?php echo "<div class='home-content'>"; echo "<center><h2 class='welcome'>Hello, ".$r['username']."</h2>"; echo "<br><br>"; echo "<div style='float: left;'><a href='logout.php'>Log Out</a></div></center>"; echo "</div>"; echo "<br><br>"; } } ?> <h2 class="title">Your Affiliate Information</h2> <hr class="carved" /> <?php // connect to the database include('config-db.php'); if ($result = $mysqli->query("SELECT id, username, amount_earned FROM affiliates WHERE id = '$_GET[id]'")) { // display records if there are records to display if ($result->num_rows > 0) { echo "<table class='affiliate'>"; echo "<tr>"; echo "<th>Affiliate ID</th>"; echo "<th>Name</th>"; echo "<th>Email</th>"; echo "<th>Amount Earned</th>"; echo "</tr>"; while ($row = $result->fetch_object()) { // set up a row for each record echo "<tr>"; echo "<td>" . $row->id . "</td>"; echo "<td>" . $row->username . "</td>"; echo "<td>" . '£' . $row->amount_earned . "</td>"; echo "</tr>"; } echo "</table>"; } // if there are no records in the database, display an alert message else { echo "No results to display!"; } } // show an error if there is an issue with the database query else { echo "Error: " . $mysqli->error; } // close database connection $mysqli->close(); ?> </div> <!--CONTENT--> <?php include( 'includes/footer.php' ); ?>
  9. I changed it now to the following but get the error: Notice: Undefined index: id in /home/sites/it-doneright.co.uk/public_html/affiliate-login.php on line 43 <?php session_start(); ob_start(); ?> <?php ini_set('display_startup_errors',1); ini_set('display_errors',1); error_reporting(-1); ?> <?php $title = "Affiliate Login - IT Done Right"; $pgDesc="IT Done Right are an Laptop repair company based in Pitsea covering Basildon, Laindon and more..."; $pgKeywords="laptop repair Pitsea, laptop repair Basildon, laptop repairs Pitsea, laptop repairs Basildon"; include ( 'includes/header.php' ); ?> <!--CONTENT--> <div id="column-whole"> <h2 class="title">Affiliate Login</h2> <hr class="carved" /> <form action="" method="post" class="signup"> <h2>Name*:</h2> <input type="text" name="username" /> <br> <h2>Password*:</h2> <input type="password" name="password" /> <br> <input type="submit" value="Login" id="submit" /> <a href="reset-pass.php">Forgot Password?</a> | <a href="new-affiliate-signup.php">Register</a> </form> <?php include'config-db.php'; if(!empty($_POST['username']) && !empty($_POST['password'])) { $username = $_POST['username']; $password = md5($_POST['password']); $id = $_GET['id']; //check data $sql = "SELECT * FROM affiliates WHERE username='$username' AND password ='$password' AND id = '$id'"; $result = $conn->query($sql); if ($result->num_rows > 0){ while($row = $result->fetch_assoc()) { $username = $row["username"]; //Store the name in the session $_SESSION['username'] = $username; header("location:affiliate-profile.php?id=$id"); } } else { echo "<h2>Incorrect Username/Password</h2>"; } } ?> </div> <!--CONTENT--> <?php include( 'includes/footer.php' ); ?> And it also comes up with Incorrect Username/Password when it is correct info
  10. I have sorted that now and is working but now got a id issue after logging in, it should redirect to profile.php?id=11 but instead it is going to profile.php?id= so I know I need to pull the id from the database but unsure how to do it, would id needed to be added to the following query $sql = "SELECT * FROM affiliates WHERE username='$username' AND password ='$password'"; am I close at all?
  11. Hi I now have a new php login script with forget password and seems to be working so far and have signed up but having issues with the login script each time I go to login, I get the following error Warning: Cannot modify header information - headers already sent by (output started at /home/sites/it-doneright.co.uk/public_html/includes/header.php:107) in/home/sites/it-doneright.co.uk/public_html/affiliate-login.php on line 49 I looked up this error and was saying about blank lines above the coding but have checked and is no blank files in the coding so am quite lost to be honest below is what I have in my login page <?php session_start(); ?> <?php ini_set('display_startup_errors',1); ini_set('display_errors',1); error_reporting(-1); ?> <?php $title = "Affiliate Login - IT Done Right"; $pgDesc="IT Done Right are an Laptop repair company based in Pitsea covering Basildon, Laindon and more..."; $pgKeywords="laptop repair Pitsea, laptop repair Basildon, laptop repairs Pitsea, laptop repairs Basildon"; include ( 'includes/header.php' ); ?> <!--CONTENT--> <div id="column-whole"> <h2 class="title">Affiliate Login</h2> <hr class="carved" /> <form action="" method="post" class="signup"> <h2>Name*:</h2> <input type="text" name="username" /> <br> <h2>Password*:</h2> <input type="password" name="password" /> <br> <input type="submit" value="Login" id="submit" /> <a href="reset-pass.php">Forgot Password?</a> | <a href="new-affiliate-signup.php">Register</a> </form> <?php include'config-db.php'; if(!empty($_POST['username']) && !empty($_POST['password'])) { $username = $_POST['username']; $password = md5($_POST['password']); //check data $sql = "SELECT * FROM affiliates WHERE username='$username' AND password ='$password'"; $result = $conn->query($sql); if ($result->num_rows > 0){ while($row = $result->fetch_assoc()) { $username = $row["username"]; //Store the name in the session $_SESSION['login'] = $username; header("location:affiliate-profile.php?id=?"); } } else { echo "<h2>Incorrect Username/Password</h2>"; } } ?> </div> <!--CONTENT--> <?php include( 'includes/footer.php' ); ?>
  12. yeah sorry I saw that response, going by what the replies were, it was easier to scrap it all and start again I did manage to do the reset password once and it did change in the password hashed column but didn't change the psalt column next to it so I was unable to login
  13. Hi Thank you for the replie, appreciate it I think I am going to scrap the current coding and look at generating a new random password but when tried to do it, I got stuck but will give it another go
  14. Regarding the sql syntax error, I put the sql query in a checker and said it was ok or have I got it wrong somewhere?
  15. Hi maxxd The password is hashed in the database as read is never good idea to store passwords as plain text for security reasons so have hashed it and that side is all ok
  16. Hi I know it is not the best way to do it but just want to get it working for the time being I want the user to enter their email address and have their password sent to their email address if they forget it I have the following so far <form method="post" action="forgot-password.php" class="signup"> <label>Email Address: <input name="username" type="text" /></label> <br /> <input type="submit" name="submit" value="submit" id="submit" /> </form> <?php $con = mysqli_connect("","","",""); // Check connection if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } if(isset($_POST['submit'])) { $mail=$_POST['username']; $q="select * password from affiliates where username='".$mail."'"; $res=mysqli_fetch_assoc($con, $q); $password=$res['password']; $msg='Your password is '.$password; $sub='Send password'; $header='From: noreply@it-doneright.co.uk'; $m=mail($mail,$sub,$msg,$header); if($m) { echo'check your mail'; } } ?> I have probably made some mistakes with the code in relation to mysql and mysqli but am trying to get it working and doing my best before I wanted to post here That code sends the email but the password is blank, it just says within the email Your password: On the page, I have the following error Notice: Undefined variable: res in /home/sites/it-doneright.co.uk/public_html/forgot-password.php on line 51 NULL Warning: mysqli_fetch_assoc() expects exactly 1 parameter, 2 given in /home/sites/it-doneright.co.uk/public_html/forgot-password.php on line 53 check your mail - SO IS SENDING THE MAIL
  17. Hi QuickOldCar Thank you so much, is working perfect now
  18. Hi Sorry I have tried to work this out on my own and got so far but got stuck I have a issue where the user logs in and it redirects to their profile page with their info relating to the id number for that user but if I click home and then click login in again, I was hoping it would detect that they are still logged in and redirect them to the profile page with their info again but when I do that, it goes to affiliate-profile.php?id= It realises the user is logged in as it has at the top Hello followed by their email address but below it is not displaying the info relating to them and just says No results to display Below is the coding from the affiliate-login.php file <? session_start(); if ($_SESSION['user']!='') {header("Location: affiliate-profile.php?id=$id");} $dbh=new PDO('mysql:dbname=;host=localhost', '', '');/*Change The Credentials to connect to database.*/ $email=$_POST['mail']; $password=$_POST['pass']; if(isset($_POST) && $email!='' && $password!=''){ $sql=$dbh->prepare("SELECT id,password,psalt FROM affiliates WHERE username=?"); $sql->execute(array($email)); while($r=$sql->fetch()){ $p=$r['password']; $p_salt=$r['psalt']; $id=$r['id']; } $site_salt="subinsblogsalt";/*Common Salt used for password storing on site. You can't change it. If you want to change it, change it when you register a user.*/ $salted_hash = hash('sha256',$password.$site_salt.$p_salt); if($p==$salted_hash){ $_SESSION['user']=$id; header("Location:affiliate-profile.php?id=$id"); }else{ echo "<h2>Username/Password is Incorrect.</h2>"; } } ?> <!--CONTENT--> <div id="column-whole"> <h2 class="title">Login</h2> <hr class="carved" /> <form method="POST" action="affiliate-login.php" class="signup"> <table> <tr> <td> <td colspan="3"> <strong>Affiliate Login</strong> </td> </tr> <tr> <td width="78">E-Mail</td> <td width="6">:</td> <td width="294"><input size="25" name="mail" type="text" placeholder="Your Email Address"></td> </tr> <tr> <td>Password</td><td>:</td> <td><input name="pass" size="25" type="password" placeholder="Your Password"></td> </tr> <tr> <td></td> <td></td> <td><input type="submit" name="Submit" value="Login" id="submit" ></td> </tr> </table> </form> </div> <!--CONTENT--> <?php include( 'includes/footer.php' ); ?> I think the issue with this coding is the third line if ($_SESSION['user']!='') {header("Location: affiliate-profile.php?id=$id");} as guessing that is saying if the session is empty then redirect to the file but I changed that location to affiliate-login.php but kept loading and then said unable to load properly Below is the affiliate-profile.php coding <? session_start(); if($_SESSION['user']==''){ header("Location:affiliate-login.php"); }else{ include("config.php"); $sql=$dbh->prepare("SELECT * FROM affiliates WHERE id=?"); $sql->execute(array($_SESSION['user'])); while($r=$sql->fetch()){ ?> <!--CONTENT--> <div id="column-whole"> <br /> <?php echo "<div class='home-content'>"; echo "<center><h2 class='welcome'>Hello, ".$r['username']."</h2>"; echo "<br><br>"; echo "<div style='float: left;'><a href='logout.php'>Log Out</a></div></center>"; echo "</div>"; echo "<br><br>"; } } ?> <h2 class="title">Your Affiliate Information</h2> <hr class="carved" /> <?php // connect to the database include('connect-db.php'); if ($result = $mysqli->query("SELECT id, name, username, amount_earned FROM affiliates WHERE id = '$_GET[id]'")) { // display records if there are records to display if ($result->num_rows > 0) { echo "<table class='affiliate'>"; echo "<tr>"; echo "<th>Affiliate ID</th>"; echo "<th>Name</th>"; echo "<th>Email</th>"; echo "<th>Amount Earned</th>"; echo "</tr>"; while ($row = $result->fetch_object()) { // set up a row for each record echo "<tr>"; echo "<td>" . $row->id . "</td>"; echo "<td>" . $row->name . "</td>"; echo "<td>" . $row->username . "</td>"; echo "<td>" . '£' . $row->amount_earned . "</td>"; echo "</tr>"; } echo "</table>"; } // if there are no records in the database, display an alert message else { echo "No results to display!"; } } // show an error if there is an issue with the database query else { echo "Error: " . $mysqli->error; } // close database connection $mysqli->close(); ?> </div> <!--CONTENT--> <?php include( 'includes/footer.php' ); ?> Sorry, have tried to fix the issue before posting here
  19. Hi Sorry just need little bit of help, I think I know the issue but just need help on how to solve it I have a form that does insert and update in one go and I am able to pull the data from the database all ok for the correct id for the record but when I change the amount earned amount, it is not updating within the database I think it is because in my database table, I have the following columns id, name, username, password, psalt, amount_earned and I am only setting not all of all the columns if that makes sense as I don't want the password and psalt columns updating, I only want the name, username and amount_earned columns updating Below is the code I have <?php ini_set('display_startup_errors',1); ini_set('display_errors',1); error_reporting(-1); ?> <?php /* Allows the user to both create new records and edit existing records */ // connect to the database include("connect-db.php"); // creates the new/edit record form // since this form is used multiple times in this file, I have made it a function that is easily reusable function renderForm($name = '', $username = '', $amount_earned = '', $error = '', $id = '') { ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <title> <?php if ($id != '') { echo "Edit Affiliate"; } else { echo "New Affiliate"; } ?> </title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <link rel="stylesheet"href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.11.2/themes/blitzer/jquery-ui.css"/> <script src="//code.jquery.com/jquery-1.10.2.js"></script> <script src="//code.jquery.com/ui/1.11.2/jquery-ui.js"></script> <link rel="stylesheet" type="text/css" media="screen" href="css/styles.css" /> <script src="js/jquery.ui.timepicker.js"></script> <link rel="stylesheet" type="text/css" media="screen" href="css/jquery.ui.timepicker.css" /> <!--<script src="//cdn.ckeditor.com/4.5.5/full/ckeditor.js"></script>--> </head> <body> <div id="logo"> <img src="images/logo/it-done-right.jpg" alt="" title=""> </div> <? session_start(); if($_SESSION['user']==''){ header("Location:../index.php"); }else{ include("../config.php"); $sql=$dbh->prepare("SELECT * FROM users WHERE id=?"); $sql->execute(array($_SESSION['user'])); while($r=$sql->fetch()){ echo "<div class='home-content'>"; echo "<center><h2>Hello, ".$r['username']."</h2>"; echo "<a href='../logout.php'>Log Out</a> <br><br> <a href='../index.php'>Home</a></center>"; echo "</div>"; echo "<br>"; } } ?> <?php include("nav-menu.php"); ?> <h1><?php if ($id != '') { echo "Edit Affiliate"; } else { echo "New Affiliate"; } ?></h1> <?php if ($error != '') { echo "<div style='padding:4px; border:1px solid red; color:red'>" . $error . "</div>"; } ?> <form action="" method="post" class="basic-grey"> <div> <?php if ($id != '') { ?> <input type="hidden" name="id" value="<?php echo $id; ?>" /> <p>Affiliate ID: <?php echo $id; ?></p> <?php } ?> <br> <strong>Customer Name:</strong> <input type="text" name="name" value="<?php echo $name; ?>"/> <br/> <strong>Customer Email:</strong> <input type="text" name="username" value="<?php echo $username; ?>"/> <br> <strong>Amount Earned:</strong> <input type="text" name="amount_earned" value="<?php echo $amount_earned; ?>"/> <br> <input type="submit" name="submit" value="Add/Update Affiliate" /> </div> </form> </body> </html> <?php } /* EDIT RECORD */ // if the 'id' variable is set in the URL, we know that we need to edit a record if (isset($_GET['id'])) { // if the form's submit button is clicked, we need to process the form if (isset($_POST['submit'])) { // make sure the 'id' in the URL is valid if (is_numeric($_POST['id'])) { // get variables from the URL/form $id = $_POST['id']; $name = htmlentities($_POST['name'], ENT_QUOTES); $username = htmlentities($_POST['username'], ENT_QUOTES); $amount_earned = htmlentities($_POST['amount_earned'], ENT_QUOTES); // check that firstname and lastname are both not empty if ($name == '' || $username == '' || $amount_earned == '') { // if they are empty, show an error message and display the form $error = 'ERROR: Please fill in all required fields!'; renderForm($name, $username, $amount_earned, $error, $id); } else { // if everything is fine, update the record in the database if ($stmt = $mysqli->prepare("UPDATE affiliates SET name = ?, username = ?, amount_earned = ?, WHERE id=?")) { $stmt->bind_param("sssi", $name, $username, $amount_earned, $id); $stmt->execute(); $stmt->close(); } // show an error message if the query has an error else { echo "ERROR: could not prepare SQL statement."; } // redirect the user once the form is updated header("Location: view-affiliates.php"); } } // if the 'id' variable is not valid, show an error message else { echo "Error!"; } } // if the form hasn't been submitted yet, get the info from the database and show the form else { // make sure the 'id' value is valid if (is_numeric($_GET['id']) && $_GET['id'] > 0) { // get 'id' from URL $id = $_GET['id']; // get the recod from the database if($stmt = $mysqli->prepare("SELECT id, name, username, amount_earned FROM affiliates WHERE id=?")) { $stmt->bind_param("i", $id); $stmt->execute(); $stmt->bind_result($id, $name, $username, $amount_earned); $stmt->fetch(); // show the form renderForm($name, $username, $amount_earned, NULL, $id); $stmt->close(); } // show an error if the query has an error else { echo "Error: could not prepare SQL statement"; } } // if the 'id' value is not valid, redirect the user back to the view.php page else { header("Location: view-affiliates.php"); } } } /* NEW RECORD */ // if the 'id' variable is not set in the URL, we must be creating a new record else { // if the form's submit button is clicked, we need to process the form if (isset($_POST['submit'])) { // get the form data $name = htmlentities($_POST['name'], ENT_QUOTES); $username = htmlentities($_POST['username'], ENT_QUOTES); $amount_earned = htmlentities($_POST['amount_earned'], ENT_QUOTES); // check that firstname and lastname are both not empty if ($name == '' || $username == '' || $amount_earned == '') { // if they are empty, show an error message and display the form $error = 'ERROR: Please fill in all required fields!'; renderForm($name, $username, $amount_earned, $error); } else { // insert the new record into the database if ($stmt = $mysqli->prepare("INSERT affiliates (name, username, amount_earned) VALUES (?, ?, ?)")) { $stmt->bind_param("sss", $name, $username, $amount_earned); $stmt->execute(); $stmt->close(); } // show an error if the query has an error else { echo "ERROR: Could not prepare SQL statement."; } // redirec the user header("Location: view-affiliates.php"); } } // if the form hasn't been submitted yet, show the form else { renderForm(); } } // close the mysqli connection $mysqli->close(); ?> I thought it would be possible to choose what columns to update? Sorry Thank you in advance Ian
  20. Sorry my fault, I spotted that shortly after and is perfect now
  21. Thank you appreciate it, is all ok now Just got one more little issue now I have logged in but want to redirect the user to affiliate-profile.php?id=theiridnumber but I can't get the id number from the database to display within the url
  22. Hi I have created a registration php file script and works perfect but can't work out the login script issue I am having Below is the errors I get Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/sites/it-doneright.co.uk/public_html/affiliate-login.php:149) in /home/sites/it-doneright.co.uk/public_html/affiliate-login.php on line 152 Warning: Cannot modify header information - headers already sent by (output started at /home/sites/it-doneright.co.uk/public_html/affiliate-login.php:149) in /home/sites/it-doneright.co.uk/public_html/affiliate-login.php on line 153 Notice: Undefined index: mail in /home/sites/it-doneright.co.uk/public_html/affiliate-login.php on line 155 Notice: Undefined index: pass in /home/sites/it-doneright.co.uk/public_html/affiliate-login.php on line 156 Below is the coding I have <form method="POST" action="affiliate-login.php" class="signup"> <table> <tr> <td> <td colspan="3"> <strong>Affiliate Login</strong> </td> </tr> <tr> <td width="78">E-Mail</td> <td width="6">:</td> <td width="294"><input size="25" name="mail" type="text" placeholder="Your Email Address"></td> </tr> <tr> <td>Password</td><td>:</td> <td><input name="pass" size="25" type="password" placeholder="Your Password"></td> </tr> <tr> <td></td> <td></td> <td><input type="submit" name="Submit" value="Login" id="submit" ></td> </tr> </table> <? session_start(); if($_SESSION['user']!=''){header("Location:affiliate-profile.php");} $dbh=new PDO('mysql:dbname=dbname;host=localhost', 'dbusername', 'dbpassword');/*Change The Credentials to connect to database.*/ $email=$_POST['mail']; $password=$_POST['pass']; if(isset($_POST) && $email!='' && $password!=''){ $sql=$dbh->prepare("SELECT id,password,psalt FROM tablename WHERE username=?"); $sql->execute(array($email)); while($r=$sql->fetch()){ $p=$r['password']; $p_salt=$r['psalt']; $id=$r['id']; } $site_salt="subinsblogsalt";/*Common Salt used for password storing on site. You can't change it. If you want to change it, change it when you register a user.*/ $salted_hash = hash('sha256',$password.$site_salt.$p_salt); if($p==$salted_hash){ $_SESSION['user']=$id; header("Location:affiliate-profile.php"); }else{ echo "<h2>Username/Password is Incorrect.</h2>"; } } ?> </form> Just can't work the issue out, the page just loads back to the affiliate-login.php page again instead of logging in and going to affiliate-profile.php page
  23. Ok great perfect, thank you so much for your help, appreciate it
  24. Thank you so much, is working perfect now Just to confirm, will it reset on the 1st of each month so tomorrow 1/12/2015 should reset to display the amount for December Is that right?
  25. I got the following now but is not outputting the month name SELECT SUM(job_cost) as job_cost, SUM(profit) as profit FROM repairs WHERE MONTHNAME(exrdate) = MONTHNAME(CURDATE()) AND YEAR(exrdate) = YEAR(CURDATE()) do I need to add MONTHNAME after as profit
×
×
  • 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.