-
Posts
24,423 -
Joined
-
Last visited
-
Days Won
806
Posts posted by Barand
-
-
I also you suggest you check the manual for PDOStatement::execute() to see what it returns.
-
The SQL tutorial link in my signature below may be of some use. It is based on a fictional school.
-
if I were you I'd use a newline (\n) to separate the data instead of "@@@".
if(isset($_POST['textdata'])) { file_put_contents('data.txt', $_POST['textdata']."\n", FILE_APPEND); }
Then, if you data.txt file contains, say
TESTA TESTB TESTC TESTD
... you can read it back and separate the items into an array using file();
$data = file('data.txt');
giving
$data = Array ( [0] => TESTA [1] => TESTB [2] => TESTC [3] => TESTD )
- 1
-
1 minute ago, ginerjm said:
I stopped reading when I saw this:
Pity. If you had read on you'd have seen he is writing to a text file.
- 1
-
10 minutes ago, Barand said:
BTW, that line you added is missing a ";" from the end
Turn your error reporting ON
- 1
-
23 minutes ago, thehubclick said:
// i added this line
$string1="| "BTW, that line you added is missing a ";" from the end;
-
In what way is it "not working"?
What do you want to happen so you can say it is working?
When posting, bear in mind we are not psychic and cannot see your screen and the data values you are seeing.
-
It's hard to find something that is defined.
- Your first query selects productcode from products but the value for the options is "productid"
- The select is named "drpcode" yet you are expecting $_POST[''productid']
4 hours ago, xtekuta said:Im new in jQuery
What jQuery? What AJAX function?
-
5 hours ago, ajetrumpet said:
Here is the code I'm currently testing (which just prints out "on" or "off" to indicate which boxes are checked):
I'm curious to know how that posted code outputs any settings with "off" (unchecked checkboxes aren't posted)
-
+----------------+ +----------------+ | Make sure to |---+ +------->| (e.g. Courier) | +----------------+ | | +----------------+ | | | | +----------+ | | +->| use a |---+ | | +----------------+ +----------+ | | +------->| and use spaces | | | +----------------+ | +----------------+ | | +--->| monospace font |-----+ | +----------------+ | +----------+ | | not tabs |<----------+ +----------+ | +--------------------------------------------------------------------------+ | V +---------------+ | It also helps | +---------------+ | | | +-------------------+ +-------------------+ +------------------------>| if you sometimes |---------------------->| switch between | +-------------------+ +-------------------+ | | +-----------------+-----------------+ | | | | +-------------------+ +-------------------+ | overtype | | insert | +-------------------+ +-------------------+ | | | | | +----------+ | +----------=>| modes |<----------+ +----------+
- 2
- 1
- 1
-
Plus a couple of related sections...
-
Sorry, there is an error
$where = "max_price <= ?";
should be
$where[] = "max_price <= ?";
-
The query has inbuilt syntax errors. Your WHERE clause will always begin with "WHERE AND … "
IMO a cleaner way to include conditions only if there is a value is
$min_price = 10; $max_price = 50; $featured = 1; $binds = []; $where = []; $whereclause = ''; if ($min_price > 0) { $where[] = "min_price >= ?"; $binds[] = $min_price; } if ($max_price > 0) { $where = "max_price <= ?"; $binds[] = $max_price; } if (in_array($featured, [0,1])) { $where[] = "featured = ?"; $binds[] = $featured ; } if ($where) $whereclause = 'WHERE ' . join(' AND ', $where); $find_records = $db->prepare(" SELECT * FROM projects $whereclause "); $find_records->execute($binds); $result_records = $find_records->fetchAll(PDO::FETCH_ASSOC);
-
Or you can use ? placeholders.
$find_records = $db->prepare("SELECT * FROM projects WHERE min_price >= ? AND max_price <= ? AND featured = ? "); $find_records->execute( [ $min_price, $max_price, $featured ] ); $result_records = $find_records->fetchAll(PDO::FETCH_ASSOC);
-
If you do it the second way (no placeholders), there is no point in preparing it; just use $db->query().
CAVEAT: If $vars originated from an external source ($_GET, $_POST, $_COOKIE etc) then you are injection-prone and, as you are not even escaping the values your queries could fail.
EG
$username = "O'Reilly"; $res = $db->query("SELECT password FROM user WHERE username = '$username' ") // fails with syntax error and open to injection
If in doubt, prepare();
1 minute ago, imgrooot said:But if you see my min and max price, i use equals to and less/more than operators to compare. But your array does not show that.
Your bindings do not either, the query does. The array is just a more convenient way of binding.
-
Your WHERE clause will then be like this...
… WHERE id = N AND duplicate = 'False'
6 minutes ago, Nigel12 said:I'm using VB.NET
You have my sympathy.
Also those "Answer_x" columns should ne normalized into a separate table; separate row for each answer.
-
30 minutes ago, tryingphp said:
("DELETE FROM users WHERE user_id = CURRENT_DATE+3 ");
The thing about programming is that it requires some thought. Why would as user_id be equal to a date value?
Why don't you do some reading about how to use SQL instead of taking the "infinite monkeys with typewriters" approach in the hope you eventually come up with a right answer?
On 11/16/2019 at 7:37 PM, Barand said:Instead of deleting the record, update the record setting the expiry date to CURRENT_DATE+3 days
-
On 11/16/2019 at 7:37 PM, Barand said:
One way would be to add an "expiry_date" (default NULL) column to your user table.
Instead of deleting the record, update the record setting the expiry date to CURRENT_DATE+3 days.
Run a job every day that does a "DELETE FROM user WHERE expiry_date < CURRENT_DATE
This time, read what I said.
-
PS there is a perfectly good function in php already which does all this for you
$file_data = file_get_contents($file);
Which reminds me, your function needs to return the file data.
-
If KB_TO_BYTES has not been defined then you need
const KB_TO_BYTES = 1024;
// We don't need to write to the file, so just open for reading $fp = fopen($file, 'r'); // open file for reading if ($fp) { $file_data = fread($fp, 8 * KB_TO_BYTES); fclose($fp); //close the file }
-
Where did I say that?
The comments are fine - you need to add the code that implements the comments.
You also need to ensure that the constant KB_TO_BYTES has been defined and use it correctly as a constant (ie without the quotes).
-
You have this comment...
1 hour ago, kiko12122 said:// We don't need to write to the file, so just open for reading
but you don't get around to actually opening the file - the comment won't do it for you. Therefore in the next line $fp has not been defined.
1 hour ago, kiko12122 said:$file_data = fread( $fp, 8 * 'KB_IN_BYTES' );
Further, you have put 'KB_IN_BYTES' inside quotes thus making it a string value (which has a numeric value of 0).
So I guess the problem is in trying to read 0 bytes from a file that doesn't exist.
And what is the comment about being "good citizens"? You don't close it either.
(Has KB_IN_BYTES been defined as constant anywhere?)
-
Try this
// Attempt delete query execution $stmt = $dbc->prepare("DELETE FROM users WHERE user_id = ? "); // prepare query with placeholder (?) for id value $stmt->bind_param('i', $_SESSION['user_id']); // bind the id value to the placeholder if ($stmt->execute()) { // execute the query echo "Records were deleted successfully."; } else { echo "ERROR: Not able to execute query " ; }
-
That same phpinfo() output will tell you the status of your error reporting settings. If you are developing on a hosted site it is probable that any error reports go to your php error log instead being displayed.
php function help
in PHP Coding Help
Posted · Edited by Barand
"Unexpected end of file" errors occur when the php parser expects something but cannot find it. Usual causes are an opening { without a corresponding closing } or quots at the start of a string and then no closing quotes.
You'll have to find it yourself as it's impossible from just the couple of isolated snippets that we can see.