Jump to content

exceedinglife

Members
  • Posts

    54
  • Joined

  • Last visited

About exceedinglife

  • Birthday 01/24/1991

Profile Information

  • Gender
    Male
  • Location
    Milwaukee WI

exceedinglife's Achievements

Regular Member

Regular Member (3/5)

0

Reputation

  1. This should be a simple task I am just not fully grasping laravel yet. I have my controllers view and models setup. I want to use my users.destroy route to delete my row in the db. But I want to do it a certain way. I want to have an alert show In my alert area on my page asking to confirm the deletion of a certain user. Im assuming I need to pass the user id in a session to an alert to confirm my delete on a delete button click. Click 1 button to open an alert on the top of my page if I click confirm it calls user.destroy. <div class="container"> <div class="row justify-content-center"> <div class="col-md-12"> <div class="card"> <div class="card-header"> <h4>View All Users</h4> @if(session()->get('success')) <div class="alert alert-success"> {{ session()->get('success') }} </div> @endif @if(session()->get('danger')) <div class="alert alert-danger"> {{ session()->get('danger') }} </div> @endif </div> <div class="card-body"> <div class="text-center my-2"> <a href="{{ route('register') }}" class="btn btn-primary">New User</a> </div> <div> <table class="table table-striped table-bordered"> <thead> <tr> <th>ID</th> <th>Name</th> <th>Email</th> <th>Username</th> <th colspan="2">Actions</th> </tr> </thead> <tbody> @foreach($users as $user) <tr> <th>{{$user->id}}</th> <td>{{$user->name}}</td> <td>{{$user->email}}</td> <td>{{$user->username}}</td> <td class="text-center"> <a href="{{ route('users.show', $user->id) }}" class="btn btn-primary mr-3">Show</a> <a href="{{ route('users.edit', $user->id) }}" class="btn btn-info text-white ml-3">Edit</a> <a href="#" class="btn btn-danger">Delete</a> </td> </tr> @endforeach </tbody> </table> public function destroy($id) { User::find($id)->delete(); return redirect()->route('users.index')->with('success','User Deleted'); } Route::resource('users', 'UserController');
  2. I put the var dump in the store method and nothing happened If I insert a row manually then the row appears in my index and I get can get and show the row with the correct data in my show view. Only I cannot update and create it. I can also delete a record successfully like this $contact = new Contact([ 'first_name' => var_dump($request->get('first_name')),
  3. Ok I fixed job_title Same thing happens tho I get the error alert on the top of the page when i click the submit button on my create view my fields say 'The first name field is required.' And nothing added to db
  4. Hello everyone, I have a PHP Laravel CRUD application I made where I am using MVC style. I have controllers views and models. My database migration is made and my table in the database is made with php artisan migrate. I am using php 7.3 and laravel 5.8. On my create view I go to create a single object in my database and my errors are thrown saying nothing in text box (no input) If I comment out the errors then just I click my submit button and nothing happens nothing is entered into my db. I have looked at many different crud examples and I am not sure why my object isn’t being created. Here is what I have //view create @section('main') <section id="section-content" class="text-center"> <div class="container contentdiv rounded"> <div class="row"> <div class="col-md-12"> <div class="pb-2 mt-4 mb-2 border-bottom clearfix"> <h2>Create Contact</h2> </div> <div > <a class="btn btn-success" href="{{route('contacts.index')}}">Back</a> </div> </div> <!-- <div class="col-md-10 mx-auto"> @if($errors->any()) <div class="alert alert-danger"> <ul> @foreach($errors->all() as $error) <li>{{ $error }}</li> @endforeach </ul> </div><br /> @endif </div> --> <div class="row"> <div class="col-md-10 mx-auto mt-3"> <form method="POST" action="{{ route('contacts.store') }}"> @csrf <div class="form-group row"> <label for="txtfn" class="col-sm-3"><b>First Name:</b></label> <div class="col-sm-9"> <input type="text" class="form-control" name="txtfn" id="txtfn"/> </div> </div> <div class="form-group row"> <label for="txtln" class="col-sm-3"><b>Last Name:</b></label> <div class="col-sm-9"> <input type="text" class="form-control" name="txtln" id="txtln"/> </div> </div> <div class="form-group row"> <label for="txtem" class="col-sm-3"><b>Email:</b></label> <div class="col-sm-9"> <input type="text" class="form-control" name="txtem" id="txtem"/> </div> </div> <button type="submit" class="btn btn-primary">Create Contact</button> </form> </div> </div> </div> </section> //controller namespace App\Http\Controllers; use App\Contact; use Illuminate\Http\Request; class ContactController extends Controller { public function store(Request $request) { $request->validate([ 'first_name' => 'required', 'last_name' => 'required', 'email' => 'required' ]); $contact = new Contact([ 'first_name' => $request->get('first_name'), 'last_name' => $request->get('last_name'), 'email' => $request->get('email'), 'job_title' => $request->get('job_title'), 'city' => $request->get('city'), 'country' => $request->get('country') ]); $contact->save(); return redirect('/contacts')->with('success', 'Contact saved!'); } public function index() { $contacts = Contact::all(); return view('contacts.index', compact('contacts')); } /** * Show the form for creating a new resource. * * @return \Illuminate\Http\Response */ public function create() { return view('contacts.create'); } // model namespace App; use Illuminate\Database\Eloquent\Model; class Contact extends Model { protected $fillable = [ 'first_name', 'last_name', 'email', 'city', 'country', 'job-title' ]; } My env is setup correctly I just don’t get the not creating object.
  5. I have a shopping cart that holds an array or my objects. I have all my customer user details serialized with a form and jQuery. I would like to insert the user data I got from my user details form (maybe I use payer or payer_info? Object. Also I would like to insert my items to the paypal CreateOrder: actions.order.create({ I am guessing I do it like this? "item_list": { "items": [ { "name": "hat", "description": "Brown color hat", "quantity": "5", "price": "3", "tax": "0.01", "sku": "1", "currency": "USD" }, { "name": "handbag", "description": "Black color hand bag", "quantity": "1", OR maybe in This is what I have $fname = $_POST['txtFirstname']; $lname = $_POST['txtLastname']; $email = $_POST['txtEmail']; var totalPrice = <?php echo $newTotal; ?> paypal.Buttons({ createOrder: function(data, actions) { // setup transaction return actions.order.create({ payer: { name: }, purchase_units: [{ amount: { value: totalPrice } }] }); },
  6. solved with echo '<img src="img/' . $row_product_image['name'] . '" class="w-100" />';
  7. Hello everyone, I have a PHP shopping cart I am working on. I have all my pictures stored in a folder url directory of my project. In my SQL database I have an image table that holds all of the image names. When I load the picture names with my php It somehow adds some extra random characters to the directory path: /img/%7B$row_product_image[name]%7D 404 (Not Found) If I hardcode the image directory img/picturename.jpg It works. Here is what I have. <?php include_once "objects/database.php"; include_once "objects/product.php"; include_once "objects/product_images.php"; // object instances $database = new Database(); $db = $database->getConnection(); $product = new Product($db); $product_image = new ProductImage($db); $recordsPerPage = 1; while($row = $stmt->fetch(PDO::FETCH_ASSOC)) { extract($row); echo '<div class="col-md-4 mb-2">'; echo '<div class="product-id d-none">{$id}</div>'; echo '<a href="product.php?id={$id}" class="product-link">'; $product_image->product_id = $pid; $stmt_product_image = $product_image->readFirst(); while($row_product_image = $stmt_product_image->fetch(PDO::FETCH_ASSOC)) { echo '<div class="mb-1">'; echo '<img src="img/{$row_product_image[name]}" class="w-100" />'; echo '</div>'; } echo '<div class="product-name mb-1">{$name}</div>'; echo '</a>'; echo '</div>'; } class ProductImage { private $pdoConn; private $table_name = "product_images"; public $id; public $product_id; public $name; public $timestamp; public function __construct($dbconn) { $this->pdoConn = $dbconn; } function readFirst() { // SELECT query $query = "SELECT id, pid, name " . "FROM " . $this->table_name . " " . "WHERE pid = ? " . "ORDER BY name DESC " . "LIMIT 0, 1"; // prepare query statement $stmt = $this->pdoConn->prepare($query); // sanitize $this->product_id=htmlspecialchars(strip_tags($this->product_id)); // bind variable as parameter $stmt->bindParam(1, $this->product_id); // execute query $stmt->execute(); // return values return $stmt; } } ?>
  8. I have 2 arrays one of the types of numbers that will be used and the 2nd array is how many times that number can be used. I have a letter that determines what kind of method will be used I need to figure out how many times I can use a certain number from an array to determine a letter+number The ‘number’ is what I have to make with all the available numbers I can use. If the number cannot be made I would like to just say number cant be made or anything but allow the program to move on. Here is what I have int[] picks = { 100, 50, 20, 10, 5, 1 }; int[] times = { 10, 10, 10, 10, 10, 10 }; string choice = Console.ReadLine(); else if (choice.Equals("D")) { Dispense(amt, billCounts); }
  9. Hello All I am working on a application where I have to represent money and display how many bills were used to make each amount. I can do this The only problem I am working on figuring out is recording the number of each bill that has been used and to subtract it for the current number. I was thinking of making a money class for 100s 50s 20s 10s 5s and 1s but I cant have each value bill with a specified number of how many. Having the value specificed I would have this : but each one of these has no value amount int hund = 10; int fif = 10; int twen = 10; int ten = 10; int five = 10; int one = 10; Or if I want a value amount I was thinking this But I cant determine a fixed number to use public class Money { public int HundBill { get; set; } public int FiftBill { get; set; } public int TwentBill { get; set; } public int TenBill { get; set; } public int FiveBill { get; set; } public int OneBill { get; set; } public Money() { HundredDollarBill = cash / 100; cash %= 100; FiftyDollarBill = cash / 50; cash %= 50; TwentyDollarBill = cash / 20; cash %= 20; TenDollarBill = cash / 10; cash %= 10; FiftyDollarBill = cash / 5; cash %= 5; OneDollarBill = cash / 1; cash %= 1; } I am getting the users input and Ill get a number and I want to minus the number of bills that were used to make that amount and to keep track.
  10. LLOOOLLLL I cant believe that is all it was My session at the top of the page i didnt realize i had that also thats all i needed to get rid of and its fixed
  11. Hello all, I have a php login project that I am almost finished with. I have users in a table and I can login with the users BUT when I click the login button I get Notice: session_start(): A session had already been started - ignoring in E:\xampp\htdocs\PHP_Login\index.php on line 53 Warning: Cannot modify header information - headers already sent by (output started at E:\xampp\htdocs\PHP_Login\index.php:53) in E:\xampp\htdocs\PHP_Login\index.php on line 60 When I click the refresh button I get what I am supposed to get and I am logged in to the dashboard. <?php error_reporting(E_ALL); ini_set("display_errors", "1"); // Initialize SESSION session_start(); // Check if logged in ifso sent to Welcome.php if(isset($_SESSION["loggedin"]) && $_SESSION["loggedin"] === true) { header("Location: php/welcome.php"); exit; } // Include config mySQL require_once "php/config.php"; // Define all variables and initialize them as 'empty' $username = $password = ""; $usernameerror = $passworderror = ""; // Process form data when submitted if($_SERVER["REQUEST_METHOD"] == "POST") { // Check if username is empty. if(empty(trim($_POST["username"]))) { $usernameerror = "Please enter a username"; } else { $username = trim($_POST["username"]); } // Check if password is empty. if(empty(trim($_POST["password"]))) { $passworderror = "Please enter a password"; } else { $password = trim($_POST["password"]); } // Validate credentials. if(empty($usernameerror) && empty($passworderror)) { // Prepare a SELECT statement. $sql = "SELECT userid, name, username, password FROM users WHERE " . "username = :username"; if($stmt = $pdoConn->prepare($sql)) { // bind variables to the prepared statement as parameters $stmt->bindParam(":username", $param_username, PDO::PARAM_STR); // Set parameters $param_username = trim($_POST["username"]); // Attempt to execute prepared statement. if($stmt->execute()) { // Check if username exists if so check password. if($stmt->rowCount() == 1) { if($row = $stmt->fetch()) { $id = $row["userid"]; $username = $row["username"]; $password_hashed = $row["password"]; $name = $row["name"]; if(password_verify($password, $password_hashed)) { // Password correct start new session session_start(); // store data in SESSION variables $_SESSION["loggedin"] = true; $_SESSION["id"] = $id; $_SESSION["username"] = $username; $_SESSION["name"] = $name; //Redirect to welcome.php header("Location: php/welcome.php"); } else { // If password INCORRECT error msg $passworderror = "Password was <b>Incorrect!</b>"; } } } else { $usernameerror = "No account was found."; } } else { echo "Error something went wrong, incorrect execution "; } } // Close prepared stmt unset($stmt); } // Close connection unset($pdoConn); } ?>
  12. My page continuely just keeps spinning on my btn click. In the network tab it opens a new tab (my php) and it has a yellow circile for google chrome - Provisional headers are shown In my form the correct data is shown - in form data. So its getting the correct values. idk if this is anything. General Request URL: http://localhost/php_crud/update.php?id=13 Referrer Policy: no-referrer-when-downgrade
  13. looks like i set this up awhile back ; Common Values: ; E_ALL (Show all errors, warnings and notices including coding standards.) ; E_ALL & ~E_NOTICE (Show all errors, except for notices) ; E_ALL & ~E_NOTICE & ~E_STRICT (Show all errors, except for notices and coding standards warnings.) ; E_COMPILE_ERROR|E_RECOVERABLE_ERROR|E_ERROR|E_CORE_ERROR (Show only errors) ; Default Value: E_ALL & ~E_NOTICE & ~E_STRICT & ~E_DEPRECATED ; Development Value: E_ALL ; Production Value: E_ALL & ~E_DEPRECATED & ~E_STRICT ; http://php.net/error-reporting error_reporting=E_ALL
  14. Ok I will try that with php.ini One of the errors I found was para_id and it was suppose to be param_id Another issue was $param_date = $date; and it suppose to be $param_date = $currentDate; I changed my button <input ...> to <button></button> My page just continues to load
  15. No error messages. My form submits and clears the data when its valid but the data isnt updated Form is <form action="<?php echo htmlspecialchars(basename($_SERVER["REQUEST_URI"])); ?>" method="post" class="rounded" id="formUpdate"> <div class="form-group row"> <label for="txtid" class="col-sm-3"><b>Id:</b></label> <div class="col-sm-9"> <input type="text" class="form-control" id="txtid" name="txtid" disabled value="<?php echo $row["id"]; ?>" /> </div> </div> <div class="form-group row"> <label for="txtname" class="col-sm-3"><b>Name:</b></label> <div class="col-sm-9"> <input type="text" class="form-control" id="txtname" name="txtname" value="<?php echo $row["name"]; ?>" /> </div> </div> <?php if(isset($nameerror)) { echo '<span id="error"><b>' . $nameerror . '</b></span>'; } ?> <div class="form-group row"> <label for="txtlang" class="col-sm-3"><b>Language:</b></label> <div class="col-sm-9"> <input type="text" class="form-control" id="txtlang" name="txtlang" value="<?php echo $row["language"]; ?>" /> </div> </div> <?php if(isset($langerror)) { echo '<span id="error"><b>' . $langerror . '</b></span>'; } ?> <div class="form-group row"> <label for="txtdate" class="col-sm-3"><b>Date:</b></label> <div class="col-sm-9"> <input type="text" class="form-control" id="txtdate" name="txtdate" disabled value="<?php echo $row["date"]; ?>" /> </div> </div> <?php if(isset($dateerror)) { echo '<span id="error"><b>' . $dateerror . '</b></span>'; } ?> <input type="hidden" name="id" value="<?php echo $id; ?>" /> <input type="submit" class="btn btn-lg btn-primary btn-block" name="submit" value="Update"/> <a href="index.php" class="btn btn-lg btn-danger btn-block" role="button">Cancel</a> </form>
×
×
  • 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.