I am looking to update a table column on a form submit using mySQL.
ie.
<form action="<?=$_SERVER['PHP_SELF']; ?>" method="post">
<fieldset>
<div data-role="fieldcontain">
<label for="status" class="select">Current Status:</label>
<select name="status" id="status">
<option value="Open">Open</option>
<option value="Closed">Closed</option>
</select>
</div>
<input type="submit" data-theme="a" name="submit" value="submit-value"></input>
</fieldset>
</form>
<?php
if(isset($_POST['submit'])) {
$query = "UPDATE vtiger_troubletickets SET status='".addslashes($_POST['status'])."' WHERE ticket_no='".$ticket['ticket_no']."'";
echo $query;
mysql_query($query);
}
?>
updated
The query I have in place works in mysql correctly, except on my form submit the database is not updating. I have tried the input and button tag for the 'Submit.' Everything is connected as I have previously tested it all with a connect script. Any ideas as to why this is not updating my columns?
You should have something like this:
<?php
if(isset($_POST['submit'])) {
$query = "UPDATE table_name SET col1='".addslashes($_POST['status'])."' WHERE id=1";
mysql_query($query);
}
?>
Something like this should do the trick. Obviously you need to change the table_name and id nr :).
You should check in this page whether "status" has been sent or not (isset($_POST['status'])), then if it has been sent, just grab the value and execute the query (UPDATE table SET whatever=something WHERE condition)
You can put all your php in a block after an if statement like this:
if(isset($_POST['submit'])){ //Your update goes here }
This makes sure that the form was submited so you don't query the DB on every request. If I understood you correctly here's a little lecture:
Javascript and HTML are client-side scripts, therefore they run in the web browser. PHP is a server-side scripting language and it runs on a server.
Becouse of this Javascript can't directly 'talk' to PHP, so you can't assign a PHP function to a onClick event, but you can use Javascript to make an AJAX request to the server. If you're interested browse the web for it. There are tons of PHP and AJAX tutorials online.