HI there,
I had a similar problem yesterday with my delete function. All looks ok, yet doesn't delete. I've tried adding the '$_GET' to the sql query, without any success. Is this perhaps a problem with the file uploads? The row ID is definately being posted correctly. -
-
<?
-
include("connect.php");
-
-
if(isset($_POST['Submit']) && $_POST['Submit'] == "Submit")
-
{
-
$fileName = $_FILES['userfile']['name'];
-
$tmpName = $_FILES['userfile']['tmp_name'];
-
$fileSize = $_FILES['userfile']['size'];
-
$fileType = $_FILES['userfile']['type'];
-
-
$fp = fopen($tmpName, 'r');
-
$content = fread($fp, filesize($tmpName));
-
$content = addslashes($content);
-
fclose($fp);
-
-
if(!get_magic_quotes_gpc())
-
{
-
$fileName = addslashes($fileName);
-
}
-
-
-
$resourceName = $_FILES['resource']['name'];
-
$tmpName = $_FILES['resource']['tmp_name'];
-
$resourceSize = $_FILES['resource']['size'];
-
$resourceType = $_FILES['resource']['type'];
-
-
$fp = fopen($tmpName, 'r');
-
$resourceContent = fread($fp, filesize($tmpName));
-
$resourceContent = addslashes($resourceContent);
-
fclose($fp);
-
-
if(!get_magic_quotes_gpc())
-
{
-
$resourceName = addslashes($resourceName);
-
}
-
-
$tutorialNumber = $_POST['tutorialNumber'];
-
$tutorialTitle = $_POST['tutorialTitle'];
-
$tutorialDescription = $_POST['tutorialDescription'];
-
$tutorialContent = $_POST['tutorialContent'];
-
-
-
mysql_query("UPDATE tutorials SET tutorialTitle='$tutorialTitle', tutorialDescription='$tutorialDescription', tutorialContent='$tutorialContent', name='$fileName', size=$filesize, type='$filetype, content='$content', resourceName='$resourceName', resourceSize=$resourceSize, resourceType='$resourceType, resourceContent='$resourceContent' WHERE tutorialNumber = '$tutorialNumber'");
-
-
-
echo "<span class='titles'>Edit Complete!</span><br><br>";
-
}
-
// ************* End update part *************
-
-
-
$tutorialNumber=$_GET['tutorialNumber'];
-
-
$result=mysql_query("select * from tutorials where tutorialNumber='$tutorialNumber'");
-
or die ('Error querying database.');
-
$row=mysql_fetch_assoc($result);
-
-
mysql_close();
-
?>
-
-
Many thanks
9 2631
Just out of interest, if the file upload field is left blank in this UPDATE form, will it over write the file that was originally posted in the database?
If so, is there a reasonably simple way around this?
code green 1,726
Recognized Expert Top Contributor
Anybody got any ideas?
I have really no idea what your problem is.
All looks ok, yet doesn't delete
I cannot see a DELETE query
I've tried adding the '$_GET' to the sql query
Please explain how you use $_GET in SQL
Is this perhaps a problem with the file uploads?
Could be. But without any error trapping or debugging in your code it is impossible to know what is happening.
You need about half a dozen more 'if' statements in your code
Thanks for the reply,
Sorry I meant UPDATE, not DELETE.
You'll have to forgive me, I'm a complete novice. I've used $_GET in the following way before... -
-
$query = ("DELETE FROM tutorials WHERE tutorialNumber = '".$_GET["id"]."' LIMIT 1");
-
-
I just thought I might be able to use a similar query with the problem above. Evidently not.
code green 1,726
Recognized Expert Top Contributor
You should avoid the habit of using data straight from a form into a query.
Read about "SQL Injection".
Although it works so that is not the problem.
I suspect a problem with the file hence my suggestion for more testing.
By that I mean at least - if($fp = fopen($tmpName, 'r')){
-
if($content = fread($fp, filesize($tmpName))){
-
echo $content;
-
$content = addslashes($content);
-
if(!fclose($fp))
-
echo 'Could not close file';
-
}
-
else echo 'Could not read file';
-
}
-
else 'Could not open file';
-
This won't 'make it work' but it will help debug
I've basically boiled it down to this. I've stripped out any mention of images uploads etc and still it doesn't work.
What am I doing wrong with the "or die" command? Not even that is working. -
-
<?
-
-
include("connect.php");
-
if(isset($_POST['Submit']) && $_POST['Submit'] == "Submit")
-
{
-
$courseID=$_POST['courseID'];
-
$courseTitle = $_POST['courseTitle'];
-
-
$str = "UPDATE course SET courseTitle='{$courseTitle}' WHERE courseID='{$courseID}'";
-
mysql_query($str) or die("Query failed:<br>".mysql_error());
-
echo "<span class='titles'>Edit Complete!</span><br><br>";
-
}
-
?>
-
-
<?
-
include("connect.php");
-
$courseID=$_GET['courseID'];
-
$result=mysql_query("select * from course where courseID='$courseID'");
-
$row=mysql_fetch_assoc($result);
-
?>
-
-
-
<form action="process_edit_course.php" method="post" enctype="multipart/form-data">
-
<input type="hidden" name="courseID" value="<?php echo $row['courseID']; ?>">
-
<TABLE width="100%" cellpadding="0" cellspacing="10" bgcolor="#FFFFFF" class="border">
-
<br>
-
<TR valign="top">
-
<TD width="388"><span class="bodytext">Course Title: </span></TD>
-
</TR>
-
<TR valign="top">
-
<TD width="388"><input name='courseTitle' type='text' class="border" id="courseTitle" value="<? echo $row['courseTitle']; ?>" size="45" /></TD>
-
</TR>
-
<TR valign="top">
-
<TD><input type="submit" name="submit" value="Add Course to Libary" /></TD>
-
</TR>
-
</TABLE>
-
</form>
-
-
code green 1,726
Recognized Expert Top Contributor
Rather than the 'or die' command I prefer to handle the error cleanly and continue.
However, you must remember that 'or die' will only action if your function returns false, which is basically an error.
So if the query executes without an error but does nothing then you will not know, because your code still lacks if statements. - print_r($_POST);
-
if(isset($_POST['Submit']) && $_POST['Submit'] == "Submit")
-
{
-
$courseID=$_POST['courseID'];
-
if(!isset($_POST['courseID']))
-
echo 'No courseID';
-
echo $courseID;
-
$courseTitle = $_POST['courseTitle'];
-
echo $courseTitle ;
-
-
$str = "UPDATE course SET courseTitle='{$courseTitle}' WHERE courseID='{$courseID}'";
-
echo $str;
-
$res = mysql_query($str) or die("Query failed:<br>".mysql_error());
-
echo $res
-
echo "<span class='titles'>Edit Complete!</span><br><br>";
-
}
-
else echo 'Form not submitted';
-
Basically you are not helping by working blind;
Thankss for your help - I appreciate the tips.
code green 1,726
Recognized Expert Top Contributor
No problem. Once you can see what is happening it is much easier to pinpoint the fault.
If you can't then post back.
EDIT: By the way, I forgot to include make use of - mysql_num_rows()
-
mysql_rows_affected()
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: David Stockwell |
last post by:
Hi,
I'd like to read the contents of a file into memory. The problem is that
this file is binary. I then want to store the whole thing in memory to a
database as a blob.
I have no problem...
|
by: Justin Case |
last post by:
I have a Perl app that stores pictures in a blob. Now I want to load a
thumbnail version of the picture into another blob column, but the update
fails with a syntax error. I'm able to insert the...
|
by: Philip Boonzaaier |
last post by:
I want to be able to generate SQL statements that will go through a list of
data, effectively row by row, enquire on the database if this exists in the
selected table- If it exists, then the colums...
|
by: Howard Lowndes |
last post by:
My situation is that I am interacting PHP 4.1.2 to PostgreSQL 7.2.2
I have no difficulty inserting and managing BLOBs into the Large Object
system table, and I have a user table called images...
|
by: John Baker |
last post by:
Hi:
I have two tables, a setup table (TblSetup) and a purchase order table (tblPO).
When i construct a query with ONLY the tblPO shown, and a type in parameter for the PO
number, I an update...
| |
by: Louis LeBlanc |
last post by:
Hey folks. I'm new to the list, and not quite what you'd call a DB
Guru, so please be patient with me. I'm afraid the lead up here is a
bit verbose . . .
I am working on an application that...
|
by: Jerry LeVan |
last post by:
Hi,
I am just getting into large objects and bytea "stuff".
I created a small db called pictures and loaded some large
objects and then tried to do a restore.
Here is how I got the dump.
...
|
by: Ian Davies |
last post by:
Hello
I have seen some tutorials to put a update a counter field in a record. I
have the counter field in a table that also has a field for a path to file.
I display the records in a table on...
|
by: tofu.captain |
last post by:
I have PDFs saved in a SQL 2005 server as BLOBs. I would like to
extract the BLOBs and either:
1. create a PDF file on the hard disk
or
2. open/stream the PDF into the application
I am...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| |