I am trying to create a successful update, using the following HTML:
<form id="form2" name="form2" method="post"
onsubmit="return validateForm();" action="">
Id <input type="text" class="txt" name="id" />
<br />
Name <input type="text" class="txt" name="name" />
<br />
Website <input type="text" class="txt" name="website" />
<br />
Description <input type="text" class="txt" name="description" />
<br />
<input type="submit" id="submit" value="Submit"/>
</form>
I then use the following PHP to read the value and update my database:
<?php
global $wpdb;
if (isset($_GET['id']) && !empty($_GET['id']) &&
isset($_POST['name']) && !empty($_POST['name']) &&
isset($_POST['website']) && !empty($_POST['website']) &&
isset($_POST['description']) && !empty($_POST['description']))
{
$wpdb->query("update where id = $_GET['id'] ".PRO_TABLE_PREFIX
."tutorial (name, website, description) "
."values('{$_POST['name']}', '{$_POST['website']}', '{$_POST['description']}')");
}
?>
What am I doing wrong?
Please note that your form method is post
and you are trying to fetch data using get method
isset ( $_GET['id'] ) && ! empty ( $_GET['id'] )
replace these with $_POST[‘key_name];
to get proper results.
use this your update query is not correct syntax
If you want the ID to be in $_GET[‘id’], then form action should be like this
Also, you have to create a textbox to input id and the for the form should be changed according to the input there, using jQuery or Javascript.
Finally, if this is too complicated, change $_GET[‘id’] to $_POS[‘id’] as the others suggested.
Also, the SQL query is incorrect. Others have already pointed it out.
Try with POST id
2 Things.
1) Since your form method is POST, you would have to use
$_POST['id']
.2) Inside your query string, your mysql
UPDATE
syntax as wrong as well as to use an array with key inside a string, you have to wrap it in{
and}
tags. This should work: