Jump to content

CyberShot

Members
  • Posts

    322
  • Joined

  • Last visited

Profile Information

  • Gender
    Not Telling

CyberShot's Achievements

Advanced Member

Advanced Member (4/5)

0

Reputation

3

Community Answers

  1. I want to create a database for my person use. I am the treasurer for an HOA. I collect money for 14 units monthly. I currently use a spreadsheet but I figured it would be a great learning experience to try creating a database. ( very little skill ). I want to be able to select a unit and see how much is owed, when the last payment was made and any other notes needed. I can't decide how I should make it. Should I just make a plain database with simple records like a spreadsheet or make it more complicated? by simple, I was thinking one table. ID, name, address ( a four digit number ) , paid ( bool ), amount_paid, date, notes I have toyed with the idea of making it more tables but I don't know if it is needed. The idea is that I want the ability to select a unit number ( address ) and see what is owed up to the current date. If I have a unit that hasn't paid in a year, I want to be able to see that and the months owed. if they pay half of the amount, I want to be able to do the math on that and see that. I am trying to figure out if a one table database will work just fine.
  2. is there a general rule as to when to set a variable? I was watching a tutorial today and the author made a small function that would accept a string. Why would you set the string in the function like that? Would it work if it was just $string? function e($string=""){ do something return $string; }
  3. I have made a database and have been able to connect to it. I have a web form for inserting records. When I fill out the form and submit, I find that the database is empty. I don't see any errors. What am I doing wrong $con = new MySQLi("localhost", "user", "password", "database" ); if(mysqli_connect_errno()){ die( "Failed to connect to MySQL" . mysqli_connect_error() ); } else { echo "Connection Established!"; } ?> <form id="insert" name="insert" method="post"> <fieldset> <legend>Resident Info:</legend> Name: <input type="text" name="name" id="name"><br> Address: <input type="text" name="address"><br> Telephone: <input type="text" name="telephone"><br> Email: <input type="text" name="email"><br> Date Paid: <input type="text" name="date"><br> Method: <input type="text" name="method"><br> Amount: <input type="text" name="amount"><br> Amount Owed: <input type="text" name="amountOwed"> <button type="submit" name="submit">Submit</button> </fieldset> </form> <?php if( $_SERVER['REQUEST_METHOD'] == 'POST') { $name = $_POST["name"]; $address = $_POST["address"]; $telephone = $_POST["telephone"]; $email = $_POST["email"]; $date = $_POST["date"]; $method = $_POST["method"]; $amount = $_POST["amount"]; $amountOwed = $_POST["amountOwed"]; $name = strtolower($name); echo ucwords($name); $query = "INSERT INTO residents (name, address, telephone, email, datepaid, method, amount, amountowed) VALUES ('$name','$address','$telephone','$email','$date','$method','$amount','$amountOwed')"; $con->query($query); if(!$con->query($query)){ die( 'Error: ' . $con->error ); } } ?>
  4. Solved it $result = $myconn->query('SELECT SUM(amount) as total, SUM(gallons) as gallons FROM stats');
  5. I have a database that I made that keeps track of my gas receipts. I already have one query going $result = $myconn->query("SELECT * FROM stats ORDER BY date ASC"); while($row = mysqli_fetch_assoc($result)){ $date = str_replace('-','/', $row['date']); echo "<tr><td id='". $row['id'] . "'>" . $row['miles'] . '</td><td>' . '$' . number_format($row['amount'], 2) . '</td><td> ' . $row['gallons'] . '</td><td> ' . $date . "</td></tr>"; } I want to add two other query's to add up all the amounts that are in the amount column and all the gallons in the gallons column. So I made this query that gets the amount but I have no idea how to add up the gallons without making another query and loop. $result = $myconn->query('SELECT SUM(amount) as total FROM stats'); while($row = mysqli_fetch_assoc($result)){ $sum = $row['total']; } echo $sum;
  6. I think that was a big problem. It took me several hours throughout the entire day to decide that the date needs to be formatted going into the database. So getting it from my html form I have formatted it like so $purchase_date = date('Y-m-d H:i:s', strtotime($_POST['date'])); Now it's in the database in it's correct format as Y-M-D. Until I did that, it was returning 0000-00-00. So now I need to format it for my American eyes as M-D-Y as it's coming out of the database
  7. I added the date picker to the code using jquery. Does the date need to enter the database as a "Date" type? Right now, it's type is coming from a textbox with the type of text.
  8. Well, I have input dates in my form like this 11/25/2015 and 11-25-2015. The data type in the database is set to "date". Although I just started thinking that maybe I should just change it to text. I don't want to do that because I am thinking that it needs to be a date type so that I can sort the returns by date. I just started to realize that these date functions need to match the format of the data in the database by reading the comments here and a little of the documentation. I thought setting date(d-m-y) was formatting it to that format. I will try again and see what happens
  9. getting this right seems to be very difficult. I keep getting mixed results. Some dates are good, some it mixes up the month and date. I am not getting consistent results. I just tried using the date object and it is producing mixed results <?php if(!empty($_POST)){ $miles = $myconn->real_escape_string($_POST['miles']); $amount = $myconn->real_escape_string($_POST['amount']); $gallons = $myconn->real_escape_string($_POST['gallons']); $purchase_date = date('d-m-y', strtotime($_POST['date'])); $sql = "INSERT INTO `stats` (miles, amount, Gallons, date) VALUES ('$miles', '$amount', '$gallons', '$purchase_date')"; $myconn->query($sql) or die($myconn->error); header('Location:index.php'); } ?> while($row = mysqli_fetch_assoc($result)){ $date = str_replace('-','/', $row['date']); $dateob = new DateTime($date); $dt = $dateob->format('m-d-y'); echo "<tr><td id='". $row['id'] . "'>" . $row['miles'] . '</td><td>' . number_format($row['amount'], 2) . '</td><td> ' . $row['gallons'] . '</td><td> ' . $dt . "</td></tr>"; } I think at this point, I might just try getting it straight from the database with the query and tackle the issue at a later time.
  10. @Guru I know that when you are developing a database for the web, you might use a date format that is good for everyone. A universal format. this database is for my own personal use that will not be live on the internet. I am running it on my own machine using wamp. So I like the date format that I have been using for 35 years. It's also good practice to learn how to manipulate the date
  11. My current query $result = $myconn->query("SELECT * FROM stats"); Well, I figured it out. Seems I need to do it twice. In my html form, I have this $purchase_date = date('d-m-y', strtotime($_POST['date'])); and then when I fetch the results, I do this while($row = mysqli_fetch_assoc($result)){ $date = date('m-d-y', strtotime($row['date'])); echo $date; }
  12. This problem is playing tricks on my. I just updated my code to this $date = date('m-d-y', strtotime($row['date'])); when I refreshed my screen, the date worked. Then I insert a new record and all the of the sudden it no longer works. I thought about getting it straight from the database as you suggested Benanamen, but that would require another query. I would rather get it done with php.
  13. I have a date in my database like so 2015-09-08 I am trying to format it with the date() function like this date('m-d-y', $row['date']) but it's returning 01-01-70 for every date. If I dump $row['date'] I get 2015-09-08
×
×
  • 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.