nav33n 472 Purple hazed! Team Colleague Featured Poster

How do you determine which value in $data to be inserted into which column ?

nav33n 472 Purple hazed! Team Colleague Featured Poster

phpmyadmin is an application to manage mysql databases just like mysql query browser :)

nav33n 472 Purple hazed! Team Colleague Featured Poster

There is something wrong with your insert query. You can try it this way. insert into tablename (col1, col2, col3, ..) values ('val1','val2','val3',...) .
Also, you can execute this query in phpmyadmin to see if it executes without any error. :)

nav33n 472 Purple hazed! Team Colleague Featured Poster

; Temporary directory for HTTP uploaded files (will use system default if not
; specified).
upload_tmp_dir = "c:/wamp/tmp"

I don't know whats the system default tmp folder. But I would suggest you to create a temporary folder with all the permissions. Did you print the query ? What does it print ?

nav33n 472 Purple hazed! Team Colleague Featured Poster

Yep. I am trying to upload a file. It doesn't really matter what you do with the uploaded file. You can either upload/store it on the file system or open it and process the data in the file. I believe the problem is with the query and not the file upload.
Btw, check if you have specified a tmp folder path (upload_tmp_dir) in php.ini .

nav33n 472 Purple hazed! Team Colleague Featured Poster

I checked your code, replaced your query with move_uploaded_file. It worked fine. I believe something is going wrong in the insert query. Print out the query, remove @ from mysql_query, use die(mysql_error()); . Everything else seems fine.
Here is the edited code. Try it out. If it uploads the file, then you know where the problem is!

<tr>
    <td colspan="6">
		  	<form action="<? echo $_SERVER['REQUEST_URI']; ?>" enctype="multipart/form-data" method="post">
				<table>					
				  <tr>
					  <td>
					      <p align="left"><span class="style4 style25 style28">Bill Uploader</span></p>
					      <p align="left"><span class="style21 style29">The Bill Uploader works in 2 steps.</span></p>					  </td>
				  </tr>
   				  <tr><td><p>&nbsp;</p></td></tr>
				  <tr>
				  	<td>
				      <table width="950" border="0" align="center" cellpadding="1" cellspacing="0" >
						<tr>
						  <td><p>&nbsp;</p></td>
						  <td colspan="4" bgcolor="#006600">
						  	<p align="left" class="style32">
						  <span class="style21  style33">Step 1: Browse for file</span></p>						  </td>
						  <td><p>&nbsp;</p></td>
						</tr>
						<tr>
						  <td><p>&nbsp;</p></td>
						  <td bgcolor="#006600"><p>&nbsp;</p></td>
						  <td width="125" bgcolor="#006600" scope="row"><div align="left" class="style13 style29 style31">Browse</div></td>
						  <td width="356" bgcolor="#006600">
						  	<div align="left">
								<strong>
									<input type="file" name="file" />
								</strong>							</div>						  </td>
						  <td bgcolor="#006600"><p>&nbsp;</p></td>
						  <td><p>&nbsp;</p></td>
						</tr>
						<tr width="950">
						  <td><p>&nbsp;</p></td>
						  <td colspan="4" bgcolor="#006600">
						  	<p align="left"><strong>
							  <span class="style21 style30">Step 2: Upload the file selected</span></strong></p>						  						  </td>
						  <td><p>&nbsp;</p></td>
						</tr>
						<tr>
						  <td><p>&nbsp;</p></td>
						  <td bgcolor="#006600"><p>&nbsp;</p></td>
						  <td bgcolor="#006600"><p>&nbsp;</p></td>
						  <td bgcolor="#006600">
						  <div align="left">
						  	<strong>
					      		<input type="submit" value="Upload" name="btnSubmit" />
						  	</strong>						  </div>  						  </td>
						  <td bgcolor="#006600"><p>&nbsp;</p></td>
						  <td><p>&nbsp;</p></td>
						</tr>
					  </table>  				    </td>
				</tr>
			</table>
		</form>	</td>
  </tr>
  <tr>
  	<td colspan="6" >
		
	  <div align="left" class="style29">
		<?
		/*
			include ("./connect.php");
			global $conn;
		*/
			ini_set("display_errors", "1");
			error_reporting (E_ALL);
			
			if(count($_FILES) > 0)
			{
					$ext = "";
				$ext = substr(trim($_FILES["file"]["name"]), -4);
				$allowedext = array(".txt", ".csv", ".sql");
				
				if(in_array($ext, $allowedext))
				{
					$filename = $_FILES['file']['tmp_name'];
					
					/*
					//$fh = fopen($_FILES['file']['tmp_name'], 'r');
					$handle = fopen($filename, "r");
					
					while (($data = fgetcsv($handle, 100000, ',', …
nav33n 472 Purple hazed! Team Colleague Featured Poster

Okay ! I did a quick test. I changed post_max_size to 80M and upload_max_filesize to 80M. I could upload a file of size 40mb (I didn't try 80mb!).

Upload: Toss the feather.divx
Type: video/divx
Size: 41345.8066406 Kb
Temp file: C:\wamp\tmp\php29.tmp
Stored in: upload/Toss the feather.divx

Maybe, You are using something like this ? <input type="hidden" name="MAX_FILE_SIZE" value="100000" />

nav33n 472 Purple hazed! Team Colleague Featured Poster

And also, there is no guarantee that the active members of a forum knows everything.

nav33n 472 Purple hazed! Team Colleague Featured Poster

Why not decide what value to choose after you submit the page ? Check this for example.

<?php
if(isset($_POST['submit1'])) {
	print $_REQUEST['firstname'];
} 
if(isset($_POST['submit2'])) {
	print $_REQUEST['lastname'];
}
?>
<html>
<head>
<SCRIPT language="JavaScript">
function decide_action() {
x = document.pressed
	if (x == "First") 
		{
		myname =document.forms['frm1'].elements['firstname'].value;
		document.frm1.action ="test.php";		
		}
	else if (x == "Last") 
		{
		myname=document.forms['frm1'].elements['lastname'].value;	
		document.frm1.action ="test.php";
		}
}  	 
</SCRIPT>
</head>
<body>
<form method="post" name="frm1" onSubmit="javascript: decide_action();">
<input type="text" name="firstname"><br>
<input type="text" name="lastname"><br>
<INPUT TYPE="SUBMIT" name="submit1" onClick="document.pressed=this.value" VALUE="First">
<INPUT TYPE="SUBMIT" name="submit2" onClick="document.pressed=this.value" VALUE="Last">
</form>
</body>
</html>

If this isn't what you are looking for, then I am sorry ! I didn't get your question right.

nav33n 472 Purple hazed! Team Colleague Featured Poster

$result=mysql_query("SELECT * FROM artists_details, attendance WHERE ethnicity='maori' AND date='record_id' BETWEEN 'date1' AND 'date2'");

The query is wrong.
Try this.

$result=mysql_query("SELECT * FROM artists_details, attendance WHERE ethnicity='maori' AND date='record_id' and date BETWEEN 'date1' AND 'date2'");

You have to specify which column to check while using 'between' clause.

nav33n 472 Purple hazed! Team Colleague Featured Poster

Php has a default upload size of 2mb. You need to change your php.ini file to increase it.
This might be of some help!
http://us3.php.net/manual/en/ini.core.php#ini.post-max-size
http://us3.php.net/manual/en/ini.core.php#ini.upload-max-filesize
and
http://us3.php.net/features.file-upload

nav33n 472 Purple hazed! Team Colleague Featured Poster

shade out ? You mean read only ?
<input type="text" name="id" readonly>

nav33n 472 Purple hazed! Team Colleague Featured Poster

The code works fine for me :) See if you have created the folder and it has all the permissions !

nav33n 472 Purple hazed! Team Colleague Featured Poster

Everything is fine in the above posted code. The only line which gave me an error was this line. $ext = $this->getExtension($img_name); Remove $this and everything will work great !

Kavitha Butchi commented: thankyou fr ur time +1
nav33n 472 Purple hazed! Team Colleague Featured Poster
if(empty($_REQUEST['hiddenfieldname'])) {
echo "Blah";
} else {
echo $_REQUEST['hiddenfieldname'];
}

Like this ?

nav33n 472 Purple hazed! Team Colleague Featured Poster

I don't get it. Here is a simple example.

<?php
if(isset($_POST['submit'])) {
	print_r($_POST['check']);
}
?>
<html>
<body>
<form method="post" action="checkbox.php">
<input type="checkbox" name="check[]" value="1"> 1 <br />
<input type="checkbox" name="check[]" value="2"> 2 <br />
<input type="checkbox" name="check[]" value="3"> 3 <br />
<input type="checkbox" name="check[]" value="4"> 4 <br />
<input type="submit" name="submit" value="submit">
</form>
</body>
</html>
nav33n 472 Purple hazed! Team Colleague Featured Poster

Can you post your latest code ?

nav33n 472 Purple hazed! Team Colleague Featured Poster

$variable = $_POST['form_variable_name']; More about it here. http://w3schools.com/php/php_post.asp
You should sanitize user's input by using mysql_real_escape_string or addslashes .

nav33n 472 Purple hazed! Team Colleague Featured Poster

Well, when you submit the form, only the selected checkboxes will be posted to the next page. You can see what values are being posted by using print_r($_POST['checkboxname'] You can loop through $_POST (since that will be an array of checked values) and display the data however you want !

nav33n 472 Purple hazed! Team Colleague Featured Poster

Oh, You can access the values as $value = $_GET['variablename'] Don't forget to sanitize the user's input by using mysql_real_escape_string or addslashes.

nav33n 472 Purple hazed! Team Colleague Featured Poster

You can give print_r(objectname) to check what values does these variables hold and debug !

nav33n 472 Purple hazed! Team Colleague Featured Poster
update table set number=number+300 where condition;

You mean like this ?

Edit: Or are you talking about concatenation ?

update table SET number = concat( number, "00" ) WHERE condition; //this will concat 00 to the value in number field for that condition
kevin wood commented: extremely helpful all the time +1
nav33n 472 Purple hazed! Team Colleague Featured Poster

I haven't used PDO classes. But maybe a "return" in the connect function will do the trick ?

public function connect() {
$pdoConnect = new PDO($this->dsn, $this->username, $this->password);
return $this->connection = $pdoConnect;
}
nav33n 472 Purple hazed! Team Colleague Featured Poster

If only admin's details are stored in admin table, then you don't need to change anything. But if the table is used for all the users, then for relevancy, you can have your table name as users.
Why not make id of contacts table a foreign key ? So, for every row in contacts table, there exist a record in users table. Doing so, when you need to display the details of a particular user, you just need his id.

nav33n 472 Purple hazed! Team Colleague Featured Poster

Hi

I would like to put a list of ids in an array
and loop to select data from a table using
"IN" in the where clause.

I am not having any success getting this to work.
Any suggestions?

Note:I am using Mysql database, apache, linux/Windows

<?
//array with list of friends to display
$friend = array('1','2','3','4');

$query = "SELECT first, last, number
      FROM friend
      WHERE id IN '$friend'";
$result = mysqli_query($mysqli, $query);

end quote.

You can't do it this way because $friend is an array. So, when you execute the query, it will be,

$query = "SELECT first, last, number
      FROM friend
      WHERE id IN 'array'";

which is wrong. You can use implode function to join the array.

$friend_implode = implode(",",$friend);

Then use it in your query.

$query = "SELECT first, last, number
      FROM friend
      WHERE id IN (".$friend_implode.")";
nav33n 472 Purple hazed! Team Colleague Featured Poster

The simplest way to solve that error is to print out the query and execute it phpmyadmin / mysql console. You will know the exact problem. You can also try $result = mysql_query($query) or die (mysql_error()); to get the error message. Also, mysql_fetch_row should be used if you are using numeric index for your array. ie., $row[0], $row[1] and so on. If you want associated names, you should use mysql_fetch_array or mysql_fetch_assoc.

nav33n 472 Purple hazed! Team Colleague Featured Poster

Umm.. Why do you need a switch case ? Why not do it directly ?

if($percent > 0 && $percent < 20) { //show red image
} elseif ($percent > 20 && $percent < 50) {
 //show orange image
} elseif ($percent > 50 && $percent < 100) {
//show green image
} 
//... and so on

Your condition will not work because, $percent can have only 1 value. It can't be 1 as well as 10.

nav33n 472 Purple hazed! Team Colleague Featured Poster

What images ? You can use it in the 2nd foreach loop itself !

nav33n 472 Purple hazed! Team Colleague Featured Poster

Something like this.

foreach($options_array as $value) { 
 $query = "select count(*) as count from opt1 where ans = '$value'";
 $result = mysql_query($query);
 $row = mysql_fetch_array($result);
 $votecount[$value] = $row['count'];
}
$opsum=array_sum($votecount);
foreach($votecount as $key => $value) {	
	$perc=$value*100;
 	echo 'per of '.$key.' is:'.$perc.'<br>';
 	echo 'Total:'.$opsum.'<br>';
 	$percent=$perc/$opsum;
 	echo 'Percentage of '.$key .' is:'. $percent.'<br>';
}
nav33n 472 Purple hazed! Team Colleague Featured Poster

No.. Store count for every option in an array. By the end of the foreach loop, you will have an array with count of votes for each answer. You can then get the sum of votes, iterate through the array to get each vote count to calculate the percentage.

nav33n 472 Purple hazed! Team Colleague Featured Poster

Do array_sum($votecount) after foreach loop.

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

No. Put the options in an array. Iterate. eg.

$options_array = array("option1","option2");
$votecount = array();
foreach($options_array as $value) {
  $query = "select count(*) as count where opt1 = '$value'";
$result = mysql_query($query);
$row = mysql_fetch_array($result);
$votecount[$value] = $row['count'];
}
//by the end of this foreach loop, $votecount will have the the votes for each option. You can get the total by doing array_sum. Then again, iterate foreach $votecount value and find out the percentage.
nav33n 472 Purple hazed! Team Colleague Featured Poster
$query = "select count(*) as count from table where opt1 = 'Option 1'";
$result = mysql_query($query);
$row = mysql_fetch_array($result);
echo $row['count'];

Try this.

nav33n 472 Purple hazed! Team Colleague Featured Poster

You know what are the available options for voting.. Right ? Can't you store them in the table ? Counting them wouldn't be difficult.

$query = "select count(*) from table where opt1 =  'A'";

This will give you the number of votes for A.

nav33n 472 Purple hazed! Team Colleague Featured Poster

$_FILES

Shouldn't this be $_FILES :)

dottomm commented: Fantastic!!!! +1
nav33n 472 Purple hazed! Team Colleague Featured Poster

Since its a voting system, I guess you are having a radio button (or checkboxes). I also assume that you are saving pre-defined values in opt1 field. Count the number of votes for each option. Find the total and calculate the percentage.
votes for option A = 1
votes for option B = 4
votes for option C = 2
votes for option D = 3
Total votes = 10
Percentage of votes for A = 100/10 = 10%
Percentage of votes for B = 400/10 = 40%
... and so on..

nav33n 472 Purple hazed! Team Colleague Featured Poster

You need to store the values in a table when someone votes. In that way, a user can vote only once. Displaying the result in % can be done by simple math calculation. I haven't worked with images, so, I am not very sure about graphs.

nav33n 472 Purple hazed! Team Colleague Featured Poster

http://nl2.php.net/language.variables.variable
I don't prefer using this because its too difficult to keep track of what is in $var. If something goes wrong in the script, for example, $var is empty, then that will cause a total failure.

nav33n 472 Purple hazed! Team Colleague Featured Poster

Umm..

if($row['col1'] == "2008") {
//print
} //else do nothing

If the record in the table has more than 2008, for example, some text with it, you can try it this way.

<?php
$str = "test - 2008 is as boring as 2007";
if(strstr($str,"2008")) {
	echo "2008 found!";
} else {
	echo "2008 not found!";
}
?>
OmniX commented: Always helpful as usual :) +1
nav33n 472 Purple hazed! Team Colleague Featured Poster

Yes. It displays everything it fetches for that particular id. You can limit your output by choosing what to print. As you can see, $row is an array. $row will have 7, $row will have "Ecuador offers to buy out oil companies" and so on.. Check this out.
http://nl3.php.net/mysql_fetch_array
This is how you can print only newsTit value.

//news.php
//db connection
$id = mysql_real_escape_string($_GET['id']);
$query = "select * from newstable where id = '$id'";
$result = mysql_query($query);
$row = mysql_fetch_array($result);
print $row['newsTit'];
?>
peter_budo commented: Good work, well done +8
nav33n 472 Purple hazed! Team Colleague Featured Poster

Change the table name (and column name) !

nav33n 472 Purple hazed! Team Colleague Featured Poster

In news.php, request id's value and fetch the data from the table for that particular id.
For example, news.php?id=4

//news.php
//db connection
$id = mysql_real_escape_string($_GET['id']);
$query = "select * from newstable where id = '$id'";
$result = mysql_query($query);
$row = mysql_fetch_array($result);
print_r($row); //display the news for id = 4
?>
nav33n 472 Purple hazed! Team Colleague Featured Poster

$level = $_SESSION;
$_SESSION["level"] = 1;
$_SESSION["level"] = 2;
$_SESSION["level"] = 3;

You are assigning 1, 2, 3 to $_SESSION. In the end, the value in $_SESSION would be 3. Here is a simple example.

//test.php
<?php
$value = 100;
if($value < 100 ) {
   $_SESSION['level'] = 1;
} elseif ($value == 100 ) {
    $_SESSION['level'] = 2;
} else {
    $_SESSION['level'] = 3;
}
include "check.php";
?>

And this is check.php

<?php
session_start();
echo $_SESSION['level'];
?>

This is just an example to show you how sessions work.

nav33n 472 Purple hazed! Team Colleague Featured Poster

Try this.

echo'<input name="tradeaid" type="hidden" id="tradeaid" value="'.$tradeaid.'">';
echo'<input name="mtitle" type="hidden" id="mtitle" value="'.<$mtitle.'">';
echo'<input name="nmain" type="hidden" id="nmain" value="'.nmain.'">';
echo '<tr><td width="90% align=left"><a onclick="submit();">'. $stitle. '</s></td></tr>';

I think its a bad practice to use <?=$varname instead of <?php echo $varname; ?>

Edit: And please use code tags while posting your code. It really helps.

nav33n 472 Purple hazed! Team Colleague Featured Poster

echo'<input name="tradeaid" type="hidden" id="tradeaid" value="<?=tradeaid?>">';
echo'<input name="mtitle" type="hidden" id="mtitle" value="<?=mtitle?>">';
echo'<input name="nmain" type="hidden" id="nmain" value="<?=nmain?>">';

missing $ in the values.

nav33n 472 Purple hazed! Team Colleague Featured Poster

$level = 1 isn't correct. Since you are comparing the value of $level, you need to use comparison operator. http://nl.php.net/operators.comparison
Secondly, where are you assigning the value to $_SESSION ? I think the value is being overwritten or something. Btw, there is no session_start() in check.php. When you assign the value to the session variable, check whats in it. In check.php, check print out the session variable value and cross check !

nav33n 472 Purple hazed! Team Colleague Featured Poster

What's the structure of the table ?

nav33n 472 Purple hazed! Team Colleague Featured Poster

Order by multiple columns work this way.
For example, you have 4 records.

field1 | field2 | field3 | field4
-------+-------+--------+----------
1 | 1 | 2 | 4
-------------------------------------
2 | 2 | 100 | 5
-------------------------------------
3 | 2 | 1 | 3
-------------------------------------
4 | 3 | 500 | 6
-----------------------------------
5 | 2 | 1 | 2

If your query is,

$query = "select * from table order by field2,field3,field4";

the result would be,

field1 | field2 | field3 | field4
-------+-------+--------+----------
1 | 1 | 2 | 4
-------------------------------------
5 | 2 | 1 | 2
---------------------------------------
3 | 2 | 1 | 3
-------------------------------------
2 | 2 | 100 | 5
-------------------------------------
4 | 3 | 500 | 6
-------------------------------------

As you can see, it sorts field2 first. Then it sorts field3 maintaining the order of field2. Then maintaining the order of field2 and field3, it sorts field4.

I know my explanation isn't really good ! (Or is it more confusing ?)

Note: If you don't specify how you want to sort your records, it will sort in ascending order by default.

nav33n 472 Purple hazed! Team Colleague Featured Poster

Heh.. maybe "c" and "d" are varchar fields and the rest are integer fields ? Simplest way to debug this problem is to print out the query and see what does it have at the runtime. Then execute it in phpmyadmin or mysql console. Doing so, you will know where exactly is the error.
Note: Varchar fields need to be wrapped within single quotes while integer fields dont need single quotes.