Click here to Skip to main content
15,889,335 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hey Guys I am trying to create Update Mysql command but it is not working can you tell me what i did wrong?

This is how it looks when place GEt one form
tickettitle=sssss&
issuedetails=ssssssssssss&
privatenotes=sssssssssss&
status=1&
uploadfile=image.jpg&
save=&
category=1&
subcat=1&
option=1&
priority=1&
companyname=2&
compid=112224&
trackid=CS20220202-67&
assign=1&
calername=&
caleremail=&
calernumber=%2B38766520452#


What I have tried:

<?php
 if (isset($_POST["save"])){

   if (($_POST["status"]==1)){
      $tickettitle= $_POST["tickettitle"];
      $issuedetails=$_POST["issuedetails"];
      $privatenotes=$_POST["privatenotes"];
      $priority= $_POST["priority"];     
      $category= $_POST["category"];
      $subcat=$_POST["subcat"];
      $option=$_POST["option"];
      $status= $_POST["status"];
      $companyname=$_POST["companyname"];
      $compid=$_POST["compid"];
      $calername= $_POST["calername"];
      $caleremail=$_POST["caleremail"];
      $calernumber=$_POST["calernumber"];
      $asign=$_POST["assign"];
   
      $ran_id = rand(time(), 100000000);
      $time = time();
      $date=date('Ymd');
      $cs="CS";
      $dubleo="-";
      $traid = $cs.$date.$dubleo.$tid;
      $date2=date('Y-m-d H:i:s');
    
      if(isset($_FILES['uploadfile'])){
   $img_name = $_FILES['uploadfile']['name'];
   $img_type = $_FILES['uploadfile']['type'];
   $tmp_name = $_FILES['uploadfile']['tmp_name'];
   $img_explode = explode('.',$img_name);
   $img_ext = end($img_explode);
   $extensions = ["jpeg", "png", "jpg", "PNG"];
   if(in_array($img_ext, $extensions) === true){
       $types = ["image/jpeg", "image/jpg", "image/png", "image/PNG"];
       if(in_array($img_type, $types) === true){
           $time = time();
           $new_img_name = $time.$img_name;
           if(move_uploaded_file($tmp_name,"../php/images/".$new_img_name)){

  
   $sql="UPDATE tickets SET  calername='$calername', caleremail='$caleremail', category='$category',priority='$priority',tickettitle='$tickettitle',
   issuedetails='$issuedetails',message_html='$issuedetails',lastchange='$date2',firstreply='$date2',privatenotes='$privatenotes',ip='$ip',status='$status',
   openedby='$flname',firstreplyby='$flname',`closedby`='$flname',assignto='$asign',assignedby='$flname',lastreplier='$flname',`archive`='$new_img_name',attachments='$new_img_name',
   subcat=' $subcat',issue='$option',companyname='$companyname',compid='$compid' WHERE	trackid='$traid' ";
   mysqli_query($dbc, $sql);
   header("Location: knwo.php");
   exit();
}
}
   }
}
 }
}

   ?>
Posted
Updated 3-Feb-22 20:47pm
v2
Comments
Dave Kreskowiak 2-Feb-22 16:12pm    
"Not working" is the most common problem description and it's equally useless.

What error messages do you get? What isn't working? What do you expect this code to do and what isn't it doing?
Member 13084733 2-Feb-22 16:14pm    
I am not getting any message and I am trying to update trackid and when I click save button it is not updating table
Richard Deeming 3-Feb-22 4:33am    
Your code is vulnerable to SQL Injection[^]. NEVER use string concatenation/interpolation to build a SQL query. ALWAYS use a parameterized query.
PHP: SQL Injection - Manual[^]
PHP: Prepared statements and stored procedures - Manual[^]

Your UPDATE SQL seems to have problems. Please check the following fields.

`closedby`='$flname',
`archive`='$new_img_name'

should be
closedby='$flname',
archive='$new_img_name'


Secondly you need to use parameterization to avoid SQL injection attacks.

Last but not least one way to isolate the problem is to reduce the scope of update till it gets success and then gradually increase update scope. What I mean here is comment out all updates except one and check if it gets success. If it does success then remove commented columns update one by one and you will find the field that was failing the update.

Hopefully this should solve your problem
 
Share this answer
 
Comments
Member 13084733 5-Feb-22 17:28pm    
Hello still fighting with this I found out that update is working without image part
Hmm.

1. What is $tid? $dbc?

2. Inspect the value of $traid !

3. An ID field (such as $traid) should be just that, and not contain meaningful information such as a date.

4. system calls always have an error mechanism. Your code does not care about the return value of PHP: mysqli::query - Manual[^]. Read how it is done.

5. BTW: you should always use parameterized queries for safety and robustness.
 
Share this answer
 
Comments
Member 13084733 2-Feb-22 17:33pm    
$findid = mysqli_query($dbc, "SELECT id FROM tickets ORDER BY id DESC LIMIT 1 ");
if($findedid = mysqli_fetch_array($findid))
{
$dbc= mysqli_connect($dbHost, $dbUsername, $dbPassword, $dbName);
$tid = $findedid['id'];
$date=date('Ymd');
$cs="CS";
$dubleo="-";
$traid = $cs.$date.$dubleo.$tid;
}
?>
Member 13084733 2-Feb-22 17:34pm    
$dbc= mysqli_connect($dbHost, $dbUsername, $dbPassword, $dbName);

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900