cereal 1,524 Nearly a Senior Poster Featured Poster

And also your table name, return, is a reserved word, check this: http://dev.mysql.com/doc/refman/5.5/en/reserved-words.html
Use backticks if you want to use it:

"insert into `return` ..."

bye :)

karthik_ppts commented: Yes. +6
cereal 1,524 Nearly a Senior Poster Featured Poster

On my opinion it's never a waste of time :)
Your solution does the job without GMP extension, in some situations you can't install what you want, so that's perfect.

cereal 1,524 Nearly a Senior Poster Featured Poster

While reading ardav solution I thought another solution. Maybe is not clean but it should work:

<?php
function convert($number)
{
	$reverse = strpos(strrev($number),'.');
	$number = (strpos($number,'0') == '0') ? str_replace('0','',$number) : $number;
	
	$n1 = str_replace('.','',$number);
	$n2 = pow('10',$reverse);
	
	$a = gmp_gcd($n1,$n2);
	$b = gmp_strval($a); # display greatest common divisor
	
	return $n1 / $b . "/" . $n2 / $b . "\n";
}

echo convert('0.75');
?>

bye :)

diafol commented: Nice :) +13
cereal 1,524 Nearly a Senior Poster Featured Poster

Check my reply, and the evolution of the script, in this thread http://www.daniweb.com/web-development/php/threads/375317
The solution is the same. Bye :)

cereal 1,524 Nearly a Senior Poster Featured Poster

I don't see the form tag but I assume you are using post method:

$loan = str_replace('PHP ','',$_POST['loan']);

if($_POST['CO'] == 'Yes')
{
    # 5% computation
    $interest = $loan * 0.05;
}

else
{
   # 10% computation
   $interest = $loan * 0.1;
}

echo 'loan: '. $loan;
echo 'interest: '. $interest;

Side note, you can reduce the conditional statement to this:

$interest = ($_POST['CO'] == 'Yes') ? $loan * 0.05 : $loan * 0.1;

bye :)

cereal 1,524 Nearly a Senior Poster Featured Poster

Send an echo from functions.php just to be sure is including fine. You should also get some notices from PHP because $_POST variables aren't there until you send the form.

A question: max_of_3.php and Maxof3.php are the same file? On the form tag you send data to the second.

cereal 1,524 Nearly a Senior Poster Featured Poster

You can write: $name,$field1,$field2 without quotes. Bye :)

cereal 1,524 Nearly a Senior Poster Featured Poster

First of all, congrats! :)
You don't need to write different versions of the same page. Sometimes you need to apply some little adjustments, just grab a CSS tutorial/book and learn from there.

Pixels are always the same on each computer, if you set a page at 900px it will look the same on each computer. But if you want an adaptive design, then use % or em. Search for tabless/fluid design.

The connection string can be saved into another file, you can use include() or require() to use it. Usually php page are processed by the server and only the output (echo, print...) is sent to the browser.

You are using relative links, it's better to use absolute paths, if you put your images/ directory into the root of your web server than remove the dots from the link <a href="/images/whatever.jpg"> will work.

cereal 1,524 Nearly a Senior Poster Featured Poster
$a = 20;
$b = 30;
echo $a+$b;

bye :)

cereal 1,524 Nearly a Senior Poster Featured Poster

So, if you write $_POST['order_of_products_by_values'] you don't get anything? if you select Pret crescator you should get 1.

Ops, I see that form and select are using the same id and name. Each element can use only a unique id per page, each form element can share the same name only if they are grouping, like radio buttons, so change the name and the id of your form.

cereal 1,524 Nearly a Senior Poster Featured Poster

I can't help you much on this.

For what I know you need to register your domain in association with the server IP address to a DNS server. In your case the IP is the public router IP.

Most of the times the Domain Registrar gives you the possibility to use their DNS, so you just need to login to their service and setup the right IP address.

I hope someone else can help you better. Bye :)

cereal 1,524 Nearly a Senior Poster Featured Poster

You're welcome :)

cereal 1,524 Nearly a Senior Poster Featured Poster

If the user register to the website you can ask for the timezone location, at that point your script becomes:

<?php 
date_default_timezone_set('Europe/London'); # or America/New_York
echo gmdate('c') . "\n"; 
echo date('c') . "\n"; 
?>

- http://www.php.net/manual/en/function.date-default-timezone-set.php
- http://www.php.net/manual/en/timezones.php

You can also use javascript to get the datetime, send it to your server through ajax and try to figure the timezone. Probably you can also use IP Geolocation but I can't help you on this.

cereal 1,524 Nearly a Senior Poster Featured Poster

I don't know your database structure, so here's an example:

# tables structure
mysql> explain users;
+---------+-------------+------+-----+---------+----------------+
| Field   | Type        | Null | Key | Default | Extra          |
+---------+-------------+------+-----+---------+----------------+
| id      | int(9)      | NO   | PRI | NULL    | auto_increment |
| fname   | varchar(50) | NO   |     | NULL    |                |
| lname   | varchar(50) | NO   |     | NULL    |                |
| userid  | varchar(50) | NO   |     | NULL    |                |
| referer | varchar(50) | NO   |     | NULL    |                |
+---------+-------------+------+-----+---------+----------------+
5 rows in set (0.00 sec)

mysql> explain blog;
+---------+-------------+------+-----+---------+----------------+
| Field   | Type        | Null | Key | Default | Extra          |
+---------+-------------+------+-----+---------+----------------+
| id      | int(9)      | NO   | PRI | NULL    | auto_increment |
| title   | varchar(50) | YES  |     | NULL    |                |
| user_id | int(9)      | NO   |     | NULL    |                |
+---------+-------------+------+-----+---------+----------------+
3 rows in set (0.00 sec)

mysql> explain comments;
+---------+--------+------+-----+---------+----------------+
| Field   | Type   | Null | Key | Default | Extra          |
+---------+--------+------+-----+---------+----------------+
| id      | int(9) | NO   | PRI | NULL    | auto_increment |
| message | text   | YES  |     | NULL    |                |
| user_id | int(9) | NO   |     | NULL    |                |
| blog_id | int(9) | NO   |     | NULL    |                |
+---------+--------+------+-----+---------+----------------+
4 rows in set (0.00 sec)

# queries to see what is inside:
mysql> select * from users; select * from blog; select * from comments;
+----+-------+-------+------------+---------+
| id | …
diafol commented: nice - coalesce - like it +13
cereal 1,524 Nearly a Senior Poster Featured Poster

Unless is specified by localtime(), time_zone cookies and so on, PHP works with the server time, not with client time, if you want to use GMT then use gmdate():

<?php 
echo gmdate('c'); 
echo date('c'); 
?>

http://www.php.net/manual/en/function.gmdate.php

cereal 1,524 Nearly a Senior Poster Featured Poster

The best option it to get an hosting with the same features you need. So the bandwidth won't be limited by your connection speed.

If you want to run your website from home, you need to check if your IP is static or dynamic. If dynamic, then you need to use a system like dyndns or freedns, where you register an account, you setup with your domain and update your IP each time you connect to internet. Some routers can connect automatically with those services, so you're always online. There are also client programs used to update the IP.

If you have a static IP address, then you need to setup your IP on the domain control panel.

Then you need to setup the VirtualHost on your apache config for your website, and write the domain you choosed, the port used by the server and so on. Check here: http://httpd.apache.org/docs/2.0/vhosts/examples.html

cereal 1,524 Nearly a Senior Poster Featured Poster

Where is the form? And why you wrote this:

<td><a href='tcninja_update.php?ID=".$rows['ID']."'>submit</a></td>

This will generate a GET, to read ID you need to write $_GET, but you won't get Status, to get that you need to add it to the link &Status=value To submit a form like yours you need the proper tag, so you need to write:

<form method="post" action="tcninja_update.php"> <!-- this goes at the top of the form -->
<!-- select goes here... -->

<!-- before </form> add this: -->
<input type="hidden" name="ID" value="<?php echo $rows['ID']; ?>" />
<input type="submit" name="submit" value="send" />
cereal 1,524 Nearly a Senior Poster Featured Poster

You need double quotes, otherwise $x won't be processed. An alternative is this:

'SELECT * FROM ...WHERE field="blah blah" HAVING field2<'.$x
cereal 1,524 Nearly a Senior Poster Featured Poster

I'm sorry, I gave you wrong suggestion, I was tired x_x
Use single quotes instead:

<?php
$fn = 'connect.inc.php';
$string = '<?php
$mysql_host = "localhost";
$mysql_user = "root";
$mysql_password = "";
$mysql_database = "main";

@mysql_connect($mysql_host, $mysql_user, $mysql_password) or die("There was an error connecting to the server");
@mysql_select_db($mysql_database) or die("There was an error connecting to the table");
?>';

if ($handle = fopen($fn, 'w')){
	if (!fwrite($handle, $string)){
		die("Couldn't write to file");
		echo "Writing success";
	}
}
?>

Writing:

<?php
$fruit = 'apples';
echo "oranges, cherries, $fruit"; # will display apples
echo 'oranges, cherries, $fruit'; # will display $fruit
?>
cereal 1,524 Nearly a Senior Poster Featured Poster

Yes, it happens because the document is not written well.
Just add @ to load function: @$dom->loadHTML($f);

cereal 1,524 Nearly a Senior Poster Featured Poster

getElementById() works like in javascript, if the target page has <div id="mytest"></div> then write getElementById('mytest')
And the script can work if the page is well formed, if there is a doctype... an example:

<?php
$f = file_get_contents('http://website/');
$dom = new domDocument;
$dom->loadHTML($f);
echo $dom->getElementById('mytest')->nodeValue;
?>
cereal 1,524 Nearly a Senior Poster Featured Poster

Try PHP DOM, I gave a suggestion here: http://www.daniweb.com/web-development/php/threads/376665

But instead of using getElementsByTagName you can use getElementById:
http://www.php.net/manual/en/domdocument.getelementbyid.php

cereal 1,524 Nearly a Senior Poster Featured Poster

Use EOF:

<?php
echo <<<EOF
<?php echo 'test'; ?>
EOF;
?>
cereal 1,524 Nearly a Senior Poster Featured Poster

Then you can use button tag. Here's an example:

<!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>
<title>test</title>
</head>
<body>

<div id="offers">
	<label for="item">Select your item</label><br />
	<button type="button" id="item1" name="item">item1</button>
	<button type="button" id="item2" name="item">item2</button>
</div>

<div id="form"></div>

<script src="jquery-1.6.2.min.js" type="text/javascript"></script>
<script type="text/javascript">
$('#item1').click(function(){
	event.preventDefault();
	$('#offers').css('display','none');
	$('#form').append('<form method="post" action="item1.php"><label for="email">e-mail</label><br /><input type="text" name="email" /><br /><input type="submit" name="getit" value="Get Item" /></form>');
});
$('#item2').click(function(event){
	event.preventDefault();
	$('#offers').css('display','none');
	$('#form').append('<form method="post" action="item2.php"><label for="email">e-mail</label><br /><input type="text" name="email" /><br /><input type="submit" name="getit" value="Get Item" /></form>');
});
</script>
</body>
</html>

Note that due to my limited knowledge of jquery I'm writing all the email form through javascript, but I'm sure someone else can suggest a better & cleaner solution.

cereal 1,524 Nearly a Senior Poster Featured Poster

Try with backticks on word:

$query = "SELECT * FROM `pro_words` WHERE `word` = ".$_GET['w'];

Or just try to do a simple query, without $_GET, to see if that works.

cereal 1,524 Nearly a Senior Poster Featured Poster

If I'm understanding good and you want to redirect, then just change forms for item1 and item2:

<form method="get" action="item1.php">
<input type="submit" name="getit" value="Item 1" />
</form>

<form method="get" action="item2.php">
<input type="submit" name="getit" value="Item 2" />
</form>

But, you still need to set the email field, so it's easier to redirect everything to a single script. I suggest you to simplify, sending a single form:

<form method="post" action="items.php">
<label for="item">Select your item</label><br />
<input type="radio" name="item" value="1" /> item 1 <br />
<input type="radio" name="item" value="2" /> item 2 <br />

<label for="email">e-mail</label><br />
<input type="text" name="email" /><br />

<input type="submit" name="getit" value="Get Item" />
</form>

items.php can do this operation:

<?php
if($_POST['item'] == '1')
{
    echo 'item 1'; # do your action here
}

if($_POST['item'] == '2')
{
    echo 'item 2'; # do your action here
}
?>

you can also hide the email fields if you want:

<form method="post" action="items.php">
<label for="item">Select your item</label><br />
<input type="radio" id="item1" name="item" value="1" /> item 1 <br />
<input type="radio" id="item2" name="item" value="2" /> item 2 <br />

<div id="email" style="display: none;">
   <label for="email">e-mail</label><br />
   <input type="text" name="email" /><br />
</div>

<input type="submit" name="getit" value="Get Item" />
</form>

<script type="text/javascript">
$('#item1').click(function(event){
	event.preventDefault();
	$('#email').css('display','block');
});
$('#item2').click(function(event){
	event.preventDefault();
	$('#email').css('display','block');
</script>

I don't know jquery so I'm not sure .click event will work, I usually use dojo. Hope it's useful :)

cereal 1,524 Nearly a Senior Poster Featured Poster

To me the wrong part are on line 35 an 42: <?=$url='item1.php'?>
Once the page is loaded, PHP won't change the value echoed on line 11: action="<?=$url?>"

Instead of using two different urls, you should send everything to the same script and use the value that you get: item1/item2 to make a conditional statement.

Other than this, the forms item1 and item2 are missing of action and method attributes. When you send a form you are requesting a connection with the server, but you are using this only to display an hidden element by CSS. What you need here is not onSubmit but onClick: $('#item1').click(function(event)

Bye :)

cereal 1,524 Nearly a Senior Poster Featured Poster

This is wrong:

$query = "SELECT * FROM pro_words".$_SESSION['where clause'];

this should work:

$query = "SELECT * FROM pro_words WHERE word = ".$_GET['w']; # or $_SESSION['word']

but remember to sanitize data.

cereal 1,524 Nearly a Senior Poster Featured Poster

Try this:

echo "<div class='posterdecoration'><img src='$row[scr1]' width='640' alt='$row[name]' /></div>";
echo (isset($row['scr2'])) ? "<div class='posterdecoration'><img src='$row[scr2]' width='640' alt='$row[name]' /></div>" : NULL;

bye :)

-==Zero==- commented: Thanks For Reply Plz Continue With Me +2
cereal 1,524 Nearly a Senior Poster Featured Poster

Just an idea: if you don't need to store those information and your website is not using an SSL Certificate, then it's better to use javascript, so the users can fill the form, display and print it without sending anything to the server.

cereal 1,524 Nearly a Senior Poster Featured Poster

You should write more information, you get the data from the form? You still display the correct data after you do str_replace()? Have you tried to get response code? Right after r->send(); write:

try
{
    $r->send();
    echo $r->getResponseCode(); # so you know if the request reaches the gateway
    echo "<div cloass='error'>Message sent to : $recipient</div>";
}
cereal 1,524 Nearly a Senior Poster Featured Poster

Two questions:
1) can you show the html part?
2) the script is saving the image to the path?

cereal 1,524 Nearly a Senior Poster Featured Poster

This code should be on modify_data.php not in the first file, because there is no query to do:

$connect=mysql_connect('localhost','root','');
mysql_select_db('bank',$connect);
cereal 1,524 Nearly a Senior Poster Featured Poster

Or just replace line 19 and 20 with this:

$page = isset($_GET['page']) ? $_GET['page'] : false;
if($page != false)

If you don't send page var through the link then $page is undefined and gives you an error.

cereal 1,524 Nearly a Senior Poster Featured Poster

In your page you put the following code:

<?php

if(isset($_GET['p']) && !empty($_GET['p'])){
 $p = $_GET['p'];
 //please put mysql queries and most of the code dealing with mysql in a separate page unlike this one
 $query = "SELECT `content` FROM `your_table` WHERE `id`='$p'";
 if (@$mysql_query = mysql_query($query)){
  if (mysql_num_rows($mysql_query)==1){
   $content = mysql_result($mysql_query, 0, 'content');
  }
 }
}else{
 $p=1;
}

?>

<html>
 <p><?php echo $mysql_result; ?></p>
</html>

This is a simple but insecure way to display page content according to the id of the page. You can make a table and store all the id and content and other stuff.

If you wanna make it secure, please put all the queries and everything dealing with mysql in a separate page and require or include it in your main page.

Sorry, I didn't saw you have already posted a solution. I opened the thread and went away for a bit.. ^_^'

cereal 1,524 Nearly a Senior Poster Featured Poster

Let say you have a table for your blog (with id, title and post fields):

<?php
	$id = $_GET['id'];
	if(ctype_digit($id))
	{
		$query = mysql_query("SELECT * FROM blog WHERE id = '$id' limit 1");
		if(mysql_num_rows($query) == 1)
		{
			while($row = mysql_fetch_assoc($query))
			{
				echo $row['title'];
				echo $row['post'];
				echo $row['id'];
			}	
		}
		else
		{
			echo 'not found';
		}
	}
	else
	{
		echo 'not valid';
	}
?>

Check these links for more information:
http://www.php.net/manual/en/function.mysql-fetch-assoc.php
http://www.php.net/manual/en/function.ctype-digit.php

cereal 1,524 Nearly a Senior Poster Featured Poster

This should work:

<Files about.html>
php_flag engine off
AddType text/html .html
ForceType text/html
</Files>
cereal 1,524 Nearly a Senior Poster Featured Poster

Size and width/height are two different things, you can have an image of 800x600 and 1.2MB and another of the same width and height but only 200KB, depends on colors, on format and compression.

So, if the user is uploading a file of 800KB, you can't be sure that with a simple resize the output will be a file of 32KB.

You should just check if the file has the sizes you want, and if not, then the user should change the values on his own computer, because converting/resizing images can be a really CPU expensive process. If you don't use a load balancer like Gearman, then few users running the same script, at the same time, can kill the server.

My Opinion. Bye :)

cereal 1,524 Nearly a Senior Poster Featured Poster

You have to do just few changes:

foreach($map as $key => $value){
	  // Define variables from $_POST array
	  // I am pretty sure this is not really the way to do this
	  $id = mysqli_real_escape_string($dbc, trim($value[0]));
	  $image_filename = mysqli_real_escape_string($dbc, trim($value[1]));
	  $description = mysqli_real_escape_string($dbc, trim($value[2]));
	  // Update database (I really only need to update the description)
	  $query1="UPDATE $tbl_name SET description='$description' WHERE id='$id'";
          $result1=mysqli_query($dbc, $query1);
}

Now it should work, at least I hope so :D
With bidimensional arrays you need to use the second form of the foreach() loop (check the link at the end of my post), because in your example $value is the first level, but you still need to get the value of the second array.

I'm assuming that you're getting an array like in my example:

result Array
(
    [0] => Array
        (
            [0] => 9
            [1] => apples.jpg
            [2] => apples
        )

    [1] => Array
        (
            [0] => 10
            [1] => peaches.jpg
            [2] => peaches
        )
    . . .
)

- http://php.net/manual/en/control-structures.foreach.php

cereal 1,524 Nearly a Senior Poster Featured Poster

It doesn't work for two reasons:

1. I don't see any id hidden input
2. image_filename and description (and id) are arrays

Run this example:

<form method="post" action="">
<input type="text" name="id[]" value="9" />
<input type="text" name="image_filename[]" value="apples.jpg" />
<input type="text" name="description[]" value="apples" /><br />

<input type="text" name="id[]" value="10" />
<input type="text" name="image_filename[]" value="peaches.jpg" />
<input type="text" name="description[]" value="peaches" /><br />

<input type="text" name="id[]" value="11" />
<input type="text" name="image_filename[]" value="oranges.jpg" />
<input type="text" name="description[]" value="oranges" /><br />
<input type="submit" value="submit" name="submit" />
</form>

<?php
if(isset($_POST['submit']))
{
	echo '<pre> id[] ';
	print_r($_POST['id']);

	echo 'image_filename[] ';
	print_r($_POST['image_filename']);

	echo 'description[] ';
	print_r($_POST['description']);

	$map = array_map(null, $_POST['id'], $_POST['image_filename'], $_POST['description']);
	echo 'result ';
	print_r($map);
	echo '</pre>';
}
?>

You can process the resulting array with a foreach() loop and do the update queries. And so you should do in your script. Bye :)

cereal 1,524 Nearly a Senior Poster Featured Poster

This means that your script is using more memory than the allowed. If you post the script maybe somebody will be able to help you.

cereal 1,524 Nearly a Senior Poster Featured Poster

Great! :) On linux there is the command file that gives you the correct mime-type for each file:

file --mime video.flv

the result is video.flv: video/x-flv; charset=binary

cereal 1,524 Nearly a Senior Poster Featured Poster

Try to add video/x-flv to the conditional statement.

cereal 1,524 Nearly a Senior Poster Featured Poster

Go with Ubuntu Server and install Apache, MySQL and PHP. Here you can read the instructions:

- https://help.ubuntu.com/10.10/serverguide/C/index.html

sergent commented: thanks +5
cereal 1,524 Nearly a Senior Poster Featured Poster

Remove quotes from NOW() and it will work:

"UPDATE users SET timp=NOW() WHERE username='$user'"
cereal 1,524 Nearly a Senior Poster Featured Poster
cereal 1,524 Nearly a Senior Poster Featured Poster
cereal 1,524 Nearly a Senior Poster Featured Poster

You're welcome :)

cereal 1,524 Nearly a Senior Poster Featured Poster

In order to pass a session from a page to another you need to start, every page, with session_start()

bye :)

cereal 1,524 Nearly a Senior Poster Featured Poster

You can learn to use sessions:

- http://www.php.net/session
- http://www.php.net/session_start

Bye :)