nav33n 472 Purple hazed! Team Colleague Featured Poster

Well, rgviza is saying, instead of having id in the action, pass the value of id in a hidden field. Access id value as $_POST instead of $_GET.
ie.,
instead of <form method="post" action="test.php?id=1"> do,

<form method="post" action="test.php">
<input type="hidden" name="id" value="1">

:)

nav33n 472 Purple hazed! Team Colleague Featured Poster

Heh.. Great ! Congrats..

nav33n 472 Purple hazed! Team Colleague Featured Poster

You missed out ''. Use this query instead.

$q2 = "UPDATE Operators SET accessLevel='".$accessType."' WHERE EmployeeID =".$empnumber;
maydhyam commented: This guy definitely knows his stuff... +1
nav33n 472 Purple hazed! Team Colleague Featured Poster

Hmm.. Print out the query again.. And also, putting print_r($_POST); (on top of the page) helps alot while debugging.

nav33n 472 Purple hazed! Team Colleague Featured Poster

Its $level == "1" and so on.. And why not use just if conditions ? ie.,

$level = $_SESSION['level'];
if ($level == "1") {
  include "page_1.php";
}
if($level == "2") {
  include "Page_2.php";
} 
//and so on..
nav33n 472 Purple hazed! Team Colleague Featured Poster

Also, in check.php, don't forget to assign $_SESSION value to $level.

nav33n 472 Purple hazed! Team Colleague Featured Poster

Okay.. Where are you setting a value to $level ?

nav33n 472 Purple hazed! Team Colleague Featured Poster

Heh! I tested it before posting it here and I am 200% sure it will work..

OmniX commented: php guru once again :) +1
nav33n 472 Purple hazed! Team Colleague Featured Poster

<?php
if (level == "1") { include('page_1.php'); }
else
if (level == "2") { include('page_2.php'); }
else
if (level == "3") { include('page_3.php'); }
?>

Shouldn't level be $level ?

nav33n 472 Purple hazed! Team Colleague Featured Poster

I have a variable in a variable.

I have done this before but it is not working this time.

I have it in a for loop so my code is:

$abc1 = one;
 $abc2 = two;
 for($i = 0; $i < 2; $i++) {
  echo $$abc$i;  
 }

The out come should be "one two", correct?

The concept is correct? The code is correct? - to the best of my knowledge and references.

Any ideas? Thanks, Regards X.

The output will not be one two because $abc1 is one and not $abc0. Try this.

<?php 
$abc1 = "one";
 $abc2 = "two";
 for($i = 1; $i <= 2; $i++) {
  echo ${abc.$i}; //value of $i will be concatenated to string abc and then it will consider the whole as a variable  
 }
 ?>
nav33n 472 Purple hazed! Team Colleague Featured Poster

Okay! here is why it doesn't work. First of all, you are calling the function validatedata() in searchuser.php. This function will call the function confirmdata passing empno as a parameter. You fetch the record for that particular empno and display it along with some elements like select box. And,

$accessType=$_POST;

print("<td><input id='upDate' name='upDate' type='submit' value='Update' /></td></form>");
$upDate = $_POST;
print("<td><font face='verdana' size='2'><center><a href=\'update.php?EmployeeID='.$myrow[0].' />Update</a></center></font></td>");
print("<td bgcolor='red'>");
$empNum = $myrow[0];
echo $empNum;
print("</td>");

print("</tr></table></center>");
//print_r($_POST);
if($upDate=TRUE)
{
$q2 = "UPDATE Operators SET accessLevel=".$accessType." WHERE EmployeeID =".$myrow[0];
$result2 = mysql_query($q2, $conn) or die("Update not successful");
}

This part will not work because there is no function call after the page is submitted. Why not put this part somewhere else in the script ? I haven't tested this, but it should be something like this.

<?php

include("./connect.php");


if($_POST['upDate']) {
$accessType=$_POST['accesstype'];
$empnumber = $_POST['empnumber'];
 	$q2 = "UPDATE Operators SET accessLevel=".$accessType." WHERE EmployeeID =".$empnumber;
	$result2 = mysql_query($q2, $conn) or die("Update not successful");		
}


function confirmData($empNo)
{
   global $conn;
   $q = "SELECT EmployeeID, FirstName, LastName, Initials, username, accessLevel FROM Operators WHERE EmployeeID =".$empNo;
   $result = mysql_query($q,$conn);
   $myrow=mysql_fetch_row($result);
   if($result)
   {
      return 1; //Indicates empNo failure
   }
   else  
   {
	   echo"<tr><td>";
	   print("<center>
	   
	   		  <table border='1' width='900'>
				<tr align='center' bgcolor='#339900'>
					<td><font face='verdana' size='2' color='white'><b>Employee ID</b></font></td>
					<td colspan='2'><font face='verdana' size='2' color='white'><b>Name</b></font></td>
					<td><font face='verdana' size='2' color='white'><b>Initials</b></font></td>
					<td><font face='verdana' size='2' color='white'><b>Username</b></font></td>
					<td><font face='verdana' size='2' color='white'><b>Access Level</b></font></td>
					<td colspan='2'><font face='verdana' size='2' color='yellow'><b>Select Access to be Granted and Update-Option 1</b></font></td>
					<td colspan='2'><font face='verdana' size='2' …
nav33n 472 Purple hazed! Team Colleague Featured Poster

ah! cool..

nav33n 472 Purple hazed! Team Colleague Featured Poster

Okay.. So, it inserts a record to the table ? I don't understand the flow of your script, so I can't say much. But why do you have die(); at most places ? :-/

nav33n 472 Purple hazed! Team Colleague Featured Poster

Have you got it right already ? While inserting a record to a table, you follow this syntax.

$sql = "insert into table (column1,column2) values ('$value1','$value2')";

Its while updating, you use this syntax.

$sql = "update table set column1='$value1', column2='$value2' where id='$id'";
nav33n 472 Purple hazed! Team Colleague Featured Poster

I have already mentioned that problem.. the column count is 20 and the values you are trying to insert is 21.

I hope that fixes it :)

nav33n 472 Purple hazed! Team Colleague Featured Poster

No. If `id` is an autoincrement field, you don't have to do anything with it..

nav33n 472 Purple hazed! Team Colleague Featured Poster

Oh, and one more thing.. As far as I know, Its not a good practice to use - (hyphen) with names of the columns. Use underscore instead. You can use `` to mention the column name. For example,

$sql = "INSERT INTO trucks (`relpath-box1`, `relpath-box2`, `relpath-box3`, `relpath-primary`) values ('$value1','$value2','$value3','$value4')";

This has to work.. :)

nav33n 472 Purple hazed! Team Colleague Featured Poster

umm.. It has to.. I could see few errors. First one is, the column count is 20 and the values you are trying to insert is 21. second error is, first value should be $data[0] instead of data[0]

nav33n 472 Purple hazed! Team Colleague Featured Poster

Yep. The whole structure is fine.. Well, If you want, you can try out this simple example. Print $sql and execute it in mysql console. Also, try with mysql_query($query) or die (mysql_error()); You will know why the query failed.

nav33n 472 Purple hazed! Team Colleague Featured Poster

Oh, you can try one more thing.. wrap your values within single quotes. ie.,

$q2 = "UPDATE Operators SET accessLevel='".$accessType."' WHERE EmployeeID =".$myrow[0];

This will not give you any syntax error ( I am sure!).

Once you are done with it, check why $accessType isn't holding any values.

nav33n 472 Purple hazed! Team Colleague Featured Poster

He has declared the tid field as an integer and he is trying to pass it as a string. MySQL probably doesn't like it.

No.. That wouldn't be a problem.. You can pass an integer like a string, but not vice-versa.
I still believe its the form action which was causing the problem! :-/

nav33n 472 Purple hazed! Team Colleague Featured Poster

Yes. Tht might be because of this.

<select id='access' name=accessType width='15'>
$accessType=$_POST;

It should have been $_POST and you are trying with $_POST, which will be empty.

nav33n 472 Purple hazed! Team Colleague Featured Poster

Umm.. so, what was the error ?

nav33n 472 Purple hazed! Team Colleague Featured Poster

For example, you have this query.

$q2 = "UPDATE Operators SET accessLevel=".$accessType." WHERE EmployeeID =".$myrow[0];

You just have to echo it.

echo $q2;

Then you will have the query with dynamic variables.

nav33n 472 Purple hazed! Team Colleague Featured Poster

So, is your form action is like this ?

<form method="POST" action="reply.php?id=852"> 
</form>

If this is the case, then it should work fine. If not, then you should post your code..

nav33n 472 Purple hazed! Team Colleague Featured Poster

So, that's the problem..There is a syntax error somewhere.. Now, print the query and tell us what it says.. And also, execute it with dynamic variables..

nav33n 472 Purple hazed! Team Colleague Featured Poster

Hmm.. Does it give any error ? print out the query and see whats being passed as values..

$name=$_POST; //from the name form
$q_id=$_GET;

What method have you specified for the form ? POST or GET ?

nav33n 472 Purple hazed! Team Colleague Featured Poster

Umm.. I think you didn't get what I said.. Try wrapping the values in single quote.

$sql = "insert into table (column1,column2) values ('test1',''test2')";

Notice the values within quotes.

nav33n 472 Purple hazed! Team Colleague Featured Poster

Are you getting any error ? The only thing that might be wrong with the query is, not using ' ' while inserting a value to the varchar field. ie.,

$query = "insert into table (col1,col2) values ('test', 'test2')";
nav33n 472 Purple hazed! Team Colleague Featured Poster

Print the update query and see if it executes in phpmyadmin/mysql console. What do you get ? A result or an error ? You can also try $result = mysql_query($query,$conn) or die (mysql_error()); This will also give the error message about why the query failed![code=php]
$result = mysql_query($query,$conn) or die (mysql_error()); This will also give the error message about why the query failed!

nav33n 472 Purple hazed! Team Colleague Featured Poster

Yep. An array of checkboxes. When the user submits the form, only those checkboxes which were selected, will be posted. You can then build your query depending on the checkboxes the user selects. :)

nav33n 472 Purple hazed! Team Colleague Featured Poster

I don't know whats causing the error. You can run queries in a for loop. Once you have freed the result using mysql_free_result, that resource identifier is freed. Actually, if your query isn't too complicated, you don't have to use free_result as php frees the result at the end of execution of the script. Source: http://nl3.php.net/mysql_free_result

Can you post your code here ?

nav33n 472 Purple hazed! Team Colleague Featured Poster

Yeah.. You can store the description in whatever way you want..

nav33n 472 Purple hazed! Team Colleague Featured Poster

Yes. Using insert query you can insert anything, long text, short text, image, etc :)

What do you mean by describe it ?

nav33n 472 Purple hazed! Team Colleague Featured Poster

You are welcome.

No. You can't store a value in the table without using an insert query.

nav33n 472 Purple hazed! Team Colleague Featured Poster

Y/w. I ll be here.. ( I hope!)

nav33n 472 Purple hazed! Team Colleague Featured Poster

When you execute a query, a resource identifier will be assigned to $result. mysql_free_result will free this value.

nav33n 472 Purple hazed! Team Colleague Featured Poster
$q = "show tables";

I have 26 tables...shall i write all the names at once

$q="show a,b,c...z";

Show tables will get all the 26 tables (If you have 26 tables in the database) . Thats a mysql query.

nav33n 472 Purple hazed! Team Colleague Featured Poster

No. The code that I have given will search for all the tables in the database. (make sure you have only those tables in the database which you want to search). And what I mean by print your query is, echo $searchtables;
Tell us what it prints on the screen.

nav33n 472 Purple hazed! Team Colleague Featured Poster

Why ? print_r($arrayname) should work fine.

nav33n 472 Purple hazed! Team Colleague Featured Poster

Have you changed the column and table names to suit your requirements ? Print out $searchtables and tell us what it prints.

nav33n 472 Purple hazed! Team Colleague Featured Poster
<?php
$var = array( ); //declare an array
$query = "select * from table";
$result = mysql_query($query);
while($row = mysql_fetch_array($result)) {
  $var[] = $row['name']; //assign a value 
}
?>

Note: The code works even without declaring a variable as array.
But, you can't use a normal variable to act like an array. Example,

<?php
$x = 100;
$x[] = "10";
print $x;
?>
nav33n 472 Purple hazed! Team Colleague Featured Poster

Print the query and show us what it says..

nav33n 472 Purple hazed! Team Colleague Featured Poster

Basically, you need another table (comments) with columns to store who wrote the comment, on whose profile was the comment written and the comment. (You also may need more columns like date). I hope every user has a unique userid. Store the userids ("from" and "to" ) and comment in the table. Then while displaying the profile, check if there are any entries for this userid. If any rows found, display it.

nav33n 472 Purple hazed! Team Colleague Featured Poster

As you have already said it yourself, you don't have to explicitly declare a variable as an array to use it like an array. You can simply use $var[] = "value"; This will treat $var as an array. But, its always a good practice to initialize a variable before using it. (But most of them don't do it ;) )

nav33n 472 Purple hazed! Team Colleague Featured Poster

Umm.. Is this how you want your script to work ? The user can select different checkboxes and enter a search string next to the checkbox. Then when he clicks on search, It should return all the matching records ?

nav33n 472 Purple hazed! Team Colleague Featured Poster

You can do it this way.

<?php
$con = mysql_connect("localhost","root");
mysql_select_db("test");
//get all the tables from the database test
$q = "show tables";
$r = mysql_query($q);
$searchresult = array();
while($row = mysql_fetch_array($r)) {
	$table = $row[0]; // get the tablename
	$searchtables = "select * from ".$table." where col1 like '%".$searchstring."%'"; //search the table column for the search string
	$result = mysql_query($searchtables);
	while($rows = mysql_fetch_array($result)) {
		$searchresult[] = $rows['name'];
	}
}
// $searchresult will have all the records from all the tables for the searchstring
?>

Cheers,
Nav

nav33n 472 Purple hazed! Team Colleague Featured Poster

Awesome!

nav33n 472 Purple hazed! Team Colleague Featured Poster

Umm.. I haven't used crons.. But this can be of some use to you on how to run crons. http://www.modwest.com/help/kb5-125.html
Note: You need linux to run cron jobs.

nav33n 472 Purple hazed! Team Colleague Featured Poster

You can do it in 2 ways. Configure a cron job to run everyday at a certain time and send out mails if there are any records for that particular date. The other way is to write a script and execute it manually everyday.