/    Sign up×
Community /Pin to ProfileBookmark

Anyone, how to make this work – no resuts evident

[code=php]<?php
error_reporting(E_ALL ^ E_NOTICE);
// error_reporting(0);

if(isset($_POST[‘update’]))
{
$dbhost = ‘localhost’;
$dbuser = ‘root’;
$dbpass = ‘cookie’;
$conn = mysql_connect($dbhost, $dbuser, $dbpass);

if(! $conn ) { die(‘Could not connect: ‘ . mysql_error()); }

$id = $_POST[‘id’];
$taxrate = $_POST[‘taxrate’];
$sql = “UPDATE numbers “.
“SET taxrate = $taxrate “.
“WHERE id = $id” ;
mysql_select_db(‘homedb’);
$retval = mysql_query( $sql, $conn );

if(! $retval ) { die(‘Could not update data: ‘ . mysql_error()); }

echo “Updated data successfullyn”;
mysql_close($conn);
}
// else
// {
?> [/code]

to post a comment
PHP

6 Comments(s)

Copy linkTweet thisAlerts:
@ginerjmMay 05.2014 — turn on display errors and see what syntax errors you (may?) have.
Copy linkTweet thisAlerts:
@ShrineDesignsMay 05.2014 — give this a try[code=php]$sql = "UPDATE numbers SET taxrate = '$taxrate' WHERE id = '$id'";[/code]
Copy linkTweet thisAlerts:
@ginerjmMay 05.2014 — Only need quotes on values if they are type string.

OP - try this version of your code. A little cleanup and some adds to show errors and see what's happening.

[code=php]
error_reporting(E_ALL ^ E_NOTICE);
// echo error messages to the screen during devl.
ini_set('display_errors', '1');

if(isset($_POST['update']))
{
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = 'cookie';
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
if(!$conn )
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db('homedb');
$id = $_POST['id'];
$taxrate = $_POST['taxrate'];
$sql = "UPDATE numbers SET taxrate = $taxrate WHERE id = $id";
$retval = mysql_query( $sql, $conn );
if(! $retval )
{
die('Could not update data: ' . mysql_error());
}
echo "Updated data successfullyn";
mysql_close($conn);
}
else
{
echo "The POST update item does not exist.";
exit();
}
[/code]
Copy linkTweet thisAlerts:
@NogDogMay 05.2014 — Only need quotes on values if they are type string....
[/QUOTE]


Yet another reason I like using PDO with prepared statements/bound parameters, so I don't have to worry about that. ?
Copy linkTweet thisAlerts:
@funeduMay 09.2014 — fallow the steps for updating value in database .

1 open php tag

2-database connection

3-take value through get or post method like "$_POST['taxrate'];"

4-use query "UPDATE numbers SET taxrate = '$taxrate' WHERE id = '$id'"; "

5-close connection and php tag.
Copy linkTweet thisAlerts:
@12StringsauthorMay 20.2014 — solved
×

Success!

Help @12Strings spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...