Jump to content

micksulley

New Members
  • Posts

    7
  • Joined

  • Last visited

Everything posted by micksulley

  1. OK I have sorted it. I created a function decOrNull() which returns either a decimal value or null, and changed $sale_stamp = $_POST['sale_stamp']; to $sale_stamp = decOrNull($_POST['sale_stamp']); and it works. I should have seen that myself earlier Thanks for your help anyway. Mick
  2. I have created a form to edit fields in a database table. This is basically what it does sale_stamp : <input type="text" name="sale_stamp" value="<?php echo $sale_stamp;?>" > $sale_stamp = $_POST['sale_stamp']; $sql = "UPDATE mytable SET sale_stamp = :sale_stamp WHERE id = :id"; $stmt=$db->prepare($sql); $stmt->execute(array( ':id' => $id, ':sale_stamp' => $sale_stamp); This works provided there are values entered but some fields may be blank and this fails for numeric fields. The generated sql is UPDATE asset set sale_stamp = '' WHERE id = '17' The table definition allows null, but when I leave the field blank in the table the generated sql has an empty string rather than null. How do I overcome this?
  3. Thanks for the replies, settings in php.ini makes much more sense:) ginerjm - I think I am missing something. I put ph tags around your code to get it to run, but it just reports 'Undefined variable: root' do I need to put something in there? Mick
  4. I have ini_set('display_errors',1); ini_set('display_startup_errors',1); error_reporting(E_ALL); at the start of my code. That picks up some errors but not all. I have just opened a web page and it is completely blank, run it in command line and it tells me PHP Parse error: syntax error, unexpected '}', expecting end of file in /home/pi/v04_0/www/model/index.php on line 17 Easy to fix in this case, but for more involved code it is difficult to track down problems.
  5. When trying to diagnose a problem with php I often run it from command line to see the "unexpected < at line 123" or similar message. This is very useful for simple scripts but if I have includes etc it shows them as an error as the path is different. I have done a bit of research and understand why this happens, but is there a way to overcome this? I don't know of any other way to get anything like a trace of execution. Running PHP Version 7.3.29-1~deb10u1 on Linux Mint 20.2 Thanks
  6. Thank you both for your replies, I now have it working. I have a blank line separating each data line, but that is no big deal. Re your comments ginerjm, I have followed several on-line tutorials to create my code and I must admit I don't understand all of it. I have searched for a good tutorial and not found one which starts from basics and actually explains how it all works, which results in me copying code, using it and hoping for the best. Some of the tutorials conflict with other, which is not helpful. The multiple php calls was from a tutorial which maintained that it was clearer that way, but on balance I think I agree with you. Thanks for your help Mick
  7. I have a form which displays values and allow changes. The "id" field is set to be read only, but I want to set a couple of other fields to read only as well. How can I do that? This is the section of code <form method="post"> <?php foreach ($assetx as $key => $value) : ?> <label for="<?php echo $key; ?>"><?php echo ucfirst($key); ?> <input type="text" name="<?php echo $key; ?>" id="<?php echo $key; ?>" value="<?php echo escape($value); ?>" <?php echo ($key === 'id' ? 'readonly' : null); ?>> </label> <?php endforeach; ?> <input type="submit" name="submit" value="Submit"> </form> Thanks Mick
×
×
  • 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.