Jump to content

Will not insert into DB


smithmr8

Recommended Posts

Hello,

The below code is not inserting items into the database. As far as I can see, its all correct in terms of attribute names and such...

 

<html>
<head>
<title>ITSS: Respond to a ticket</title>
<style type="text/css" media="all">@import "css/style.css";</style>
<script type="text/javascript" src="checkRespond.js"></script>
</head>
<body onLoad="return checkRespond();">
<?php
if($_GET['step'] == 'do'){
$ticketid = $_POST['ticketid'];
$subject = $_POST['subject'];
$message = nl2br($_POST['message']);
$ufile = $_POST['ufile'];
$userid = $x['ID'];

mysql_query("INSERT INTO `response` (`ticket_id`, `user_id`, `subject`, `message`) VALUES ('$ticketid', '$userid', '$subject', '$message')");
echo "Your response was submitted successfully!<br>";
echo $ticketid."<br>";
echo $subject."<br>";
echo $message."<br>";
echo $ufile."<br>";



if ($ufile == ""){
echo "No attachment uploaded<br>";
} else {
$file_name = $HTTP_POST_FILES['ufile']['name'];
$numatt = mysql_query("SELECT * FROM `attachment` WHERE `ticket_id` = '$ticketid'");
$totalatt = mysql_num_rows($numatt);
$totalatts = $totalatt + 1;
$extension = strip_ext($file_name);
        $newname = "Ticket".$ticketid."-Attachment".$totalatts."".$extension;
       
        
        
$path= "upload/".$HTTP_POST_FILES['ufile']['name'];
$pathnew = "upload/".$newname;
if(copy($HTTP_POST_FILES['ufile']['tmp_name'], $pathnew)){

$file_name = $HTTP_POST_FILES['ufile']['name'];
$file_size = $HTTP_POST_FILES['ufile']['size'];
$file_type = $HTTP_POST_FILES['ufile']['type'];
$file_location = $path;



        rename('$HTTP_POST_FILES[tmp_name]', '/public_html/support/upload/$newname');
                
mysql_query("INSERT INTO `attachment` (`user_id`, `ticket_id`, `file_type`, `file_location`, `file_size`, `file_name`) VALUES ('$x[iD]', '$ticketid', '$file_type', '$pathnew', '$file_size', '$newname')");
echo "Your attachment has been uploaded!<br>";
echo $newname;
}
}

} elseif ($_GET['id']) {
$ticket = $_GET['id'];
?>

<div class="respondform">
  <h1>Respond to a Ticket</h1>
  
Fill in the below form with the appropriate information to respond to <b>Ticket <? echo $ticket; ?></b><br /><br />
<form onSubmit="return checkRespond();"  method="POST" action="respondticket.php?step=do" enctype="multipart/form-data" name="form1" id="form1">
<input type="hidden" id="ticketid" name="ticketid" value="<? echo $ticket; ?>"> 
<table>
<tr> 
<td width="150"><b>Subject</b></td>
<td width="200"><input method="text" onChange="return checkRespond();"  type="text" size="20" name="subject" id="subject" value=""></td>
<td width="200"><div class="error" id="subjectError">Subject Required</div><div class="noerror" id="subjectNoError">Subject Complete</div></td>
</tr>
<tr>
<td width="150"><b>Attachment</b></td>
<td colspan="2"><input name="ufile" type="file" id="ufile" size="40"/></td>
</tr>
<tr> 
<td width="150"><b>Message</b></td>
<td width="200"></td>
<td width="200"><div class="error" id="messageError">Message Required</div><div class="noerror" id="messageNoError">Message Complete</div></td>
</tr>
<tr>
<td colspan=3><textarea cols=60 onChange="return checkRespond();" rows=5 name="message" id="message" value="" type="text"></textarea></td>
</tr>
<tr>
<td width="150"><input type="submit" value="Submit Response" id="submit" name="submit" disabled="true"></td>

</tr>

</table>
</form>
</div>
<?
}

?>
</body>
</html>

Link to comment
https://forums.phpfreaks.com/topic/148065-will-not-insert-into-db/
Share on other sites

Hi

 

Presume that is a part of the script. There is nothing set to the array $x[], so nothing put into the $userid field.

 

Are you really sending data to the script by both GET and POST methods? As your first insert will only happen if $_GET['step'] is "do" but inserts various $_POST fields.

 

All the best

 

Keith

I had that on the end of it, and it did say there was an error with the query. I just can't figure out what it is.

 

You've reminded me of what the problem is with it. I'm not connecting to the DB, as well as supply the ID information. Forgot to put it into this as its a pop-up.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.