-
Posts
2,134 -
Joined
-
Last visited
-
Days Won
42
Everything posted by benanamen
-
*
-
Can insert "option type" in ENUM in php?
benanamen replied to sigmahokies's topic in PHP Coding Help
Dont use ENUM. Others replying will tell you why not. In the mean time you can research on your own as to why not. -
Retrieving Birthday from database MySQL php problem
benanamen replied to cobusbo's topic in PHP Coding Help
Ahh, yes, of course. -
Retrieving Birthday from database MySQL php problem
benanamen replied to cobusbo's topic in PHP Coding Help
You are using deprecated code. You need to use PDO with prepared statements or Mysqli. Why are you going through all that code when you can just get the data you want in a query? SELECT column1, column2 FROM table WHERE date_column=CURDATE() You are all over the place with upper and lowercase naming. Use all lowercase separating words with an underscore. -
Display text if a database field is null else display another text
benanamen replied to zazu's topic in PHP Coding Help
The whole piece of code is wrong. First, do not use the @ to suppress errors. Errors are your friend. They tell you something is wrong and what the problem is. If you just want the state of one column, just select that one column, not selecting everything with *. By adding the WHERE condition you are specifying a certain status to return so you will not get all the status's of that column. Then you are checking your user supplied value of $paid_status for null instead of the database column status. Additionally, the query could be done with a MySQL IF http://www.w3resource.com/mysql/control-flow-functions/if-function.php SELECT IF(paid_status IS NULL,'Status is null','Status is not null') AS "paid_status" FROM depanarecuora_clients; -
Delete the H:i:s Your column is a date column, not a datetime column
-
Thats fine, as long as the format is correct by the time it reaches the insert.
-
@Jaques1, you said Would that be in reference to the following and if so why is it hacky? Seems you may be referring specifically to Unix timestamp. In regards to unix timestamp, does strtotime() have some issue with working sometimes and sometimes not? $date = date("Y-m-d",strtotime($_POST['date']));
-
First thing, leave the column type as date. Why are you using two different date formats in your form? Only one of the form inputs should be named date to correspond to $_POST['date']. 11-25-2015 and /or 11/25/2015 needs to be transformed to 2015-11-25 to insert into your date column. There are several ways to do that. Bottom line the format needs to be YYYY-MM-DD to insert into the date column.
-
What is the format of $_POST['date'] and what is the DB date column type? If the column is standard mysql date type your insert format (d-m-y) is wrong. The mysql date format is Y-m-d.
-
Code sample please?
-
Your site/server has several security issues and you are vulnerable to Click Jacking. You should also run your pages through an html validater. You have some code issues. The site is also not mobile friendly (Not responsive design).
-
You are using deprecated code that will not work at all in the latest version of Php. You need to use PDO with prepared statements or Mysqli.
-
@Jaques1, I am not sure I am getting what you said as to why. Could you please provide a case example. * And if there are worlds outside the USA, they should just be using our date format anyways.
-
OP, while I am pondering the response from @Jaques1, the SQL I said would not require two query's is simply SELECT column1, column2, date_format(date_column, '%m/%d/%Y') as date FROM stats Regardless of the date formatting, better to select the specific column names you want rather than SELECT *
-
It doesn't require another query. Post your current query.
-
You can get it straight from the database the way you want it. SELECT date_format(date_column, '%m/%d/%Y') as date @Jaques1, why go through code gymnastics to format the date when the DB can easily give it to you the way you want? Surprised you didn't mention date_format.
-
You could always just remove the two lines where you are setting time limits.
-
@Barand, it was supposed to say form "element". He is missing an opening tag for a fieldset. I didn't use the code tags because the code was highlighted and formatted. "bovine excrement!" LOL! I will have to use that one.
-
empty cell in data in columns (display record from database)
benanamen replied to sigmahokies's topic in PHP Coding Help
I concur. Very bad grammar. Very hard to understand what you were saying. -
You are using fieldset and legend wrong. There is only ONE fieldset and ONE legend per form. You should work on your code formatting. It will make it easier to read. There are several established styles to chose from. You can see a list of them here: http://www.terminally-incoherent.com/blog/2009/04/10/the-only-correct-indent-style/ Also, you keep escaping out of Php when you are still in Php. Formatted code from your last code post: <?php ini_set('display_startup_errors', 1); ini_set('display_errors', 1); error_reporting(-1); ?> <? session_start(); if ($_SESSION['user'] == '') { header("Location:login.php"); } else { include("config.php"); $sql = $dbh->prepare("SELECT * FROM employee WHERE emp_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></center>"; echo "</div>"; } } ?> <?php $hostname = ''; $username = ''; $password = ''; $db = new PDO("mysql:host=$hostname;dbname=", $username, $password); $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); // if form is submitted update task details if ($_SERVER['REQUEST_METHOD'] == 'POST') // was data sent { if ($_POST['descrip'] != '') { try { $sql = "UPDATE task SET customer_name = ?, customer_phone = ?, customer_address = ?, date_of_repair = ?, description = ?, status = ? WHERE task_id = ?"; $stmt = $db->prepare($sql); $result = $stmt->execute(array( $_POST['customer_name'], $_POST['customer_phone'], $_POST['customer_address'], $_POST['date_of_repair'], $_POST['descrip'], $_POST['status'], $_GET['task_id'] )); if ($result && $stmt->rowCount() !== 0) { $msg = 'Task has been updated successfully'; } else { $msg = 'Sorry unable to update task.'; } } catch (PDOException $e) { $db->rollBack(); die($e->getMessage()); } } } // return the task which matches $_GET['task_id']; $sql = $dbh->prepare(" SELECT task_id , customer_name , customer_phone , customer_address , date_of_repair , description , status FROM task WHERE task_id = ?"); $sql->execute(array( $_GET['task_id'] )); $sql->setFetchMode(PDO::FETCH_ASSOC); // fetch the row from the result $row = $sql->fetch(); function emps_assigned_by_taskid($db, $task_id) /******************************************* * function to list employees with checkboxes - checkbox is checked if they are assigned to the task ********************************************/ { $sql = "SELECT e.emp_id, e.emp_name, IF(a.emp_id IS NULL, 0, 1) as isAssigned FROM employee e LEFT JOIN assignment a ON e.emp_id = a.emp_id AND a.task_id = ?"; $stmt = $db->prepare($sql); $stmt = $db->prepare($sql); $stmt->execute(array( $task_id )); $emps = ''; foreach ($stmt->fetchAll() as $row) { // if isAssigned is set to 1 then set the checked attribute, otherwise leave blank $checked = $row['isAssigned'] == 1 ? ' checked="checked" ' : ''; $emps .= "<input type='checkbox' name='emp_id[]' value='{$row['emp_id']}'{$checked}> {$row['emp_name']}<br>"; } return $emps; } ?>
-
empty cell in data in columns (display record from database)
benanamen replied to sigmahokies's topic in PHP Coding Help
$data is only a count. Your actual data is in $result. These are wrong: $data['FirstName'] -
Lets forget the code a minute. Your standing next to the arrival/departure board at XYZ Airport. Now tell your buddy standing next to you what you want to know about it in a simple complete explanation. I am still not grasping what your wanting to know about the information. Something like: We are at airport XYZ on 3-6-2015. There is an arrival coming from HHN at 16:15 and then it is leaving to TPS at 18:35. I WANT TO KNOW................??????
-
How to retain select box value after submit
benanamen replied to samuel_lopez's topic in PHP Coding Help
If the form is POST'd as most forms are, the value will be in POST, not GET. -
Times you are giving dont even exist in the database. There is no 13:25 or 22:25 anywhere in the data.