CodeLobster IDE

Free cross-platform PHP IDE (HTML, PHP, CSS, JavaScript code editor) with support Drupal, Joomla, Twig, JQuery, BackboneJS, LaravelJS, Node.js, Fhalcon, CodeIgniter, CakePHP, Laravel, Magento, MeteorJS, Phalcon, Symfony, VueJS, WordPress, Yii
It is currently Wed Aug 12, 2020 12:09 am

All times are UTC




Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: need help updating database
PostPosted: Wed Mar 18, 2020 3:05 am 
Offline

Joined: Tue Jun 16, 2015 1:03 am
Posts: 14
I'm trying to update a couple of rows in a database using the form below and the php following:

the form:
<!DOCTYPE html><html lang="en">
<head>
<meta charset="UTF-8">
<title>update Record Form</title>
</head>
<body><center>
<font size=+2><b> update visits & lastused information database</font><br>
<form action="crud-update.php" method="post">
<p><label for="target">target:</label>
<input type="text" name="target" id="target"></p>
<input type="submit" name="submit" value="Submit">
</form></body></html>
--------------------------------------------------------------------------------------------
crud-update.php code:
<?php
require 'homedb-connect.php';
$target = $_POST["target"];
$visits = visits;
$Lastused = Lastused;
$sql = "UPDATE receiptno SET visits=visits+1, lastused=NOW() WHERE target=$target";
if ($conn->query($sql) === TRUE) { echo "Record updated successfully"; }
else
{ echo "Error updating record: " . $conn->error; }
$conn->close();
?>
-----------------------------------------------------------------------------------------------
This is result. what's wrong?


Top
 Profile  
 
 Post subject: Re: need help updating database
PostPosted: Tue Mar 24, 2020 2:29 pm 
Offline
Site Admin

Joined: Wed Sep 12, 2007 2:18 pm
Posts: 3559
Hi.

Please, try to add quotes to $target

Code:
$sql = "UPDATE receiptno SET visits=visits+1, lastused=NOW() WHERE target='".$target."'";


Regards,
Codelobster Team.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 18 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2016 phpBB Group