|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
smart-noob Smarty n00b
Joined: 25 Feb 2011 Posts: 1
|
Posted: Fri Feb 25, 2011 4:57 pm Post subject: onclick update table set fieldvalue doit =1 |
|
|
Hello all,
Iīve got some problems with the syntax (on itself the smarty language is very easy). Please take a little bit care for my knowladge with the following used programming-languages. Iīm in a learning process with websolutions.
Iīve got this special problem:
It deals with a function wich refer from "update.php" to a file called "change.php" to do some action (set doit = 1 and refresh page "update.php").
Why post this problem in the smarty forum ?:
I just solved this in a rudimentary way without smarty but Iīm working with an extension wich not allow to make this function useful for this content and it works with smarty. A "<form>" in the refered "tpl"-file in this extension does already exist and this would impliment a "<form>" in a "<form>" that the following "solution" doesnīt work. Itīs a joomla extension. Hope Iīm right here, really need help.
The only way I can see is "<a href="change.php" onclick="if (confirm('doit?')) //dosomthing; return false;">"
Reason:
The file "change.php" has to change an sql-fieldvalue called 'doit' from 0(Standard on insert: null) to 1 with update by automatically select an existing subject by clicking a button/link.
1st steps of solution (Please donīt ask why first update and than delete - I think you will understand it shortly):
I tried it by using sql and php by a raw test(without using smarty). So far so good - the raw test was working (by using "<form>").
But I need a solution with using smarty(or not, itīs not nessessary) and without using form(or include a new input into the existing form - donīt know how).
Here is the code of the raw test if anybody would like to know (ordered by a logically way):
update.php
Code: |
<?php
session_start();
$token = $_SESSION['token'];
session_register('token');
unset( $_SESSION['token'] );
?>
<!--<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">-->
<html>
<head>
<?php
// Create a $string
$_SESSION['token'] = $string;
require_once('config.php'); // Connection
$select_hid = "select * from persons where id = '100' and doit='1'";
// I need a variable select 'id' by a specified automatically detected $id (it means not '100' but $id[one of them from 1 to end - Further validations already exist]).
// id is a auto_increment primary key - How to realize "select * from persons where id = '$id'"?
$meg_hid = mysql_query($select_hid) or die(mysql_error());
$line_meg_hid = mysql_fetch_assoc($meg_hid);
$this_line_meg_a = mysql_num_rows($meg_hid);
mysql_free_result($meg_hid);
$werdtfgj='0'; if ($select_hid==true) $werdtfgj='1'; // Iīm not sure why creating this line but I think it wonīt work if itīs not theire
mysql_close($con);
if ($this_line_meg_a=='1'){
echo "<title>Updated</title>";
}else{
echo "<title>Update this</title>";
}
?>
<meta name="author" content="Dennis H.">
</head>
<body text="#000000" bgcolor="#FFFFFF" link="#FF0000" alink="#FF0000" vlink="#FF0000">
<form id="doit" name="doit" method="post" action="change.php?str=<?php echo $string;?>">
<?php
if ($this_line_meg_a=='1'){
echo "It works!!!";
}else{
include('action.php');
}
?>
<br />
<?php echo $_POST['doit']; ?>
<input type="hidden" name="token" id="token" value="<?php $string; ?>" />
</form>
</body>
</html>
|
action.php
Code: |
// Itīs easier to include
<a href="<?php echo $line_meg_a['megLink'];?>" onclick="if(confirm('Do it?')) javascript:document.doit.submit(); return false;"; />
<input type="image" src="pic.png" alt="<?php echo $line_meg_a['megAlt'];?>" />
</a>
|
change.php
Code: |
<?php
session_start();
?>
<html>
<head>
<?php
function Page() {
$page = 'http';
if ($_SERVER["HTTPS"] == "on") {$page .= "s";
}
$pageURLstr .= "://";
if ($_SERVER["SERVER_PORT"] != "80") {
$page .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
} else {
$page .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
}
return $page;
}
require_once('config.php'); // Connection
$tag = substr(Page(),-16, 16) ;
if ($_SESSION['token']==$tag){
$inv_a = "update persons set doit = '1' where id ='100'";
$del = "delete persons where id ='100' and doit = '1'";
$doit_a = mysql_query($inv_a);
$doit_c = mysql_query($del); // It doesnīt delete the row, please tell me why???
$select_a = "SELECT * FROM persons where id = '100' AND doit='0'";
$meg_a = mysql_query($select_a) or die(mysql_error());
$line_meg_a = mysql_fetch_assoc($meg_a);
$this_line_meg_a = mysql_num_rows($meg_a);
mysql_free_result($meg_a);
mysql_close($con);
echo '<table width="100%" height="100%"><tr valign="middle" align="center"><td valign="middle" align="center">';
echo '<img width="17px" height="17px" src="pic.gif">';
echo "The process will accepted.<br />- Please wait a moment -";
echo '</td></tr></table>';
}else{
echo '<table width="100%" height="100%"><tr valign="middle" align="center"><td valign="middle" align="center">';
echo '<img width="17px" height="17px" src="pic.gif">';
echo '<br />';
echo "Please do not enter another URL as automatically generated - Has not worked, try again!";
echo '</td></tr></table>';
}
?>
<meta http-equiv="refresh" content="2 URL=update.php" >
</head>
<body bgcolor="gray">
</body>
</html>
|
Again, the content works with a 'tpl'-smarty-content and I donīt know how to integrate this working test function on this way.
Also I dont know how to select a coulumn by a primary key - Does anyone could explain or give an example code? -Shame on me, I know.-
These are my questions and solution up to this point. Please give me some feedback. Maybe another idea to disolve it.
In the next step I explain the very specified problem. This was just a test (a warm up:) ), I hope itīs not to much...
Best regards,
DH
Last edited by smart-noob on Fri Feb 25, 2011 5:08 pm; edited 3 times in total |
|
Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|