PDA

View Full Version : DWCS4 - Problem with update record behaviour and file field


fandano_fred
04-18-2010, 04:15 AM
In short: I can insert a record into a MySQL database using File Fields in Dreamweaver but I cannot updats that same field using file Field and update behavior..


Been looking for a quick visual fix for this problem for hours on the net and found nothing that really equates to the issue I am having.

- please bear in mind in replyong that I have not done any dynamic dev work or programming for several years and the mind is foggy. Please reply visually as opposed to in code where possible.

Here is The problem - I am using a php/MySQL set up. I have a very simple database structure - in fact this solution uses only one table with 5 fields...

I have an insert record form as follows

Title: [Textbox] - text
Description: [Textbox] - text
Link URL File Field - varChar(100)
Thumb URL File Field - varChar(100)

My problem lies with the file fields and Update record behavoiur in DWCS4

Intilially the insert record does exacly what is expected. The user typeis in the Title and description and browses to the limk and thumb urls. The latter are returned to the database trucnated (ie without the full path info just file.jpg or file.html). I have had to had code the results pages to get the image to display and to create a clickable link... So far so good... I populate the database. The form update takes me to a records page which includes a link to an edit form where all is hunky dory. I discover a record is inaccurate and need to change it.

In the update record page I have the samwe structure as above... have created the record set and the update behaviou having first bound the textboxes and file fields to the relevant form fields..

When I click the edit link from the records page it takes me to this page aand drags in some of the data from the database - ie the values of the textbox variables only but nothing in the file field.

As with the insert record for... I have changed the info for the Title and Description and browsed for the URL files

I click update and find that the data passed from the textboxes has indeed updated but the file fields are now NULL or blank values in the database.

How do I go about provinding the user with a browseable solution that will actually return a value to the database?

I have troubleshooted by replacing one of the file fields with a text box and C&P the file name in there,,, and that updates just fine. Seems to be a broblem just the file field.

Hope someone can help -- I am sure the solution here is quite simple but I have been trying now for some 24 hours and have not been able to solve the riddle...

Thanking you in advance

PS on another note.. Don't know if it is just me but with DWCS4 - particularly is setting up a new site or browsing to a file.. I never get the the full link... and have to type in the file name manually. Or the remote server will just show http:// localhost and not http:// localhost/Sitename despite the fact you clicked on Sitename folder.... Never had these issues when DW was Macromedia!

fandano_fred
04-19-2010, 05:04 PM
'Is there anybody there?' said the Traveller,
Knocking on the moonlit door;
And his horse in the silence champed the grasses
Of the forest's ferny floor.

- when things fo BUMP in the night....

Hope the experts and expert volunteers dont feel the solution to this is too easy for them and might kill a few braincells. I join forums because I need help (dsometimes urgently). I am often a totań Newb in some cases - in others been working for years with an app but have a bug or a quirk that neds ironing out!

This thread was posted intially 3 days ago now and not a hint of a replym making me again question the value of forums.

davidj
04-20-2010, 10:13 AM
Once again

If you post in the correct forum then you may get a responce

I cant be bothered to read your entire post. I switched off after reading...

Update record behavoiur in DWCS4

fandano_fred
04-20-2010, 06:08 PM
Once again

If you post in the correct forum then you may get a responce

I cant be bothered to read your entire post. I switched off after reading...

Would that be Sheesh - as in Sheesh kebab??? Line me up, haven't eaten yet today.

So why did I post here? Because this is a PHP forum and yes, my issue is a php related one and it is coding that is giving the issue. I am not an expert - but I am right! If you had bothered to take a minute you will find that I also posted the query there - a day before I did on this thread.... and no one home there at all either. Not surporising at all that the frequency of queries on this forum is so minimal. Either everyones an expert and don't need help.

As for your Can't be bothered statement.. Not surprising at all, not even in the slightest!!! Totally illustrates my point and the atrtitude of Geeks in need of a tweak or two themselves. I can forget about getting a solution to the problem from folks like yourself who share this kind of attitude!

I guess my whole - 'Nobody home' point has been perfectly made!
Where do I email you? Nobody@noonehome.org

Homesite - www.PHPhelpdeskforum.com?experts=0 (http://www.PHPhelpdeskforum.com?experts=0)

If forums are not intended to be for helping others then what are they all ablout?- a place for geeks to share their pseudo-intellectuality to share their intellectuality? Really should get out more.....

Oh, I'm a geekerjack and I'm okay, I cut down code and I seldom play..
I'm a geekerjack...

BTW what is that bs in your signature tag??

Would you like me to teach you php?

With your attitude?? That's rich, m8.....

davidj
04-20-2010, 07:33 PM
I'm pleased you took time to compose that

another nerve eh

haha

mangofreak
04-20-2010, 07:51 PM
DWCS4 has some PHP tools missing. I'm wondering if the problem is there. Do you have the Missing tools plugin?

In any case, check here: http://www.felixone.it/extensions/freedwextsen.asp

domedia
04-20-2010, 09:15 PM
Please keep it friendly guys.

fandano_fred
04-20-2010, 10:53 PM
DWCS4 has some PHP tools missing. I'm wondering if the problem is there. Do you have the Missing tools plugin?

In any case, check here: http://www.felixone.it/extensions/freedwextsen.asp

Thanks - just goes to prove that not everyone is quite as absent as this davidj character and get the gist of what forums are supposed to be all about. Not sure about these tools but will check it out.

The problem though is not so much about tools but coding.

My form uses 2 file fields which allow the user to browse for a file on the computer and pass that value to MySQL database. This works perfecrtly.

However if the user wants to change this information - againthe idea is that tey will browse for the file and upload it, replacing the earlier string.

With dreamweaver the update record behavior (which is php/mysql) should pass this value back to MySQL and update that field in MySQL... but does not... it returns either a vacant vale (ie greyed out) or a NULL Value.

If anyone feels they can help - or are willing to investigate the problem I will put up an example and upload it here if zip files are allowed. I think tough the problem should be easy enough to understand and investigate without the need to do so. just try an update form in dreamweaver using a file field object on a test database and I am sure you will see what I mean.

Thanks again - at least someone willing to offer some help here is appreciated given what I have had to contend with thus far. Appreciated!

mangofreak
04-20-2010, 11:16 PM
you insert record fine.
you have a list that shows your inserted records.
you want to edit a particular record, but you don't see the info for each field. right?

Title
Description
Link URL
Thumb URL


if that is the issue, have you done the binding of each record to each of your form fields?

and used the behaviour Move to Specific record?

When you want to go to detail page: do you see on values passed the correct id number of the record you want to see?

fandano_fred
04-20-2010, 11:34 PM
you insert record fine.
you have a list that shows your inserted records.
you want to edit a particular record, but you don't see the info for each field. right?

Title
Description
Link URL
Thumb URL


if that is the issue, have you done the binding of each record to each of your form fields?

and used the behaviour Move to Specific record?

When you want to go to detail page: do you see on values passed the correct id number of the record you want to see?

I have bound a dbase text field to the fiel field (although with this object you can not see that visually (noly in split view or code)

We go into an edit record page which shows the value originally inserted using the file field.

We then try to change this value via update record and again using a bound file field object leting the user browse for the replacement file.

However the original record gets overwritten but either with NULL or a blank...

forgot to mention.. yes, the record association is fine as the 2 non url fields that use textboxes as opposed to file fields do update the database as expected

give me 1/2 hor and I will try replicate the problem and provide you with a mySQL table and form...

mangofreak
04-21-2010, 01:45 AM
I re-read your initial post and I didn't realize that your issue was with file field.
Hopefully this will help:

http://www.sebastiansulinski.co.uk/web_design_tutorials/tutorial/19/php_upload_form

:D I just saw your post somewhere else - small world!

Anyhow, the way I saw it done was using ASP, but it was to call the file field info into a text field and have a file filed to give you the option to upload a new file. I think that is what you want.

The short answer is I have never done it myself, I have used ASPUpload for it and PHP upload from DMxZone.

I'll keep checking and see what I find.

fandano_fred
04-21-2010, 01:49 AM
@Mangofreak

I put this together - I think the problem should be evident enough - w small files including the MySqlDump

One only need download - import the MySQL dump of the Dbase and set up a connecton to it as well as copy the files to a live directory for testing. About the simplest I can do it

http://www.sendspace.com/file/otu1nb

fandano_fred
04-21-2010, 01:50 AM
I re-read your initial post and I didn't realize that your issue was with file field.
Hopefully this will help:

http://www.sebastiansulinski.co.uk/web_design_tutorials/tutorial/19/php_upload_form

:D I just saw your post somewhere else - small world!

Anyhow, the way I saw it done was using ASP, but it was to call the file field info into a text field and have a file filed to give you the option to upload a new file. I think that is what you want.

The short answer is I have never done it myself, I have used ASPUpload for it and PHP upload from DMxZone.

I'll keep checking and see what I find.

Lol - looks like our posts just crossed.. a quickie to examine... check the sendspace link..

btw, Nice link... but I forgot to mention I am not trying to upload files to the DB just store the text values as strings (references) I think the upload I made to sendspace will show you exactly what the issue is and what I want to do... Link again is

http://www.sendspace.com/file/otu1nb

mangofreak
04-21-2010, 03:54 AM
OK. If you are trying to just change the text reference, then you have to use a text field and not a file field.

I tested it and there is no problem. Here is the code:


<?php require_once('Connections/castaneda.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}

$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}

function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;

switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . date("Y-d-m",strtotime($theValue)) . "'" : "NULL";
break;
case "time":
$theValue = ($theValue != "") ? "'" . date("H:i:s",strtotime($theValue)) . "'" : "NULL";
break;
case "datetime":
$theValue = ($theValue != "") ? "'" . date("Y-d-m H:i:s",strtotime($theValue)) . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form1")) {
$updateSQL = sprintf("UPDATE books SET thumbnailURL=%s, bookTitle=%s, linkURL=%s WHERE bookID=%s",
GetSQLValueString($_POST['thumbURL'], "text"),
GetSQLValueString($_POST['bookTitle'], "text"),
GetSQLValueString($_POST['linkURL'], "text"),
GetSQLValueString($_POST['recordID'], "int"));

mysql_select_db($database_castaneda, $castaneda);
$Result1 = mysql_query($updateSQL, $castaneda) or die(mysql_error());

$updateGoTo = "books.php";
if (isset($_SERVER['QUERY_STRING'])) {
$updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
$updateGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $updateGoTo));
}

$colname_rsBooks = "-1";
if (isset($_GET['recordID'])) {
$colname_rsBooks = $_GET['recordID'];
}
mysql_select_db($database_castaneda, $castaneda);
$query_rsBooks = sprintf("SELECT * FROM books WHERE bookID = %s", GetSQLValueString($colname_rsBooks, "int"));
$rsBooks = mysql_query($query_rsBooks, $castaneda) or die(mysql_error());
$row_rsBooks = mysql_fetch_assoc($rsBooks);
$totalRows_rsBooks = mysql_num_rows($rsBooks);

$colname_rsBooks = "-1";
if (isset($_GET['recordID'])) {
$colname_rsBooks = $_GET['recordID'];
}
mysql_select_db($database_castaneda, $castaneda);
$query_rsBooks = sprintf("SELECT * FROM books WHERE bookID = %s", GetSQLValueString($colname_rsBooks, "int"));
$rsBooks = mysql_query($query_rsBooks, $castaneda) or die(mysql_error());
$row_rsBooks = mysql_fetch_assoc($rsBooks);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style type="text/css">
<!--
#container {
position: absolute;
height: 600px;
width: 600px;
left: 0px;
top: 0px;
}
-->
</style>
</head>

<body>
<div id="container">
<form action="<?php echo $editFormAction; ?>" method="POST" enctype="multipart/form-data" name="form1" id="form1">
<table width="450" border="0" cellpadding="2" cellspacing="2">
<tr>
<td width="283">Thumbnail</td>
<td width="33">&nbsp;</td>
<td width="274"><input name="thumbURL" type="text" id="thumbURL" value="<?php echo $row_rsBooks['thumbnailURL']; ?>" /></td>
</tr>
<tr>
<td>Book Name</td>
<td>&nbsp;</td>
<td><label>
<input name="bookTitle" type="text" id="bookTitle" value="<?php echo $row_rsBooks['bookTitle']; ?>" />
</label></td>
</tr>
<tr>
<td>Book Description</td>
<td>&nbsp;</td>
<td><label>
<textarea name="textarea" id="textarea" cols="45" rows="5"><?php echo $row_rsBooks['bookTitle']; ?></textarea>
</label></td>
</tr>
<tr>
<td>Link to book</td>
<td>&nbsp;</td>
<td><input name="linkURL" type="text" id="linkURL" value="<?php echo $row_rsBooks['linkURL']; ?>" /></td>
</tr>
<tr>
<td><input name="recordID" type="hidden" id="recordID" value="<?php echo $row_rsBooks['bookID']; ?>" /></td>
<td>&nbsp;</td>
<td><label>
<input type="submit" name="update" id="update" value="Update" />
</label></td>
</tr>
</table>
<input type="hidden" name="MM_update" value="form1" />
</form>
</div>
</body>
</html>
<?php
mysql_free_result($rsBooks);
?>



Late here... feeling sleepy. Cheers.

fandano_fred
04-21-2010, 04:54 AM
I will definitely need the file field - the user will need to browse to a file and the text will need to be extracted and passed to the db in the same way as it is in the input form.

The reason being is that I cannot assume the user will know where to look for files or what they need to type into a text field (I have alreadsy been using the text fields for the time being myself since logically text fields work, but this does not solve the problem)

Have you tried to use the file field to update the records???? you should find blanks in the db for both the URLS... that my friend, is the problem.

In the input form I can use the file browser to input the records - the db updates. However if I want to change the record using the same method I cannot... can't see why not...

Thanks for looking at this,,, much appreciated...

I did have a quick look at your adjustments.. you are exactly where I am right now... not the solution I am afraid....

mangofreak
04-21-2010, 02:44 PM
Too bad! I thought the problem was solved.

I know that you should have something like this:


<form action="<?php echo $editFormAction; ?>" method="POST" enctype="multipart/form-data" name="form1" id="form1">
<table width="450" border="0" cellpadding="2" cellspacing="2">
<tr>
<td width="283">Thumbnail</td>
<td width="33">&nbsp;</td>
<td width="274"><p><?php echo $row_rsBooks['thumbnailURL']; ?><br />
</p></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td><input type="file" name="thumbURL" id="thumbURL" /></td>
</tr>
<tr>
<td>Book Name</td>
<td>&nbsp;</td>
<td><label>
<input name="bookTitle" type="text" id="bookTitle" value="<?php echo $row_rsBooks['bookTitle']; ?>" />
</label></td>
</tr>
<tr>
<td>Book Description</td>
<td>&nbsp;</td>
<td><label>
<textarea name="textarea" id="textarea" cols="45" rows="5"><?php echo $row_rsBooks['bookTitle']; ?></textarea>
</label></td>
</tr>
<tr>
<td>Link to book</td>
<td>&nbsp;</td>
<td><p><?php echo $row_rsBooks['linkURL']; ?></p></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td><input type="file" name="linkURL" id="linkURL" /></td>
</tr>
<tr>
<td><input name="recordID" type="hidden" id="recordID" value="<?php echo $row_rsBooks['bookID']; ?>" /></td>
<td>&nbsp;</td>
<td><label>
<input type="submit" name="update" id="update" value="Update" />
</label></td>
</tr>
</table>
<input type="hidden" name="MM_update" value="form1" />
</form>



I don't know how to accomplish that on the code side. An idea would be to have a div with a list and thumbs of your images to guide the user and if they need that info applied, via javascript they could just click the filename an automatically fill the field, then you could do your update.

I had something like that using ASP long time ago.

I imagine that you could figure out a way to use the upload file code conditionally in addition to your update function. As far as I can understand you want to be able to re-upload another file if the current file is not correct, right?

I was looking at the same issue and have been toying with the idea to go with a form of file management script, usually those are commercial. I like TinyMCE and the range of products they have.

Perhaps is more time and economically viable.

sorry man. good luck.

fandano_fred
04-21-2010, 04:59 PM
No problem - thanks again... I don't know if it is a bug or what... because (as you can see) the file field works perfectly with insert record coe, but just doesn't seem to lime the update code at all... MySQL sees the file field as an apple in input behaviour but clearly sees it as something other than an apple in the update behaviour... I suspect it has to be a php problem since the data is the same... I don't know enough about php or have the confidence with it or I'd check out the API to see what kind of methods are attached to the update methods anf behaviours