MitkOK 61 Junior Poster

Hello.

You have to check which button is closed :

<?php
      if(isset($_POST['action'])) { display(); }

      if (isset($_POST['submit'])) { profile(); }

?>

- Mitko Kostov

MitkOK 61 Junior Poster
MitkOK 61 Junior Poster

It's better to store audio files in dir on your server and put path in MySQL field.


- Mitko Kostov

MitkOK 61 Junior Poster

So, only thing you have to do is to select records from the database and put them in the forms ( value="..." ). After submit you update the database with the new values.

Example :

<?php

// connect to SQL server and select DB
// ..
// your query will select to edit record by id if you have one

$query = "SELECT name, phone, mail from table where id='$id' ";

$result = mysql_query($query, $link);

$row = mysql_fetch_array($result);

?><form action="edit.php" method="POST">
<input type="text" name="name" value="<?php echo $row['name']; ?>">
<input type="text" name="phone" value="<?php echo $row['phone']; ?>">
<input type="text" name="mail" value="<?php echo $row['mail']; ?>">
<input type="hidden" name="id" value="<?php echo $id; ?>">
<input type="submit" name="submit" value="Edit">
</form>

edit.php

<?php

// connect to DB server and select DB
....
// validate form data
// ...

$query = "UPDATE table SET name='$_POST[name]', phone='$_POST[phone]', name='$_POST[mail]' WHERE id='$_POST[id]' ";

// ...

?>

- Mitko Kostov

MitkOK 61 Junior Poster

Be more specific.

Do you insert data with forms ?

- Mitko Kostov

MitkOK 61 Junior Poster

Hi.

I recommend you to validate form data using PHP because JavaScript can be disabled by the user.


- Mitko Kostov

MitkOK 61 Junior Poster

file1.php

echo "<input type=\"hidden\" value=\"".$p."\"  name=\"p\">";

file2.php

echo $_POST['p'];

- Mitko Kostov

MitkOK 61 Junior Poster

I think your server doesn't recognize php file, so
it doesn't interpret it. Do you install and configure
correctly PHP ?


- Mitko Kostov

MitkOK 61 Junior Poster
<A HREF="javascript:window.print()">Click to Print This Page</A>
MitkOK 61 Junior Poster

Hi folks,
The page load time is the one of the main factors...

  • Reduce the HTTP Requests
  • Don’t rely on other sites
  • Save your images properly
  • Compression
  • Avoid JavaScript where possible
  • Strip extraneous PHP calls
  • Optimize Images
  • Image Formats
  • Optimize Your CSS
  • Use a Slash on Your Links
  • PHP/MySql Performance tuning
  • Server side Performance tuning

Hello.

You have enumerated things with different names, not different issues.

In red : PHP/MySQL programming

In green : Optimizing images.

Why do you think slashes in links affect loading time ?


- Mitko Kostov

MitkOK 61 Junior Poster

I don't understand you.

So, if the username and password are found
in DB the page redirects. What do you want
to do if it's incorrect ?

Hint: You can put $_SERVER in form action url to reload login page
until username and password are correct.


- Mitko Kostov

MitkOK 61 Junior Poster

If you want to use header() you must write it before any html code.

<?php

// check if submit button is clicked

if (isset($_POST['submit']))

{
$db=mysql_connect("localhost","root","") or die ('Connection error'. mysql_error());
	echo "ajay<br/>";

mysql_select_db("chat") or die ('Error connecting to database'. mysql_error());
	echo "connected to database";

$fr_username=$_POST["txt_username"];
$fr_password=$_POST["txt_password"];

$result = mysql_query("SELECT username,password FROM login WHERE username='$fr_username' AND password='$fr_password' ");

while($row = mysql_fetch_assoc($result))
  {
 		if($result!="")  
			{
				header("Location: page1.php");
			}
		else 
			{			
    			if ($result="")
					{
						echo "bad";
     				}
			}
} 

mysql_close($db);

}

$date = date("a");
if ($date=="am")
	{
		$title="Good Morning";
	}	
else
	{	
		$title="Good Afternoon";
	}


?>
</head>
<title>met-ene-dialogue</title>
<?php echo $title ?>
<style type="text/css">
<!--
body {
	background-image: url();
}
.style1 {color: #C13167}
.style2 {font-size: large}
-->
</style></head>

<body>
	
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <th width="16%" bgcolor="#FFFFFF" scope="col"><img src="images/queascopf4.gif" width="124" height="145"/></th>
    <th width="77%" bgcolor="#FFCCFF" scope="col"><p class="style1">WELCOME</p>
    <p class="style1">TO </p>
    <p class="style1">METE-ENE-DIALOGUE DOT COM  </p></th>
    <th width="7%" background="Drag to a file to choose it." bgcolor="#FFFFFF" scope="col"><img src="images/queascopf4.gif" width="124" height="145" /></th>
  </tr>
  <tr>
    <td colspan="3" bgcolor="#FFFFFF"><table width="100%" border="1" cellspacing="0" cellpadding="0">
      <tr>
        <th width="50%" bordercolor="#330033" scope="col" border = "5">MEMBERS LOGIN </th>
        <th width="50%" bordercolor="#330033" scope="col">NEW USER? SIGN IN </th>
      </tr>
      <tr>
        <td height="139">
		<form action = "<?php $page?>" method ="post">
	      <p>Username: 
	        <input type = "text" name = "txt_username"/>
	       
	        </p>
	      <p>Password: 
	        <input type = "password" name = "txt_password"/>
	      </p>
	      <p>
	        <input name="Submit" type = "submit" value="Submit"/>
	              </p>
        </form></td>
        <td height="139" align="center" valign="middle"><span class="style2">Sign in as new user </span></td>
      </tr>
    </table></td>
  </tr>
</table>
</body>
</html>
MitkOK 61 Junior Poster

Remember that header() must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP. It is a very common error to read code with include(), or require(), functions, or another file access function, and have spaces or empty lines that are output before header() is called. The same problem exists when using a single PHP/HTML file.

header()

PS : Why do you put your code in HEAD ?

- Mitko Kostov

MitkOK 61 Junior Poster

Hi.

If you're uploading files with ftp client, there must be an option to change permissions.

More info about chmod -> link


- Mitko Kostov

MitkOK 61 Junior Poster

chmod ?

MitkOK 61 Junior Poster

Hi there.

You can set php configuration options with ini_set() in every page. There is a limitation I think that with this command you cannot load extensions.

I don't know about Linux, but this is how it can be done on Windows :

httpd.conf :

Include conf/php.conf

php.conf

# PHP Definitions for Apache

# Load PHP Module & Associate .php extensions

#PHP 5
PHPIniDir "C:/web/Apache/conf"
LoadModule php5_module c:/web/PHP/php5apache2_2.dll
AddType application/x-httpd-php .php

# PHP Test & Help Sites
Alias /php "C:/web/webs/php"
Alias /phpmanual "C:/web/PHP/html"

DirectoryIndex index.php index.html index.html.var

Form PHPIniDir will php.ini loaded after restart.

On the other hand :

httpd.conf :

Include conf/sites/*.conf

In sites for example we've got test1.conf :

Alias /test1 C:/web/webs/test1
<Directory "C:/web/webs/test1">
   Order Deny,Allow
   [B]php_flag[/B] register_globals off
</Directory>

//

You can use specific apache directives in httpd.conf or .htaccess :

php_value name value

php_flag name on|off

php_admin_value name value

php_admin_flag name on|off


//

With this you have different configuration options for different directories.


- Mitko Kostov

MitkOK 61 Junior Poster

Hi.

There are instructions to install php on Linux.
Look in INSTALL file.


- Mitko Kostov

MitkOK 61 Junior Poster

What graphics card do you have?

I think that's the answer :

... intel extreem graphics

I recommend you to turn off Aero.


- Mitko Kostov.

MitkOK 61 Junior Poster

Hello.

Pay attention to the quotes :

$result = mysql_query("SELECT * FROM pages WHERE pagenumber LIKE '$pagenumber' ",$db) ;

Hint : You don't have to use LIKE if you don't want to use it with pattern. Instead of LIKE here you can use this :

$result = mysql_query("SELECT * FROM pages WHERE pagenumber='$pagenumber' ",$db) ;

- Mitko Kostov

MitkOK 61 Junior Poster

Why do they make computers harder to use and program than they need to be? Here are some examples:

- Why do most spreadsheets and programming languages do trigonometric functions in radians, when most people use degrees?

This is Math, trgometric functions use radians, it is standart.

- In the 1980s, kids all over were programming computers. With the change to Windows, this suddenly stopped, as Microsoft made programming a lot harder to do. Why?

Computer became very complex, therefore languages become harder to learn and use -> that's why people stop programming.

- Why have all of the easy-to-use programming languages been replaced with the hard-to-use C derivatives?

Same answer as above.

- Why are they making HTML harder to use by taking away features and not replacing them?

HTML is simple language, if you consider it as hard to learn maybe programming is not for you.

- Why do the operating systems get more complicated and take up more memory? They aren't any more useful.

No one makes you use OS like eating memory monsters like MS product or heavy UNIX OS.

MitkOK 61 Junior Poster

How I was born ...

The little boy asks his father - "Daddy, how was I born?"

Dad responds, "Ah, my son, I guess one day you will need to find out anyway! Well, you see, your Mom and I first got together in a chat room. Then I set up a date via e-mail with your Mom and we met at a cyber-cafe. We sneaked into a secluded room, where your mother agreed to a download from my hard drive. As soon as I was ready to upload, we discovered that neither one of us had used a firewall, and since it was too late to hit the delete button, nine months later a blessed little Popup appeared and said:

"You've got male!"

MitkOK 61 Junior Poster

You can put PHP code everywhere in your XHTML page with php extension ( except some functions like header ... ). For example :

<!DOCTYPE Doctype goes here>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title><?php echo $title; ?></title>
</head>
<body>
<?php echo $data; ?>
</body>
</html>

So you can format the page using CSS ...


- Mitko Kostov

MitkOK 61 Junior Poster

Hi.

Here is an example :

<?
    class dummy {
        var $variable;
        var $variable2 = 1;
        var $variable3 = 2;
        function sum($one, $two) {
            $val = $one + $two;
            return $val;
        }
        function sum2() {
            $val = $this->sum($this->variable2, $this->variable3);
            return $val;
        }
    }
?>

The "$this" variable is a reserved variable in object-oriented PHP programming (translation - don't use it in your classes!) that actually does the inheritance. "$this->sum()" is basically interpreted as, "in this class, perform the sum() function." Like "$this->sum()", "$this->variable2" is interpreted as "in this class, use the value of 'variable2'." Likewise with $this->variable3. Note: all calls to native class functions or variables are done in this manner. Starting with "$this->" and followed by the name of the function or variable you wish to use. I can't stress the importance of that enough.

http://www.spoono.com/php/tutorials/tutorial.php?id=27


- Mitko Kostov

MitkOK 61 Junior Poster

Hi.

You can use PhpMyAdmin to export/import it
or mysqldump and mysql to backup/restore db.

Example with mysqldump and mysql :

1. mysqldump --user=username --password database > filetosaveto.sql

2. mysql --user=username --password database < dumpfile.sql


- Mitko Kostov

MitkOK 61 Junior Poster

Hi.

This is a function to convert date from DD-MM-YYYY to YYYY-MM-DD :

function con2mysql($date) {

  $date = explode("-",$date);
  if ($date[0]<=9) { $date[0]="0".$date[0]; }
  if ($date[1]<=9) { $date[1]="0".$date[1]; }
  $date = array($date[2], $date[1], $date[0]);
 
 return $n_date=implode("-", $date);
 }

If you are using PHP 5 >= 5.1.0 there is native funciton :

date_format()

You can use it like this :

$date ='12-12-2007';
$dateTime = new DateTime($date);

$formatted_date=date_format ( $dateTime, 'Y-m-d' );

echo $formatted_date;
// This will output 2007-12-12

- Mitko Kostov

MitkOK 61 Junior Poster

If I am on this page for example

http://www.mypage.com/view.php?prop_id=5

and I want to add a link, that would translate to

<a href="submit_docs.php?prop_id=5 ">Click </a>

How do I accomplish this, how do I pass the php variable "prop_id" to a href link? Can someone shed me some light on this matter? Thanks a lot :)

What do you mean by trabslate ?

If you want to you use prop_id from view.php url in link :

$prop_id = '$_GET[prop_id]';

echo "<a href=\"submit_docs.php?prop_id=".$prop_id."\">Click </a>";

- Mitko Kostov

MitkOK 61 Junior Poster
ndeniche commented: HAHAHAHA +2
MitkOK 61 Junior Poster

Double post, please delete it.

MitkOK 61 Junior Poster

MySQL commands :

You can then import it into a MySQL table by running:

load data local infile 'file.csv' into table table
fields terminated by ','
enclosed by '"'
lines terminated by '\n'
(field1, field2, field3)

The fields here are the actual tblUniq table fields that the data needs to sit in. The enclosed by and lines terminated by are optional and can help if you have columns enclosed with double-quotes such as Excel exports, etc.

http://dev.mysql.com/doc/refman/5.0/en/load-data.html

WIth PHP :

Look in the attached file.


- Mitko Kostov

MitkOK 61 Junior Poster
MitkOK 61 Junior Poster

Hi.

It seems that the query is the problem.

$query = "SELECT * FROM contacts WHERE message LIKE '%$search%'";

 echo $query;

- Mitko Kostov

MitkOK 61 Junior Poster
MitkOK 61 Junior Poster

Interesting.

Please, print the sql query and try to execute it in PHPMyAdmin ( if you have ).

- Mitko Kostov

MitkOK 61 Junior Poster

Hi.

How do you check username and password ?
DB login or ?

- Mitko Kostov

MitkOK 61 Junior Poster

Cron job ?

MitkOK 61 Junior Poster

You have to remove any blank spaces before the php code.

The problem is that many editors seem to add additional blanks (spaces) and/or empty lines at the end of a file when you edit it. This so-called whitespace is then sent to the browser when the file is loaded and interferes with the header of a page that tries to send to the browser, often causing problems such as login problems.

If you are using UTF-8, disable BOM.


- Mitko Kostov

MitkOK 61 Junior Poster

Headers must be sent before any output.
So you cannot use it after/in any HTML, for example in <body>.

<BODY ...> is the section that holds everything that is actually displayed. All the text, headers, tables, etc are in the <BODY ...> section.

You don't need <body> in the code above, because you don't display anything.


- Mitko Kostov

MitkOK 61 Junior Poster

Hi.

I don't understand what's the problem.

Hint : Why don't you do the check in the query :

$result = mysql_query("SELECT username,pw FROM login WHERE username='$name' AND pw='$password' ");

if($result!='NULL')
	{
	header("Location: http://www.google.com");
	}
	
else {
            header("Location: http://www.yahoo.com");
            }

Hint 2:

$con = mysql_connect("localhost","","") or die('Could not connect: ' . mysql_error());

- Mitko Kostov

MitkOK 61 Junior Poster

Hi.

I recommend you to install all-in-one package :

Windows : WAMP or XAMPP
MacOS : MAMP

- Mitko Kostov

MitkOK 61 Junior Poster

You can try Notepad++, PSPad, Eclipse and SciTE - all free.

- Mitko Kostov

MitkOK 61 Junior Poster

This time for real :twisted: ?

Pleased to meet you, Osiris Elf Sky .

PS:

Hey, don't oppress me with your gender politics.

:icon_lol: :icon_lol: :icon_lol:

MitkOK 61 Junior Poster
MitkOK 61 Junior Poster

Sessions ?

- Mitko Kostov

MitkOK 61 Junior Poster

Hello. Welcome to DaniWeb ;)

MitkOK 61 Junior Poster

foreach()

- Mitko Kostov

MitkOK 61 Junior Poster

Welcome to DaniWeb :)


- Mitko Kostov

MitkOK 61 Junior Poster

^
Very helpful

MitkOK 61 Junior Poster

Or may be you can ;)

$query = "UPDATE company SET `references` = 'blahblahblah' where username = 'company'";

PS: Pay attention to the quotes ...


- Mitko Kostov

MitkOK 61 Junior Poster

Hi.

I'm learning now CakePHP and I'm writing basic login script.
So when I log ( validate username and password ) I want to
print a message and after 5 seconds to redirect to index.

I use $this->flash('Login successfull', '/users/index', 5); but
won't work ;(

Ideas ?

Thanks in advance.

- Mitko Kostov

MitkOK 61 Junior Poster

My name is Huggy Bear :)

christina>you commented: cute. :) +14