Mysql update query wont save writing from text area - mysql

I am having a problem, i can connect to my database but it wont save in database what i wrote in a text area. Every time i click update it saves as blank, if i write lalala in mysql directly and refresh the page where text area is i can see lalala in text area but if i replace the text lalala in text area for something else and click update, it deletes the previous text lalala and leaves the field blank. Heres my code:
----------------------------- File 1 ---------------------------------
<?
include("header.inc.php");
$result5 = mysql_query("SELECT faq FROM `demo_a_faq`");
$myrow5 = mysql_fetch_row($result5);
$faq = $myrow5[0];
?>
<?
include("../templates/admin-header.txt");
?>
<form method="post" action="faq2.php">
<TABLE bgcolor="#FFFFFF" bordercolor="#000008" border="0" width="95%" align="center">
<TR>
<TD width="50%"><center><font face="Verdana, Arial, Helvetica, sans-serif" size="2"> <b>Edit FAQ:</b><br><textarea name="faneu" type="text" cols="80" rows="25"><? echo "$faq"; ?></textarea></TD>
</TR>
</TABLE><br><br>
<center><input type="submit" value="Update"></form></center>
<?
include("../templates/admin-footer.txt");
?>
----------------------------- File 2 ---------------------------------
<?
include("header.inc.php");
$asl = "UPDATE `demo_a_faq` SET `faq` = '$faneu'";
$results = mysql_query($asl) or die(mysql_error());
?>
<?
include("../templates/admin-header.txt");
?>
<center><br><br><br><b>Updated!</b></center>
<?
include("../templates/admin-footer.txt");
?>
In header.inc.php i simply have the conection to database.
Can someone please tell me why it is not saving what i write in text area to database as it is driving me crazy.
Thanks in advance

Try this:
<?php
include("header.inc.php");
// Always escape variables used in SQL-queries to avoid SQL-injections.
$faneu = mysql_real_escape_string($_POST['faneu']);
$asl = "UPDATE `demo_a_faq` SET `faq` = '$faneu'";
$results = mysql_query($asl) or die(mysql_error());
?>
<?
include("../templates/admin-header.txt");
?>
<center><br><br><br><b>Updated!</b></center>
<?
include("../templates/admin-footer.txt");
?>

You don't POST your textarea value to "FILES 2".Be carefull.

Related

How to fectch data from table in cakephp

Hi i have one table in my database which has list of states and i want to fetch this data from the table but my query is not executing properly it gives me some error
<?php
require_once('../Config/database.php');
$result1=$this->Signup->query("SELECT * FROM states");
//echo $popular;
while($post = mysql_fetch_array($result1))
{ ?>
<table width="380">
<tr>
<td class="table_txt"><a class="thickbox tn" href="demo.php?state_name=<?php echo $post['state_name']?>&state_id=<?php echo $post['state_id']?>&height=430&height=430&width=700&inlineId=myOnPageContent"><?php echo $post['state_name']?></a></td>
</tr>
</table>
<?php }
?>
But it gives me error
Warning (512): Method SignupHelper::query does not exist [CORE\Cake\View\Helper.php, line 192
Warning (2): mysql_fetch_array() expects parameter 1 to be resource, null given
Please read the documentation first.
It seems you are trying to get the states, inside the View, with a query.
You need to separate the view from the model.
Create a State model.
Use something like this in your controller:
$this->loadModel('State');
$states = $this->State->find('list'); // this will create a key => value array with the IDs and names
$this->set('states', $states);
In your view, use
<table width="380">
<tr>
<?php foreach ($states as $stateId => $stateName) {
<td class="table_txt"><a class="thickbox tn" href="demo.php?state_name=<?php echo $stateName?>&state_id=<?php echo $stateId?>&height=430&height=430&width=700&inlineId=myOnPageContent"><?php echo $stateName ?>></a></td>
<?php } ?>
</tr>
You might still need some changes, but this is the main idea.

You have an error in your SQL syntax

Hi im running into this error and i just cant seem to see the problem so any ideas, a fresh set of eyes might help.
Full Error:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'desc='ittititi', price='22', img='img.png'' at line 1
<?php
// Include MySQL class
require_once('../inc/mysql.php');
// Include database connection
require_once('../inc/global.inc.php');
// Include functions
require_once('../inc/functions.inc.php');
// Start the session
session_start();
?>
<?php
// try to create a new record from the submission
$genre = mysql_real_escape_string($_REQUEST['genre']);
$title = mysql_real_escape_string($_REQUEST['title']);
$desc = mysql_real_escape_string($_REQUEST['desc']);
$price = mysql_real_escape_string($_REQUEST['price']);
$img= mysql_real_escape_string($_REQUEST['img']);
if (!empty($genre) && !empty($title) && !empty($desc) && !empty($price) && !empty($img)) {
// here we define the SQL command
$query = "SELECT * FROM books WHERE title='$title'";
// submit the query to the database
$res=mysql_query($query);
// make sure it worked!
if (!$res) {
mysql_error();
exit;
}
// find out how many records we got
$num = mysql_numrows($res);
if ($num>0) {
echo "<h3>That book title is already taken</h3>\n";
exit;
}
// Create the record
$query = "INSERT INTO books SET genre='$genre', title='$title', desc='$desc', price='$price', img='$img'";
$res = mysql_query($query)or die(mysql_error());
if (! $res) {
echo mysql_error();
exit;
} else {
echo "<h3>Book Created</h3>\n";
echo $_SESSION['title']=$title;
}
}
?>
<form name="newbook" method="post">
<table border=0>
<tr>
<td>Genre:</td>
<td><input type=text name='genre'></td>
</tr>
<tr>
<td>Title:</td>
<td><input type=text name='title'></td>
</tr>
<tr>
<td>Description:</td>
<td><input type=text name='desc'></td>
</tr>
<tr>
<td>Price:</td>
<td><input type=number name='price'></td>
</tr>
<tr>
<td>Image:</td>
<td><input type=text name='img'></td>
</tr>
<tr>
<td colspan=2>
<input type=submit value="Create my account">
</td>
</tr>
</table>
</form>
You need to escape reserved words in MySQL like desc with backticks
INSERT INTO books
SET genre = '$genre', title = '$title', `desc` = '$desc'
^----^-----------------here
desc is reserved keyword for mysql
use it like that
`desc`
this must ne your query
$query = "INSERT INTO books SET genre='$genre', title='$title', `desc`='$desc', price='$price', img='$img'";
Don't use desc as a column name; it is a keyword. If you use it as a column name, you have to quote it.

Use forms in wordpress which goes back to itself?

i'm working on a wordpress site using buddypress. So, i'm making a page where you can see members and search for them using a database: wp_users.
This works fine if i have it as a php when adding it to a wp page it shows up correctly but when clicking submit I get a 404 error.
This is the code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Search Contacts</title>
<style type="text/css">
#spacer {
border-top-width: 1px;
border-right-width: 1px;
border-bottom-width: 1px;
border-left-width: 1px;
border-top-style: solid;
}
</style>
</head>
<p><body>
<p> </p>
<form method="post" action="" id="searchform">
<p>
<input name="name" type="text">
<input type="submit" name="submit" value="Søk">
</p>
<p>Tips: du kan søke etter adresse, navn og e-post.</p>
</form>
<table width="600">
<tr>
<th width="200" height="50">Navn</th>
<th width="200"> </th>
<th width="200">E-post adresse</th>
</tr>
<?php
/* Change next two lines if using online*/
$db="skynnaks_skyn";
$link = mysql_connect('localhost', 'skynnaks_skyn', '*password*');
if (! $link) die(mysql_error());
mysql_select_db($db , $link) or die("Couldn't open $db: ".mysql_error());
$result = mysql_query( "SELECT * FROM wp_users" )
or die("SELECT Error: ".mysql_error());
$num_rows = mysql_num_rows($result);
if ($result) {
while ($row = mysql_fetch_array($result)) {
$_SESSION['id']=$row['id'];
#echo "<tr><a href='#'>".$row['display_name']."</a>";
echo "<td><a href="."/members/".$row['user_nicename']."/profile/>".$row['display_name']."</a></td>";
#echo "<a href=" '.$row['id'].'>Bruker: ".$row['user_url']."</a>";
echo "<td>".$row['user_url']."</td>";
echo "<td>".$row['user_email']."</td></tr>";
}
}
?>
</table>
<div id="spacer">
<?php
if(isset($_POST['submit'])){
if(preg_match("/^[ a-zA-Z]+/", $_POST['name'])){
$name=$_POST['name'];
//connect to the database
$db=mysql_connect ("localhost", "skynnaks_skyn", "*password*") or die ('I cannot connect to the database because: ' . mysql_error());
//-select the database to use
$mydb=mysql_select_db("skynnaks_skyn");
//-query the database table
$sql="SELECT ID, user_login, user_nicename FROM wp_users WHERE user_login LIKE '%" . $name . "%' OR user_nicename LIKE '%" . $name ."%'";
//-run the query against the mysql query function
$result=mysql_query($sql);
//-create while loop and loop through result set
while($row=mysql_fetch_array($result)){
$loginName =$row['user_login'];
$niceName=$row['user_nicename'];
$ID=$row['ID'];
//-display the result of the array
echo "<ul>\n";
echo "<li>" . "<a href="."/members/".$loginName."/profile/>".$niceName."</a>" ;
echo "</ul>";
}
}
else{
echo "<p>Please enter a search query</p>";
}
}
?>
</div>
<p> </p>
</body>
</html>
</p>
PS: I cant use default permalinks due buddypress plugin. And i know that buddypress comes with a members search, but i have installed norwegian language pack, but it wont work with members search in buddypress.
Thanks for the help :)
It looks like this problem,
so change your input tag name with any specific name attribute.
for example,
<input name="membername" type="text" />
but don't forget to get variable with same from $_POST

HTML form with Zend Form filters/validators

I'm creating a simple contact form within my ZF application. It doesn't feel like it's worth the trouble to manipulate decorators for only a few form elements.
My Question is: am I able to still use Zend Form Filters on elements that are not created with Zend Form:
For Example:
The Form:
<!-- Standard HTML - not generated with ZF -->
<form id="contact-form" method="post" action="/contact/submit">
<input type="text" name="name" />
<input type="email" name="email" />
<input type="submit" name="submit" />
</form>
The Controller:
public function submitAction()
{
$params = $this->_request->getParams();
//Am I able to apply filters/validators to the data I get from the request?
//What is the best way to handle this?
}
I took a look at this (the answer from Darcy Hastings) - and it seems like it would work, it just feels a bit hacky.
Any and all advice appreciated.
Thanks,
Ken
yes, you can use Zend_Filter_Input, here is an example of how to set it up.
//set filters and validators for Zend_Filter_Input
$filters = array(
'trackid' => array('HtmlEntities', 'StripTags')
);
$validators = array(
'trackid' => array('NotEmpty', 'Int')
);
//assign Input
$input = new Zend_Filter_Input($filters, $validators);
$input->setData($this->getRequest()->getParams());
//check input is valid and is specifically posted as 'Delete Selected'
if ($input->isValid()) {
also you may consider using the viewscript decorator to render a Zend Form, The control is absolute (or almost).:
//in your controller action
public function indexAction() {
//a normally constructed Zend_Form
$form = new Member_Form_Bid();
$form->setAction('/member/bid/preference');
//attach a partial to display the form, this is the decrator
$form->setDecorators(array(
array('ViewScript', array('viewScript' => '_bidForm.phtml'))
));
$this->view->form = $form;
//the view
<?php echo $this->form?>
//the partial
//use a normal Zend_Form and display only the parts you want
//processing in an action is done like any other Zend_Form
form action="<?php echo $this->element->getAction() ?>"
method="<?php echo $this->element->getMethod() ?>">
<table id="sort">
<tr>
<th colspan="2">Sort By Shift</th>
<th colspan="2">Sort By Days Off</th>
<th colspan="2">Sort By Bid Location</th>
</tr>
<tr></tr>
<tr>
<td class="label"><?php echo $this->element->shift->renderLabel() ?></td>
<td class="element"><?php echo $this->element->shift->renderViewHelper() ?></td>
<td class="label"><?php echo $this->element->weekend->renderLabel() ?></td>
<td class="element"><?php echo $this->element->weekend->renderViewHelper() ?></td>
<td class="label"><?php echo $this->element->bidlocation->renderLabel() ?></td>
<td class="element"><?php echo $this->element->bidlocation->renderViewHelper() ?></td>
</tr>
<tr></tr>
<tr>
<td colspan="6" style="text-align: center"><?php echo $this->element->submit ?></td>
</tr>
</table>
</form>
Yes, you definitely can use Zend_Form on self-rendered forms.
You can do this in two ways:
Use a Zend_Form object, but don't render it. You create a Zend_Form instance as usual, with all the elements named correctly and attach validators and filters as per normal. In your action, you can then check the form's isValid() and use getValues() to ensure that you collect the filtered data.
The second option is to use Zend_Filter_Input which is a chain of validators and filters. You set up your validators and filters at construction and then call setData to populate the filter with the information from the request. Again, you have isValid() to test and then you use getUnescaped() to retrieve the data. The manual page has more details.

WordPress - Display Post Content and Post Meta on a Page in the Admin Area

I am trying to create a page in my WordPress Admin Area that displays excerpts of posts and various custom field meta in a table-style layout.
If this were a front-end WordPress Template, I could do this very easily using a WordPress Loop and Query, however, I am not so sure how I would go about doing this on a page in the admin area.
Would it be the same, or would I need to use a completely new method? If so, could someone please provide a working example of how I would do this?
The admin page will be created using an included file within my functions.php - or at least that is the plan at the moment, so I just need help in figuring out how to pull the WordPress Excerpts and Post Meta.
you can use the WP_Query object everytime after WordPress is initialized, so if you like you can even make thousands of nested queries in den WordPress backend if you want to do this.
This is the way to go:
Create an action to add your backend page - write a Plugin or put it into your functions.php
Setup the Menu Page - the code is an example for a full backend administration Page of your Theme
Include your queries using the WP_Query object - optionally make database queries directly (http://codex.wordpress.org/Displaying_Posts_Using_a_Custom_Select_Query). Possibly use the "widefat" class of WordPress, for pretty formatting.
Make sure that your changes are saved correctly
add_action('admin_menu', 'cis_create_menu');
function cis_create_menu() {
//create new top-level menu
add_menu_page(__('Theme Settings Page',TEXTDOMAIN),__('Configure Theme',TEXTDOMAIN), 'administrator', __FILE__, 'cis_settings_page', '');
//call register settings function
add_action('admin_init','cis_register_settings');
}
function cis_register_settings() {
register_setting('cis-settings-group','cis_options_1','cis_validate_settings');
}
function cis_settings_page() {
// All Text field settings
$op_fields = array(
array(__('Label 1','textdomain'),"Description 1")
);
?>
<div class="wrap">
<h2><?php echo THEME_NAME; _e(": Settings",TEXTDOMAIN); ?></h2>
<?php
settings_errors();
?>
<form method="post" action="options.php">
<?php
settings_fields( 'cis-settings-group' );
$options = get_option('cis_options_1');
?>
<h3><?php _e('General','textdomain'); ?></h3>
<table class="widefat">
<thead>
<tr valign="top">
<th scope="row"><?php _e('Setting','ultrasimpleshop'); ?></th>
<th scope="row"><?php _e('Value','ultrasimpleshop'); ?></th>
<th scope="row"><?php _e('Description','ultrasimpleshop'); ?></th>
<th scope="row"><?php _e('ID','ultrasimpleshop'); ?></th>
</tr>
</thead>
<tbody>
<?php
// the text-settings we define fast display
$i=1;
foreach($op_fields as $op) {?>
<tr valign="top">
<td><label for="cis_oset_<?php echo $i; ?>"><?php echo $op[0]; ?></label></td>
<td><input size="100" id="cis_oset_<?php echo $i; ?>" name="cis_options_1[cis_oset_<?php echo $i; ?>]" type="text" value="<?php echo esc_attr($options['cis_oset_'.$i]);?>" /></td>
<td class="description"><?php echo $op[1]; ?></td>
<td class="description"><?php echo $i; ?></td>
</tr>
<?php
$i++;
} ?>
</tbody>
</table>
<p class="submit">
<input type="submit" class="button-primary" value="<?php _e('Save Changes',TEXTDOMAIN) ?>" />
</p>
</form>
</div>
<?php }
// Validate the user input - if nothing to validate, just return
function cis_validate_settings( $input ) {
$valid = array();
$i= 1;
while(isset($input['cis_oset_'.$i])) {
$valid['cis_oset_'.$i] = $input['cis_oset_'.$i];
$i++;
}
$cis_additional_settings = get_option('cis_options_1');
foreach($input as $ikey => $ivalue) {
if($ivalue != $valid[$ikey]) {
add_settings_error(
$ikey, // setting title
"cis_oset_".$ikey, // error ID
str_replace("%s",$ikey,__('Invalid Setting in Settings Area ("%s"). The value was not changed.',TEXTDOMAIN)), // error message
'error' // type of message
);
$valid[$ikey] = $cis_additional_settings[$ikey];
}
}
return $valid;
}
outside the loop you would need to use
$post->post_excerpt
or try this
function get_the_excerpt_here($post_id)
{
global $wpdb;
$query = "SELECT post_excerpt FROM $wpdb->posts WHERE ID = $post_id LIMIT 1";
$result = $wpdb->get_results($query, ARRAY_A);
return $result[0]['post_excerpt'];
}