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 :)
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 :)
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.
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.
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;
?>
You are welcome! ;)
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
}
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;
?>
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..
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.
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.
So, the problem is solved now ?
$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 :)
I tried microChat from hotscripts and its simple. :) Maybe, you want to give it a try ?
umm.. there are few bugs in the application, but, its working..
Yep. See here, Kkeith29 has done something like that.
http://www.daniweb.com/forums/thread126462.html
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.
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
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.. :)
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.
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.
Sorry ! I don't know much about ajax+xml. Maybe you will understand what he's saying.
Check this out.
http://james.revillini.com/2006/10/27/no-element-found-in-firebug-or-firefox-javascript-console/ and
http://james.revillini.com/2006/10/27/%E2%80%98no-element-found%E2%80%99-in-firebug-or-firefox-javascript-console-part-2/ All the best!
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).
:) Welcome!
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 ?
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..
Umm.. Let me get something clear.. You want to delete only the records where the usern field has the value "caughtusername". Right ?
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!
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!
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 ?
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.
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 />
$LETTER = $_GET;
should be
$LETTER = $_GET['LETTER'];
P.S. using uppercase for variable names is not preferred by most programmers :)
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
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.
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))";
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 ;)
Yeah.. I am 100% sure..
Return ValuesFor 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 ?
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 :)
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 ?
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
$tablename = "test";
$query = "create table ".$tablename." (name varchar(200) not null )";
mysql_query($query);
Like this.
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.
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.
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.
Yep.. :)
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 ?
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
}