Any body can explain me how session works in PHP. for eg. 3 users logged into gmail. how the server identifies these 3 uers. what are the internel process behind that.
I have simple template that's html mostly and then pulls some stuff out of SQL via PHP and I want to include this template in three different spots of another php file. What is the best way to do this? Can I include it and then print the contents?
Example of template:
Price: <?php echo $price ?>
and, for example, I have another php file that will show the template file only if the date is more than two days after a date in SQL.
Hi,
I've inherited a project which we are trying to migrate to MySQL 5 from MySQL 4.0(!) and from myISAM to InnoDB. Queries are now falling down because they are being constructed using an ADODB connection's -qstr() on all parameters, including ints. Where no value is provided I end up with:
INSERT INTO tablename VALUES ('', 'stuff'...)
where the first column is an auto_increment. This causes an error (fair enough since '' isn't an int). Is there a switch in MySQL to make it behave as it used to (I assume it just silently converted to 0?)
Thanks.
I am new to PHP & want to we send email from localhost to my gmail address.
I used:
$to = "[email protected]";
$subject = "Account Confirmation";
$headers = "From: [email protected]";
$message = "Testing";
$mail = mail($to, $subject, $message, $headers);
if ($mail) {
echo "Mail sent.";
} else {
echo "Some Error occur.";
}
And it show Some Error occur.
please help.
Thanks
I use Aptana Studio for my PHP projects. I have not learned it but just used with what I was able to do in it. Many features I still don't know how to use in it.
At present, I have a HTML form and I want to write a .php script for the SEND button that it has. It is a submission script for the contact form.
I want a simple PHP IDE with which I can execute a single PHP file or work with at least two or three files easily, without much mess.
Please suggest a simple alternative to Aptana.
I have a url http://*.com/branch/module/view/id/1/cat/2/etc/3.
It becomes.
array
(
'module'=>'branch',
'controller'=>'module',
'action'=>'view'
);
next I need to get the params.
Ihave this array.
/*function getNextSegments($n,$segments) {
return array_slice ( $q = $this->segments, $n + 1 );
}
$params = getNextSegments(3);
*/
array ( 0 => 'id', 1 => '1', 2 => 'cat', 3 => '2', 4 => 'etc', 5 => '3' );//params
And i wanna convert it to this one:
array
(
'id'=1,
'cat'=2,
'etc'=3,
);
How i can do this using php function. I know I can do using for or foreach, but I think php has such function , but i cant find it :(.
Thank you.
class A {
protected function combine($params) {
$count = count ( $params );
$returnArray = array ();
for($i = 0; $i < $count; $i += 2) {
$g = $i % 2;
if ($g == 0 or $g > 0) {
if (isset ( $params [$i] ) and isset ( $params [$i + 1] ))
$returnArray [$params [$i]] = $params [$i + 1];
}
}
return $returnArray;
}
}
This works normaly. If anybody has better login for this please help.
Thank you again.
I have three php scripts. main.php questions.php and values.php
Here's the code
main.php
<html>
<head>
<title></title>
</head>
<body>
<h1>Be Prepare for the battle</h1>
<?php
$strTitle = "Begin";
$strLink = "<a href = 'question.php?ques_id=1'>" . $strTitle ."</a>";
echo $strLink;
?>
</body>
</html>
questions.php
<?php require_once('../connect.php'); $quesSQL = mysql_query("SELECT * FROM `questions` WHERE `ques_id`=". $_GET["ques_id"]);
if(!mysql_num_rows($quesSQL)>=1)
{
die('Complete.');
}
$next = $_GET["ques_id"]; while($row = mysql_fetch_array($quesSQL)) {
$id = $row['ques_id'];
$strTitle = $row['ques_title'];
echo "<li>". $strTitle ."</li><br/>";
}
$optSQL = mysql_query("SELECT `options`,`values` FROM questions_options WHERE ".$id."= ques_id");
echo "<form action=\"values.php\" method=\"POST\">";
while($row = mysql_fetch_array($optSQL) ) {
$strOptions = $row['options'];
$strValues = $row['values'];
echo "<input type =\"radio\" name =\"valueIn\" value=".$strValues." />". $strOptions ."<br/>";
}
echo "</form>";
$strTitle = "<input type =\"submit\" value=\"Next\">";
$next = $next+1;
$strLink = "<a href = 'values.php?ques_id=".$next."'>" . $strTitle ."</a>";
echo $strLink;
mysql_close();
?>
and values.php
<?php
require_once('../connect.php');
$input = $_POST['valueIn'];
$ansSQL = mysql_query("SELECT `answer` FROM questions WHERE 1-".$_GET["ques_id"]."= ques_id");
$marks = 0;
if($input == $ansSQL)
{
$marks = $marks+1;
}
else
{
$marks = $marks+0;
}
echo $marks;
?>
Now problem is i have to pass one value from second script(questions.php) to third script(values.php).
And it is from the <form> section in radio button's name value "valueIn". But I can't do that. Because I'm sending another value ques_id with $strLink variable at the end of the second script.
So how can i do that?
Is there a simple :) and efficient way or reading very large number of rows sequentially using Zend_Db?
Basically I need to process entire table, row by row. Table is large, primary key sequence is not guaranteed(i.e. not an autoincrement, but is UNSIGNED INT).
What's the best way to approach this?
Environment: PHP 5.2, Zend Framework 1.10, MySQL 5.1
How does one provide a direct URL for an image file (JPEG) that is secure?
For example, if a PHP script writes uploaded images to directory http://www.somehost.com/images, is it okay to provide http://www.somehost.com/images/someimage.jpg as the URL, or is there a more secure way to do this?
Should I look into something like the permalink feature that is a part of Wordpress? I am not sure if that is related.
The main reason I ask is that I have a custom PHP/MySQL CMS for managing images. I would like for the client to be able to copy a link to the image they want and then include it in a TinyMCE text editor for inserting the image in their website.
Thanks!
0 down vote
hi,
I have problem in showing $date="2011-02-10 15:26:20"; in the format of Thursday 10th of February 2011 03:26:20 PM in php.
i know there is one date function in php and can be done in one line for example: but via this it will flash today date or so.
i want to do it when user check any date and want that date in the format which i mention earlier.
please revert me back as soon as posib....
thanks
Hi people, i'm starting with Zend Framework and I'm a little bit confused with models and relathionships (one-to-many, many-to-many etc).
The "Zend Framework Quick Start" says to create a Zend_Db_Table, a Data Mapper and finally
our model class
Suppose we have a database like this:
table A (
id integer primary key,
name varchar(50)
);
table B (
id integer primary key,
a_id integer references A
);
then, i'll create:
Application_Model_DbTable_A extends Zend_Db_Table_Abstract,
Application_Model_AMapper,
Application_Model_A,
Application_Model_DbTable_B extends Zend_Db_Table_Abstract,
Application_Model_BMapper,
Application_Model_B,
if I understood, i've to store the references informations in
Application_Model_DbTable_A:
protected $_dependentTables = array('B');
and Application_Model_DbTable_B:
protected $_referenceMap = array(
'A' => array(
'columns' => array('a_id'),
'refTableClass' => 'A',
'refColums' => array('id')
)
);
and my models class:
class Application_Model_A
{
protected $_id;
protected $_name;
public function __construct(array $options = null)
{
if(is_array($options)) {
$this->setOptions($options);
}
}
public function __set($name, $value)
{
$method = 'set' . $name;
if (('mapper' == $name) || !method_exists($this, $method)) {
throw new Exception('Invalid property');
}
$this->$method($value);
}
public function __get($name)
{
$method = 'get' . $name;
if (('mapper' == $name) || !method_exists($this, $method)) {
throw new Exception('Invalid property');
}
return $this->$method();
}
public function setOptions(array $options)
{
$methods = get_class_methods($this);
foreach ($options as $key => $value) {
$method = 'set' . ucfirst($key);
if (in_array($method, $methods)) {
$this->$method($value);
}
}
return $this;
}
public function setName($name)
{
$this->_name = (string) $name;
return $this;
}
public function getName()
{
return $this->_name;
}
public function setId($id)
{
$this->_id = (int) $id;
return $this;
}
public function getId()
{
return $this->_id;
}
class Application_Model_B
{
protected $_id;
protected $_a_id;
public function __construct(array $options = null)
{
if(is_array($options)) {
$this->setOptions($options);
}
}
public function __set($name, $value)
{
$method = 'set' . $name;
if (('mapper' == $name) || !method_exists($this, $method)) {
throw new Exception('Invalid property');
}
$this->$method($value);
}
public function __get($name)
{
$method = 'get' . $name;
if (('mapper' == $name) || !method_exists($this, $method)) {
throw new Exception('Invalid property');
}
return $this->$method();
}
public function setOptions(array $options)
{
$methods = get_class_methods($this);
foreach ($options as $key => $value) {
$method = 'set' . ucfirst($key);
if (in_array($method, $methods)) {
$this->$method($value);
}
}
return $this;
}
public function setA_id($a_id)
{
$this->_a_id = (int) $a_id;
return $this;
}
public function getA_id()
{
return $this->_a_id;
}
public function setId($id)
{
$this->_id = (int) $id;
return $this;
}
public function getId()
{
return $this->_id;
}
it's that right?
Hi everybody,
How could I make sure that the startProcess(); function is being called, but without halting the execution for myFunction(). I'll guess that there's a way to call a function and prevent it from returning it's value to thereby accomplishing this?
Pseudo-code:
function myFunction() {
startProcess();
return $something;
}
function startProcess() {
sleep(5);
// Do stuff that user doesn't should have to wait for.
}
I haven't found any MYSQL many-to-many relationships examples here and in google. What I am looking is to see a very simple example with php+mysql showing database's results. Can anybody write a very simple example?
I am trying to insert some Arabic Language data into MySQL using PHP and an HTML form. When I insert the data in to MYSQL table, the table field represents data as مرØبا العالم.
But when I access the same data with PHP and show it in my webpage, it shows the correct data. I am using:
http-equiv="Content-Type" content="text/html; charset=utf-8"
meta tag in my web page to show Arabic data. My question is why my data looks like this: مرØبا العالم in MySQL table, and how should I correct it.
I have an array thats generated dynamically and it has some empty elements. How do I get rid of empty elements from an array?
array
0 = string '' (length=0)
1 = string 'x%6wm' (length=5)
2 = string 'x%6wmvf' (length=7)
3 = string 'x%645' (length=5)
4 = string '' (length=0)
And I want it to become like
array
0 = string 'x%6wm' (length=5)
1 = string 'x%6wmvf' (length=7)
2 = string 'x%645' (length=5)
Thanks
I have this SQL by a programmer:
$sql = "
INSERT INTO
`{$database}`.`table`
(
`my_id`,
`xType`,
`subType`,
`recordID`,
`textarea`
)
VALUES
(
{$my_id},
?xType,
?subType,
{$recordID},
?areaText
) ";
My question is why is he using ? before values? How do I see what values are coming in? I did echo and it shows ?xType as ?xType. No values. What does ? stand for in SQL?
why does this script show empty alert box. I am trying to use php value in javascript
<script type="text/javascript">
alert(<?php echo count($myorder) ?>); </script>
thanks
Hi all
I'm trying to write a function that could receive it's second arg a name of a function.
In order to validate function's name (that will be used in an eval statement) I use function_exists such as:
if(function_exists($type)){
$toEval= $type.'(\''.$file.'\');';
}else{
But if the arg sent is include or require (with 'once' variations) this code fails (function_exists returns false).
How could this be fixed?
Thanks,
Alex
Disclaimer, I'm not a PHP programmer, so you might find this question trivial. That's why I'm asking you!
I've got this kind of timestamp: 2010-05-10T22:00:00 (That's Y-m-d)
I would like to subtract, say, 10 days (or months, whatever) from this, and have my result be in the same format, i.e. 2010-04-30T22:00:00.
What function(s) do I need to do this in PHP?
Note: I'm using this to do a computed field in Drupal. The result will be the date that an e-mail is sent.
Bonus question: If 2010-05-10T22:00:00 means "May 10, 2010 at 10pm", is there a timestamp equivalent of "May 10, 2010 (all day)"?
Thanks everyone.
?
username:
';
}
else
{
$user=$_POST['user'];
$query="select name from login where name='$user'";
$result=mysql_query($query) or die(mysql_error());
$rows=mysql_num_rows($result)or die(mysql_error());
session_start();
//echo "results";
$username=mysql_fetch_array($result) or die(mysql_error());
$fields=mysql_num_fields($result) or die(mysql_error());
echo "username:$username[0]";
$_SESSION['username']=$username[0];
$sesion_username=$_SESSION['username'];
//echo "rows:$rows"." "."fields:$fields";
echo""."username:$sesion_username";
}
?
i wanted to create a site where user can login and upload their details depending on their user name have stored their details in a database,the problem i am facing is two people 'a' and 'b' login one after other session_variable $_SESSION['username'] will have 'b's' username ,so i can't display 'a's' details now. . . .
what i want to achieve is when a user logins in i want to store his name and other details in session variable and navigate him according and display his details
This is my BIG string
BEGIN:VEVENT
UID:xxxxxx
DTSTAMP:xxxxxx
STATUS:CONFIRMED
CLASS:PUBLIC
URL:xxxxxx
SUMMARY:YYYYYYY
DESCRIPTION:xxxxxx; YYYYYYY;
DTSTART:xxxxxx
DTEND:xxxxxx
GEO:xxxxxx
LOCATION:xxxxxx
END:VEVENT
I need to change position of the two "YYYYYYY" in SUMMARY/DESCRIPTION
I have to replace them without being specific since it is implemented in a much larger function. (This string is already sliced out of a 3700 line - Calendar)
pls help! :)