//<?php
// faqs_save
// extract configuration settings for local use
extract($cfg);
// define the $fields variable as an array
$fields=array();
// extract the form data fields using getFormVars
$fields = $etomite->getFormVars($method="POST",$prefix,$trim=1,$REQUEST_METHOD);
// adjust our display setting to be a boolean value
$fields['active'] = $fields['active'] ? 1 : 0;
// extract the form file fields using getFormVars
$files = $etomite->getFormVars($method="FILES",$prefix,$trim=1,$REQUEST_METHOD);
// if a new image file is being uploaded, and filesize > 0, let's store the new filename reference
$fields['image'] = ($files['imageFile']['size'] > 0) ? $files['imageFile']['name'] : $fields['image'];
// insert/update record based on existence of primary key
if($fields['faqsid']!="") {
// edited record so uspate using updIntTableRows()
$rs = $etomite->updIntTableRows($fields, $table, $where="faqsid=".$fields['faqsid'], $sort="", $dir="ASC", $limit="");
} else {
// new record so save using putIntTableRow()
$rs = $etomite->putIntTableRow($fields,$table);
}
// move uploaded image image to destination
$uploadfile = $imagesPath.$fields['image'];
move_uploaded_file($files['imageFile']['tmp_name'], $uploadfile);
// return to caller
echo "<script type='text/javascript'>location.href='$actionURL'</script>";
Saving Data To The Db With ' In
Started by Dean, Apr 15 2006 11:46 AM
2 replies to this topic
#1
Posted 15 April 2006 - 11:46 AM
Hi Guys, I have a snippet that has some field entry stuff in... but when I use ' in them, it won't write to the DB - whereas if I put a \ before it, it will (addslashes) ... I can't for the life of me figure where the addslashes stuff needs to go - can anyone help?
#2
Posted 15 April 2006 - 01:14 PM
I'm not entirely sure what you're trying to do, but my guess would be to apply it to each of the text fields in the $fields array immediately after you've retrieved the array:
something like
something like
... // extract the form data fields using getFormVars $fields = $etomite->getFormVars($method="POST",$prefix,$trim=1,$REQUEST_METHOD); // adjust our display setting to be a boolean value $fields['active'] = $fields['active'] ? 1 : 0; // protect from quotes in text fields $fields['text1'] = addslashes($fields['text1']); $fields['text2'] = addslashes($fields['text2']); ...
#3
Posted 15 April 2006 - 01:54 PM
That was it, thanks Mike!
//<?php
// faqs_save
// extract configuration settings for local use
extract($cfg);
// define the $fields variable as an array
$fields=array();
// extract the form data fields using getFormVars
$fields = $etomite->getFormVars($method="POST",$prefix,$trim=1,$REQUEST_METHOD);
// adjust our display setting to be a boolean value
$fields['active'] = $fields['active'] ? 1 : 0;
// extract the form file fields using getFormVars
$files = $etomite->getFormVars($method="FILES",$prefix,$trim=1,$REQUEST_METHOD);
// protect from quotes in text fields
$fields['name'] = addslashes($fields['name']);
$fields['description'] = addslashes($fields['description']);
// if a new image file is being uploaded, and filesize > 0, let's store the new filename reference
$fields['image'] = ($files['imageFile']['size'] > 0) ? $files['imageFile']['name'] : $fields['image'];
// insert/update record based on existence of primary key
if($fields['faqsid']!="") {
// edited record so uspate using updIntTableRows()
$rs = $etomite->updIntTableRows($fields, $table, $where="faqsid=".$fields['faqsid'], $sort="", $dir="ASC", $limit="");
} else {
// new record so save using putIntTableRow()
$rs = $etomite->putIntTableRow($fields,$table);
}
// move uploaded image image to destination
$uploadfile = $imagesPath.$fields['image'];
move_uploaded_file($files['imageFile']['tmp_name'], $uploadfile);
// return to caller
echo "<script type='text/javascript'>location.href='$actionURL'</script>";
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users











