Why shouldn't I use mysql_* functions in PHP?
The MySQL extension:
- Is not under active development
- Is officially deprecated as of PHP 5.5 (released June 2013).
- Has been removed entirely as of PHP 7.0 (released December 2015)
- This means that as of 31 Dec 2018 it does not exist in any supported version of PHP. If you are using a version of PHP which supports it, you are using a version which doesn't get security problems fixed.
- Lacks an OO interface
- Doesn't support:
- Non-blocking, asynchronous queries
- Prepared statements or parameterized queries
- Stored procedures
- Multiple Statements
- Transactions
- The "new" password authentication method (on by default in MySQL 5.6; required in 5.7)
- Any of the new functionality in MySQL 5.1 or later
Since it is deprecated, using it makes your code less future proof.
Lack of support for prepared statements is particularly important as they provide a clearer, less error-prone method of escaping and quoting external data than manually escaping it with a separate function call.
See the comparison of SQL extensions.
Cannot Update MYSQL using PHP
You are missing a space after the value of end
also, you will need to wrap your variables with a quotes like the query below.
$sql = "UPDATE usezas ".
"SET start = '$emp_salary', end = '$empd_end' ".
"WHERE field_3 = $emp_id" ;
However, your code is vulnerable to SQL injections. You sure prepare your query and should be using either PDO or MySQLi extensions not the old mysql_query extension.
Why I cannot update the data?
Disabled form elements are not sent to PHP so $this->input->post('id')
will be blank which is why your echo_data image/screenshot does not show the ID. Change the form element to readonly instead of disabled or use $this->input->get('id');
which appears to be present anyway as you use it to get the data initially.
Also it doesn't appear you are handling the uploaded file (images) correctly, please look into that.
Php-MySQL UPDATE & INSERT stopped working after upgrading to MySQL 5.5 from 4.1
condition
is a reserved word http://dev.mysql.com/doc/refman/5.5/en/reserved-words.html which is most likely a/the reason.
Try (using backticks around the word condition
)
`condition`='".add_slashes($_POST['condition'])."',
Plus, if at all possible, try and use another word for the column name.
In past MySQL releases, condition
was not a reserved word at the time which explains why it worked for you back then when you were using 4.1 and have since upgraded to 5.5.
- http://dev.mysql.com/doc/refman/4.1/en/reserved-words.html
condition
became a reserved word as of version 5.0
- http://dev.mysql.com/doc/refman/5.0/en/reserved-words.html
Footnotes:
mysql_*
functions deprecation notice:
http://www.php.net/manual/en/intro.mysql.php
This extension is deprecated as of PHP 5.5.0, and is not recommended for writing new code as it will be removed in the future. Instead, either the mysqli or PDO_MySQL extension should be used. See also the MySQL API Overview for further help while choosing a MySQL API.
These functions allow you to access MySQL database servers. More information about MySQL can be found at » http://www.mysql.com/.
Documentation for MySQL can be found at » http://dev.mysql.com/doc/.
MYSQL Syntax Error on UPDATE with 'Key' word
KEY
is a reserve word in mysql
better put KEY
inside `` back ticks.
Source(link)
PHP update command not working
I am not sure if this is the complete code. But form fields should be included in <form>
tags.
<form method="post" action="">
<fieldset>
<legend><strong>Main Title Information</strong></legend>
<div id="prompt">Client Company Name:</div><div id="answer"><input type="text" name="clientname" id="clientname" value="<? echo $companyname; ?>"/></div>
<div id="prompt">Web Tool Name:</div><div id="answer"><input type="text" name="webtoolname" id="webtoolname" value="<? echo $toolname; ?>"/></div>
<div id="prompt"><input type="submit" id="toolnameupdate" name="toolnameupdate" value="Update Information" /></div><div id="answer"> </div>
<div id="prompt"> </div><div id="answer"> </div>
</fieldset>
</form>
also the correct syntax is $_POST['..'], and not with parenthesis.
and also move error_reporting(E_ALL);
to the top of the file, otherwise it won't be too useful.
Related Topics
How to Use PHP Reserved Names for My Functions and Classes
Understanding Ioc Containers and Dependency Injection
Differencebetween Sessions and Cookies in PHP
Uploading a File in Chunks Using HTML5
When Should I Declare Variables in a PHP Class
Namespace in PHP Codeigniter Framework
How to Set a Cookie and Then Redirect in PHP
Getting Node's Text in PHP Dom
Sending Multiple Attachment in an Email Using PHP
PHP Keep Checkbox Checked After Submitting Form
Autoloading Classes in PHPunit Using Composer and Autoload.Php
What Is the Best Practice to Export Canvas with High Quality Images
Relative Path Not Working in Cron PHP Script