PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, February 2, 2022

[FIXED] Php isn't updating my database

 February 02, 2022     html, mysql, php, phpmyadmin     No comments   

Issue

I am building a website which contains reports to publish and update, I have the following codes which after surfing the web and checking for solutions no help at all.

After selecting the reference number this page grabs the content from the database and echo it in text area for the user to update them. Here is a sample:

second page:

<form method="post"  action="./../php/updated_preview_report.php">
ending:
<textarea id="endings" name="endings"  placeholder="ending" > <?php echo $endings; ?></textarea> 
<input type="submit" name="preview" value="ending" />
</form>

the updated_preview_report.phppage:

<?php
include 'connectionfile.php' ;

$ref= mysql_real_escape_string($_POST['ref']);
$titl= mysql_real_escape_string($_POST['titles']);
$kind= $_POST['kindy'];
$subjec= mysql_real_escape_string($_POST['subjects']);
$caus= mysql_real_escape_string($_POST['causes']);
$solutio= mysql_real_escape_string($_POST['solutions']);
$penalt= mysql_real_escape_string($_POST['penaltys']);
$not= mysql_real_escape_string($_POST['notes']);
$endin= mysql_real_escape_string($_POST['endings']);
session_start();

$sql = "UPDATE report SET title = '$titl', type = '$kind', subject = '$subjec', cause = '$caus', solution = '$solutio', penalty = '$penalt' , note = '$not', ending = '$endin'  WHERE reference = $ref";

$result = mysqli_query($con, $sql);

?>

When i echo any of the updated values such as $title for example, it does show the updated value

Note that no error was reported/shown.

So why isn't this query updating my database?

My knowledge in web development is poor, so easy on me and thank you in advance!


Solution

You need to escape the variable you're using, and use the concat . operator in order to string together the query.

e.g. something like

$str = "SELECT " . $var1 . " FROM " . $var2;

So this

$sql = "UPDATE report SET title = '$titl', type = '$kind', subject = '$subjec', cause = '$caus', solution = '$solutio', penalty = '$penalt' , note = '$not', ending = '$endin'  WHERE reference = $ref";

becomes this

$sql = "UPDATE report SET title = '" . $titl . "', type = '" . $kind . "', subject = '" . $subjec. "', cause = '" . $caus . "', solution = '" . $solutio . "', penalty = '" . $penalt . "' , note = '" . $not . "', ending = '" . $endin . "'  WHERE reference = '" . $ref . "'";

You're not getting errors because UPDATE report SET title = '$titl', type = '$kind', subject = '$subjec', cause = '$caus', solution = '$solutio', penalty = '$penalt' , note = '$not', ending = '$endin' WHERE reference = $ref is valid syntax.



Answered By - UnstableEagle
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home
View mobile version

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing