nav33n 472 Purple hazed! Team Colleague Featured Poster

Hi Nav,

Sorry, I am not in PHP, I work in ASP.
These days I am learning PHP, so I don't know much about php.ini file.

Ah! I see.. Btw, Good work with your script :)

nav33n 472 Purple hazed! Team Colleague Featured Poster

The problem is I am not getting any error, its running smooth on my system.

Which OS u r using?

Its not OS dependent. Go to php.ini and search for ; Error handling and logging ;, and use this.
error_reporting = E_ALL & ~E_NOTICE & ~E_STRICT This will show all errors except notices.

nav33n 472 Purple hazed! Team Colleague Featured Poster

Notice: Undefined variable: a_img in E:\web\test\photoalbum.php on line 39

Either turn off notices or initialize your variables before using them. This way, one can avoid notices.

nav33n 472 Purple hazed! Team Colleague Featured Poster

If you use print_r for an array, thats how it prints. You can't do much about it. But you can use foreach to use the array as you want it.
Example,

<?php
$x = array("teacher"=>"10","student"=>"20");
$y = array("teacher"=>"30","student"=>"40");
$z = array("teacher_no_id"=>$x,"teacher_no_name"=>$y);
foreach($z as $key => $value) {
	$output.="Main array index ".$key." -> <br />";
	foreach($value as $newkey => $newvalue) {
		$output.="Sub array index ". $newkey." -> Sub array value ".$newvalue."<br />";
	}
	$output.="<br />";
}
echo $output;
?>
nav33n 472 Purple hazed! Team Colleague Featured Poster

You are welcome! ;)

nav33n 472 Purple hazed! Team Colleague Featured Poster

Instead of

$test="<table border=1><tr><td>Cell 1</td><td>Cell 2</td></tr></table>";

fetch the data from the database and use it.

$text = "Name \t Age \n"; //header
while($row = mysql_fetch_array($result)) {
 $text.=$row['name']."\t".$row['age']."\n"; //records
}
nav33n 472 Purple hazed! Team Colleague Featured Poster

If you have the a working example of exporting mysql data to excel I would appreciate that.

A simple example.

<?php
$file="test.xls";
$test="<table border=1><tr><td>Cell 1</td><td>Cell 2</td></tr></table>";
header("Content-type: application/vnd.ms-excel");
header("Content-Disposition: attachment; filename=$file");
echo $test;
?>
R0bb0b commented: Even works for open office, right on! +1
nav33n 472 Purple hazed! Team Colleague Featured Poster

Are you storing these courses in a table ?

Excel 2003 Level 1
Excel 2003 Level 2
Excel 2003 Level 3
Excel 2007 Level 1

If yes, then, just pass the id of the clicked course in the query string of the popup, query the table and fetch the relevant course. If the courses are hardcoded, then put the courses in a session array variable. For the hyperlink of courses, use the index of this array and pass it in the query string.
Simple example.

//test.php
<?php
session_start();
$courses = array();
$courses[]="course1";
$courses[]="course2";
$_SESSION['courses'] = $courses;
foreach($courses as $key => $courses_offered) {
	echo "<a href='popup.php?courseid=".$key."'>".$courses_offered."</a><br />";
}
?>

and this is popup.php

<?php
//popup.php
session_start();
$courseid = $_REQUEST['courseid'];
$courses = $_SESSION['courses'];
echo $courses[$courseid];
?>

This is just a simple example to show how you can do it..

nav33n 472 Purple hazed! Team Colleague Featured Poster

Well, then you have to pass the array as a hidden form element. But if the user uses back button, then the chances of these values getting 'lost' is more.

nav33n 472 Purple hazed! Team Colleague Featured Poster

Have an array, put the question numbers (or ids) you have viewed in the array. Keep the array in the session. Display last 4 questions using the last 4 indexes of the array.

nav33n 472 Purple hazed! Team Colleague Featured Poster

Use mysql_real_escape_string for user inputs, If the input is an integer, check it with intval.

nav33n 472 Purple hazed! Team Colleague Featured Poster

So, the problem is solved now ?

nav33n 472 Purple hazed! Team Colleague Featured Poster

$pet_list = mysql_fetch_assoc(mysql_query("SELECT * FROM ".$db_prefix."uberpets_pet_species"));

This will definitely return 1 record.

$result = mysql_query("SELECT * FROM ".$db_prefix."uberpets_pet_species");
while($row = mysql_fetch_assoc($result)) {
$pet_list[] = $row;
}

Notice the use of while :)

nav33n 472 Purple hazed! Team Colleague Featured Poster

I tried microChat from hotscripts and its simple. :) Maybe, you want to give it a try ?

nav33n 472 Purple hazed! Team Colleague Featured Poster

umm.. there are few bugs in the application, but, its working..

nav33n 472 Purple hazed! Team Colleague Featured Poster

Yep. See here, Kkeith29 has done something like that.
http://www.daniweb.com/forums/thread126462.html

nav33n 472 Purple hazed! Team Colleague Featured Poster

Maybe I didnt explain well my problem.

I am using some little cookies, where I store a user information for example: nickname and password. that is working ok. After a user signs out, these cookies will be deleted.
So if the user tries to create another account from the same computer I cant stop that. this is the problem.

I want to store some extra information in cookies that will notice the user and will not let him to create more than one account.

So can anyone give me a solution?

That is simply not possible. Oh, it is possible if everyone starts using static IP. You can log the IP in a table and cross check whenever a user tries to create an account. (Mind you, Its possible only if everyone has a static IP!). Btw, its a bad idea to let the user create only 1 account. What if everyone in the family wants an account ?
:) As Rob has suggested, check for existing username or email id while registration.

nav33n 472 Purple hazed! Team Colleague Featured Poster

Is it even possible without ending the identifier.

<?php
echo <<<HEREDOC
<div>
HEREDOC;
if($i==2) {
echo <<<HEREDOC
$i is 2
</div>
HEREDOC;
}

I think this is the only possible way. I hope I am wrong. :)
Cheers,
Naveen

nav33n 472 Purple hazed! Team Colleague Featured Poster

Thanks vicky_rawat, for the reply,
BUT it is still not working, I don't know what to do?

I tried vicky_rawat's code and it works perfectly fine.. :)

nav33n 472 Purple hazed! Team Colleague Featured Poster

mysql_connect error is because the user gave wrong credentials to connect to the database.
Its not possible to call a php function or a mysql query with "onclick" event. As others have mentioned already, you can use ajax or pass the id of the record in the anchor tag and then do relevant operation.

Kavitha Butchi commented: ok, thank you fr ur time. +1
nav33n 472 Purple hazed! Team Colleague Featured Poster

like

//...database connections...
<a href=mysql_query("DELETE FROM example WHERE age='15'")>delete</a>

something like that which works..where everything is coded in a single page rather than passing it over to the other page.

AFAIK, Its not possible.

nav33n 472 Purple hazed! Team Colleague Featured Poster
nav33n 472 Purple hazed! Team Colleague Featured Poster

Yeah sure.

<?php
$fileatt = ""; // Path to the file
$fileatt_type = "application/octet-stream"; // File Type
$fileatt_name = ""; // Filename that will be used for the file as the attachment

$email_from = ""; // Who the email is from
$email_subject = ""; // The Subject of the email
$email_txt = ""; // Message that the email has in it

$email_to = ""; // Who the email is too

$headers = "From: ".$email_from;

$file = fopen($fileatt,'rb');
$data = fread($file,filesize($fileatt));
fclose($file);

$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";

$headers .= "\nMIME-Version: 1.0\n" .
"Content-Type: multipart/mixed;\n" .
" boundary=\"{$mime_boundary}\"";

$email_message .= "This is a multi-part message in MIME format.\n\n" .
"--{$mime_boundary}\n" .
"Content-Type:text/html; charset=\"iso-8859-1\"\n" .
"Content-Transfer-Encoding: 7bit\n\n" .
$email_message . "\n\n";

$data = chunk_split(base64_encode($data));

$email_message .= "--{$mime_boundary}\n" .
"Content-Type: {$fileatt_type};\n" .
" name=\"{$fileatt_name}\"\n" .
//"Content-Disposition: attachment;\n" .
//" filename=\"{$fileatt_name}\"\n" .
"Content-Transfer-Encoding: base64\n\n" .
$data . "\n\n" .
"--{$mime_boundary}--\n";

$ok = @mail($email_to, $email_subject, $email_message, $headers);

if($ok) {
echo "<font face=verdana size=2>The file was successfully sent!</font>";
} else {
die("Sorry but the email could not be sent. Please go back and try again!");
}
?>

Just specify the filepath, filename and filetype (and ofcourse, from, to address).

nav33n 472 Purple hazed! Team Colleague Featured Poster

:) Welcome!

nav33n 472 Purple hazed! Team Colleague Featured Poster
nav33n 472 Purple hazed! Team Colleague Featured Poster

Well, Thats because, $_SESSION['getdisplayname']=$displayname; is being set after you include/require outlineget.php . That is, $_SESSION is empty on the first run. So, outlineget.php will not display anything.

$conn=mysql_connect(".....") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db('db1') or die (mysql_error());

$displayname = $_SESSION;

$displayname is null here. The solution is to make sure $_SESSION has a value before you include outlineget.php.

I hope its pretty clear. Eh ?

Kavitha Butchi commented: thanx a ton , this simple analysis really solved my problem +1
nav33n 472 Purple hazed! Team Colleague Featured Poster

Then this will do the trick for you.

<?php
// connect (host, usr, and pwd are previously defined, correctly)
$cid = mysql_connect( $host, $usr, $pwd );

// get all columns from the table 'accounts', $db was previously defined (database name)
$query = "DELETE FROM accounts where usern='caughtusername'";
$result = mysql_db_query( $db, $query, $cid );
?>

Ofcourse, $db, $host,$usr and $pwd has to be defined..

nav33n 472 Purple hazed! Team Colleague Featured Poster

Umm.. Let me get something clear.. You want to delete only the records where the usern field has the value "caughtusername". Right ?

nav33n 472 Purple hazed! Team Colleague Featured Poster

Example,

<?php
session_start();
if($_SESSION['user'] == "admin") {
 echo "<a href=link.php?user=$username&hash=some_hash_to_check_a_valid_user> Click here </a>";
} 
?>

If the user is admin, then it will show the above link. Also, in link.php, have a security check to cross check if the user is really an admin!

nav33n 472 Purple hazed! Team Colleague Featured Poster

What exactly are you trying to do ? I mean, Do you have to show that message at the end ? ie., spared and deleted ?
If no, You can use the query,

$query = "delete from accounts where usern = 'caughtusername'";
mysql_query($query);

This will delete all the records from table accounts where usern is "caughtusername".
But, If you want to display that message, you can try this way.

$cid = mysql_connect( $host, $usr, $pwd );

// get all columns from the table 'accounts', $db was previously defined (database name)
$query = "SELECT * FROM accounts";
$result = mysql_db_query( $db, $query, $cid );

// run through each row looking for column 'usrn' with the value 'caughtusername'
while( $row = mysql_fetch_array($result)) {
	$username = $row['usern'];
	$id = $row['id'];
	if($username == "caughtusername") {
		$query = "DELETE  FROM accounts WHERE id=".$id;
		// execute the deletion statement
		$result = mysql_db_query( $db, $query, $cid );
		echo "<b>Deleted: </b>" . $username . "<br>";
	} else {
		echo "<b>Spared: </b>" . $username . "<br>";
	}
}

Give it a try and tell us if it works!

nav33n 472 Purple hazed! Team Colleague Featured Poster

What exception does it throw ? I don't see anything wrong with your script :S
Umm.. one question though. Why don't you query the table using the condition where usern="caughtusername"; and delete all those records ?

nav33n 472 Purple hazed! Team Colleague Featured Poster
nav33n 472 Purple hazed! Team Colleague Featured Poster

how would you reccomend cleaning it up.

Like this ?

$letter = $_GET['LETTER'];
if(!empty($letter)) {
$sql = "SELECT `EndowmentNumber`,`LotSize`,`Letter`,`Section`, `LotNumber`,`LotOwner`,`LastName`,`FirstName`,`MiddleInitial`, `MaidenName`,`Suffix`,`Born`,`Died`,`VeteranInfo`,`MiscInfo` FROM `BurialsTable` WHERE Letter='".$letter."' ORDER BY `Letter`, `LastName`, `FirstName`, `FirstName`, `Section`, `LotNumber` ";
}

This one query will do exactly what you are trying to do with so many conditions and queries.

nav33n 472 Purple hazed! Team Colleague Featured Poster

Simple..

$txtFname = isset($_POST['txtFname'])?$_POST['txtFname']:$contact['firstName'];
//if txtFname is set, then assign that value to $txtFname, else, assign $contact['firstName'] to $txtFname.

and then,

First Name: <input type="text" name="txtFname" value="<? echo $txtFname; ?>" /><br />
nav33n 472 Purple hazed! Team Colleague Featured Poster

$LETTER = $_GET;

should be

$LETTER = $_GET['LETTER'];

P.S. using uppercase for variable names is not preferred by most programmers :)

nav33n 472 Purple hazed! Team Colleague Featured Poster

Hmm.. Well, Thats because the limits are not being set properly.

if ($_GET[pg]==0)  $pg = 1;
  $lines = (int)$lines;
  if ($lines==0)  $lines = 5;
  $left_limit = ($_GET[pg]-1)*$lines;

This block of code is the one causing you the problem. :) If you are in page1, $_GET will not be set (ie., it will be null and not 0). I can't guarantee you that this will work, but you can try this.

if ($_GET['pg']=="" || $_GET['pg']==0){
     $pg = 1;
} else {
  $pg = $_GET['pg'];
}
  $lines = (int)$lines;
  if ($lines==0) {
    $lines = 5;
  }
  $left_limit = ($pg-1)*$lines;

:) Cheers,
Naveen

Cobber commented: Fixed my problem +4
nav33n 472 Purple hazed! Team Colleague Featured Poster

The 1st warning,

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/ozwww04/public_html/auction/yourfeedback.php on line 65

is because of this query.

SELECT f.*,a.title FROM PHPAUCTIONXL_feedbacks f
      LEFT OUTER JOIN PHPAUCTIONXL_auctions a
      ON a.id=f.auction_id
      WHERE rated_user_id='$secid' 
      ORDER by feedbackdate DESC 
      LIMIT $left_limit,$lines

Right after this query, you have $res=mysql_query ($sql); Instead, use $res=mysql_query ($sql) or die (mysql_error()); You will see why you are getting the warning.

nav33n 472 Purple hazed! Team Colleague Featured Poster

Missing ending )
P.S. group is a keyword. Its not advisable to use keywords as column names.
This works fine for me.

$sql = "CREATE TABLE test.".$picurl ."
(name VARCHAR(200) NOT NULL ,
picurl VARCHAR( 200 ) NOT NULL ,
group1 VARCHAR( 200 ) NOT NULL ,
dateadded TIMESTAMP( 200 ) NOT NULL DEFAULT CURRENT_TIMESTAMP ,
id INT( 200 ) NOT NULL ,
PRIMARY KEY ( id ) ,UNIQUE (name ,picurl))";
nav33n 472 Purple hazed! Team Colleague Featured Poster

It doesn't matter if you have functions in a separate file and include it in the executing script.

Aaarghhhh ! :@ Do this.. I found the error !

function executequery($query) {
	$x = mysql_query($query) or die(mysql_error());
	return $x;
}

Assign mysql_query to a variable and return it. That works.. Indeed, return mysql_query($query) returns 1. :)

Edit : In my 1st example, I had assigned the value returned by mysql_query to a variable.. You missed it somehow ;)

OmniX commented: saved me again, thankyou :) +1
nav33n 472 Purple hazed! Team Colleague Featured Poster

Yeah.. I am 100% sure..


Return Values

For SELECT, SHOW, DESCRIBE, EXPLAIN and other statements returning resultset, mysql_query() returns a resource on success, or FALSE on error.

For other type of SQL statements, INSERT, UPDATE, DELETE, DROP, etc, mysql_query() returns TRUE on success or FALSE on error.

The returned result resource should be passed to mysql_fetch_array(), and other functions for dealing with result tables, to access the returned data.

Use mysql_num_rows() to find out how many rows were returned for a SELECT statement or mysql_affected_rows() to find out how many rows were affected by a DELETE, INSERT, REPLACE, or UPDATE statement.

mysql_query() will also fail and return FALSE if the user does not have permission to access the table(s) referenced by the query.

Source : http://in.php.net/mysql_query
You should get the desired output if you are using a simple select query. Well, what does your function queries return if you use update/delete query ?

nav33n 472 Purple hazed! Team Colleague Featured Poster

Yep. Thats the error. If you have update/delete/insert query, mysql_query will return 1 and its definitely not a valid resource. So, mysql_fetch_array / mysql_fetch_assoc wouldn't work. Try passing a select query to your function and see what it returns. It should return a resource :)

nav33n 472 Purple hazed! Team Colleague Featured Poster

You are passing a wrong value to the function. Are you sure you are passing the result you get when you use mysql_query ?
ie., $result = mysql_query($query); I really think you are doing something wrong right there (the function is fine though!)

Edit: Check your queryFunction. See what it returns. Maybe its returning a wrong value ?

nav33n 472 Purple hazed! Team Colleague Featured Poster
while($row = mysql_fetch_array($result)) {
 $array[] = $row['name']; // this will assign the values of only the column "name" to the array $array.
}

AND

while($row = mysql_fetch_array($result)) {
 $array[] = $row; //this will assign the array $row to the array $array. 
}

I don't understand what is not working and I don't see any problem.. :S

nav33n 472 Purple hazed! Team Colleague Featured Poster
$tablename = "test";
$query = "create table ".$tablename." (name varchar(200) not null )";
mysql_query($query);

Like this.

nav33n 472 Purple hazed! Team Colleague Featured Poster

No.. You are creating an alias for SUBSTRING_INDEX(tip, ' ',8) . Php parser will look for a column name and since you aren't specifying any, it will be empty.

SUBSTRING_INDEX(tip, ' ',8) as tip

This will return the result under "user defined" column name tip, so that php parser can access it.

antwan1986 commented: Very useful! +1
nav33n 472 Purple hazed! Team Colleague Featured Poster

Ah!!! You can do it this way.

$query = "SELECT SUBSTRING_INDEX(tip,' ',8) as tip  FROM tips";

This will solve your problem, I am sure.

nav33n 472 Purple hazed! Team Colleague Featured Poster

Hmm.. Execute the query

SELECT SUBSTRING_INDEX(tip,' ',8) FROM tips;

in phpmyadmin/mysql console and see if you get any output ! Maybe there are no records in the table with more than 7 spaces.

nav33n 472 Purple hazed! Team Colleague Featured Poster

Yep.. :)

nav33n 472 Purple hazed! Team Colleague Featured Poster
select SUBSTRING_INDEX(description," ",3) from table [where condition];

description = column name
" " = delimiter
3 = count
For example, if we apply the above query to the following text,

This is an example of substring_index.

it returns,

This is an

Umm.. Clear enough ?

nav33n 472 Purple hazed! Team Colleague Featured Poster

Instead of

if ($uname != $dbunames)

You can do,

if(mysql_num_rows($dbunames) > 0 ) { //check if there is already an entry for that username
 echo "Already taken";
} else {
//insert to table
}