nav33n 472 Purple hazed! Team Colleague Featured Poster
<?php
// open database connection code and then my code as follows

//$id = mysql_insert_id();  << This line wouldn't work ie., $id will be null because there isn't any insert statement before this function call. 

//$sql="INSERT INTO clients (clientID, firstname, surname, address1, address2, town,  postcode,  telephone, email, cardno, expirydate) VALUES ($id,'$_POST[firstname]','$_POST[surname]','$_POST[address1]','$_POST[address2]','$_POST[town]', '$_POST[postcode]','$_POST[telephone]','$_POST[email]','$_POST[cardno]','$_POST[expirydate]')";
//since clientID is an autoincrement field, you don't need to mention it. Use this query instead.
$sql="INSERT INTO clients (firstname, surname, address1, address2, town,  postcode,  telephone, email, cardno, expirydate) VALUES ('$_POST[firstname]','$_POST[surname]','$_POST[address1]','$_POST[address2]','$_POST[town]', '$_POST[postcode]','$_POST[telephone]','$_POST[email]','$_POST[cardno]','$_POST[expirydate]')";

if (!mysql_query($sql,$con))
  {
  die('Error: ' . mysql_error());
  }
$last_insert_client_id = mysql_insert_id();
//get previous insert statement's clientID

//$sql="INSERT INTO bookings (bookingID, clientID, roomID, startdate, enddate, adults, children, roomtype,  requirements) VALUES ($id, LAST_INSERT_ID(),'NULL','$_POST[startdate]','$_POST[enddate]','$_POST[adults]','$_POST[children]','$_POST[roomtype]', '$_POST[requirements]')";
$sql="INSERT INTO bookings (clientID, roomID, startdate, enddate, adults, children, roomtype,  requirements) VALUES ('$last_insert_client_id','NULL','$_POST[startdate]','$_POST[enddate]','$_POST[adults]','$_POST[children]','$_POST[roomtype]', '$_POST[requirements]')";

if (!mysql_query($sql,$con))
  {
  die('Error: ' . mysql_error());
  }
  $last_insert_booking_id = mysql_insert_id();
  //last insert statement's bookingID
  //$result = mysql_query("SELECT * FROM clients WHERE clientID=LAST_INSERT_ID()");
	//this also wouldn't work because LAST_INSERT_ID will give you the last inserted id of booking table.. Instead use this
	$result = mysql_query("SELECT * FROM clients WHERE clientID='$last_insert_client_id'");
	
  //$result = mysql_query("SELECT * FROM bookings WHERE bookingID=LAST_INSERT_ID()");
  //This will work but it will override the value stored in the variable $result. You should use a different variable. 
  $result1 = mysql_query("SELECT * FROM bookings WHERE bookingID='$last_insert_booking_id'");

echo "<table border='1'>
<tr>
<th>ID</th>
<th>Firstname</th>
<th>Lastname</th>
<th>address1</th>
<th>address2</th>
<th>town</th>
<th>postcode</th>
<th>telephone</th>
<th>email</th>
<th>Arrival</th>
<th>Departure</th>
<th>Adults</th>
<th>children</th>
<th>Room Type</th>
<th>Requirements</th>

</tr>";

while($row = mysql_fetch_array($result))
  {
  echo "<tr>";
  echo "<td>" . $row['clientID'] . "</td>"; …
HB25 commented: very very helpful +2
nav33n 472 Purple hazed! Team Colleague Featured Poster

last_insert_id() in mysql or mysql_insert_id() in php gets the value of the autoincrement field from the last insert query.
Eg.

//using mysql's LAST_INSERT_ID()
// considering clientID as auto increment - primary key
$add_to_client_query = "insert into client (name,age) values ('test','20')";
mysql_query($add_to_client_query);
$add_to_booking_query = "insert into booking (busname, totalseats,clientID) values ('Air bus','30',LAST_INSERT_ID())";
mysql_query($add_to_booking_query);
//using php's mysql_insert_id()
// considering clientID as auto increment - primary key
$add_to_client_query = "insert into client (name,age) values ('test','20')";
mysql_query($add_to_client_query);
$last_inserted_mysql_id = mysql_insert_id();
$add_to_booking_query = "insert into booking (busname, totalseats,clientID) values ('Air bus','30','$last_inserted_mysql_id)";
mysql_query($add_to_booking_query);

I hope thats clear ?

Cheers!

nav33n 472 Purple hazed! Team Colleague Featured Poster

In every page you use session variables, you should have session_start(). :)

theimben commented: Thanks :) +2
nav33n 472 Purple hazed! Team Colleague Featured Poster

You are welcome :)

nav33n 472 Purple hazed! Team Colleague Featured Poster

I am good OmniX! How are you ?

I don't think there is any decrypting script/function which you can download. They have mentioned how there can be a collision between 2 different strings giving out the same hash ! I tried to read some more about the same, but, everything is going right over my head :(
http://www.mscs.dal.ca/~selinger/md5collision/
http://www.unixwiz.net/techtips/iguide-crypto-hashes.html

Thank you for creating this thread.. I can spend the rest of the evening reading these links ;)

Will Gresham commented: Very interesting links +1
nav33n 472 Purple hazed! Team Colleague Featured Poster

if($filename!="NULL" || $filename!="FALSE" || $filename!="")

This must be

if($filename!=NULL && $filename!=FALSE && $filename!="")

In your example, you are checking if variable filename value is NULL or FALSE (which is wrong). And, you should use logical operator "and" instead of "or".

peter_budo commented: Nicely done ;) +15
nav33n 472 Purple hazed! Team Colleague Featured Poster
update journey j, passengers p, shuttle s set j.occupancy=j.occupancy - 1 where p.journey_id = j.id and s.id = j.shuttle_id and s.id = 1 and p.passenger_name='bill gates'

wouldn't this work ? Many people at my workplace avoid joins (they say its comparatively slower than normal queries).

stephen84s commented: Absolutely +6
nav33n 472 Purple hazed! Team Colleague Featured Poster

I prefer for each forum a man of forum each month, that's would be good idea

I don't think that is a good idea! It would be a herculean task for the committee to find one person in every community every month (not that there aren't enough people, but there aren't enough qualified ones)!

peter_budo commented: Correct +15
nav33n 472 Purple hazed! Team Colleague Featured Poster

@Rhyan, \n will return extra line breaks. For example, If the actual string is

ab
bc

\n will return

ab 

bc
Nick Evan commented: sounds right to me :) +14
nav33n 472 Purple hazed! Team Colleague Featured Poster

Umm.. Yeah, well, almost.. This looks good except the part where you insert string values to a varchar column of the table. Strings should be wrapped in ' single quotes.. So, pass the values accordingly.. ie.,

$obj_Connection = new Database();
$obj_Connection->getConnection();
$table = "food";
$columns = "type, calories";
$data = "[single_quote_here]'cake'[/single_quote], 1000";
$obj_Connection->insertToTable($table, $columns, $data);
$obj_Connection->closeConnection();

I hope you understood what I am talking bout.

Venom Rush commented: Thanks for the help. Really appreciate it ;) +2
nav33n 472 Purple hazed! Team Colleague Featured Poster

If you want to 'move' a column from one table to another table, both the tables should have a common column to link these 2 tables. First, as Vermadba has mentioned, you have to create a column called "id" in table_2 first. Then, update the second table's "id" column using joins.
For example,

update table_2,table_1 set table_2.id=table_1.id where table_1.counter = table_2.counter

This will update table_2's id column with id values of table_1.
Then delete the column "id" from table_1.
Cheers,
Nav

nav33n 472 Purple hazed! Team Colleague Featured Poster

Because you are using mysql_fetch_row and trying to use the associated name. Use mysql_fetch_array instead.

Scottmandoo commented: man you help me soo much, thanks. +1
nav33n 472 Purple hazed! Team Colleague Featured Poster

I am not sure if you can do that using joins. Join returns all the records which matches the condition. So, there is no way to find out which advertiser belongs to which category.

$query = "select id from category";
$result = mysql_query($query);
while($row = mysql_fetch_array($result)) {
    $categoryid = $row['id'];
  $query2 = "select * from advertisers where category_id='$categoryid' and active=1";
$result2 = mysql_query($query2);
if(mysql_num_rows($result2) > 0 ) {
echo "<h1>".$categoryid."</h1>";
  while($row2 = mysql_fetch_array($result2)) {
$advertisername = $row2['name'];
  echo "Advertiser is ".$advertisername;
}
} else {
 echo "No advertisers found for this category..";
}
}

This way, you can print Category first, then get all the advertisers for that category.

nav33n 472 Purple hazed! Team Colleague Featured Poster

Yap ! Change function name "final" to "finally" or something !

wussa commented: thanks wussa +1
nav33n 472 Purple hazed! Team Colleague Featured Poster
<?php
if(isset($_POST['check'])) {
	$host="localhost";
	$user="";
	$pass="";
	$dbid="upload";
	$link=mysql_connect($host,$user,$pass);
	mysql_select_db($dbid);
	$name = mysql_real_escape_string($_POST['name']);
	$password = mysql_real_escape_string($_POST['apass']);
	$result=mysql_query("select * from login where username='$name' and password='$password'");
	if(mysql_num_rows($result) > 0 ) {
		while($row=mysql_fetch_array($result))
		{
			$type=$row['usertype'];
		}
	}
	if($type==0) {
		header("location: uregister.php");
	} else {
		header("location: userlink.php");
	}
	mysql_close($link);
}
?>
<html>
<head>
<head>
<body>
<form method="post" action="login.php">
<table border=1>
<tr>
<td>
UserName</td><td><input type="text" name="name">

</td>
</tr>
<tr>
<td>
Password</td><td><input type="password" name="apass">
</td>
</tr>
<tr>
<td>
</td><td><input type="Submit" name="check" Value="Submit">
</td>
</tr>
</table>
</form>
</body>
</html>

This should work.

praveen_dusari commented: i am learning from u.thank u +1
nav33n 472 Purple hazed! Team Colleague Featured Poster

Yep. It will create a user called "naveen" with password "password1" and grant SELECT,INSERT,UPDATE,DELETE permissions for that user.

kevin wood commented: one of the most helpfull people i have come across +1
nav33n 472 Purple hazed! Team Colleague Featured Poster

Yep! it seems like a tough job for me!

nav33n 472 Purple hazed! Team Colleague Featured Poster

Eg. test1.php

<?php
session_start();
$array = array();
for($i=0;$i<5;$i++) {
$array[] = $i; //insert $i to an array
}
$_SESSION['array'] = $array; //assign $array to the session variable $_SESSION['array']
?>

test2.php

<?php
session_start();
$array = $_SESSION['array']; //assign $_SESSION['array'] to $array
foreach($array as $value) {
print $value; //print $array contents
}

P.S. Dude, don't you understand english ? How hard is it to use code-tags ?

R0bb0b commented: Hell ya dude! +1
nav33n 472 Purple hazed! Team Colleague Featured Poster

Then maybe something is wrong with your query.
I tried it and it worked !

SELECT uname,datej,curdate(),(YEAR(curdate())-YEAR(datej))-(RIGHT(curdate(),5)<RIGHT(datej,5)) AS age FROM members ORDER BY uname
Shanti C commented: smart answer +1
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

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

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

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
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

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

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

As I have shown you in my example, where I am assigning $row to $array (which is an array), you can do the same !
You can do,

function fetchAssoc($sql) {
$array = array();
while($row = mysql_fetch_assoc($sql)) {
$array[] = $row;
}
return $array;
}

Then iterate through $array.

OmniX commented: php guru to the rescue! +1
nav33n 472 Purple hazed! Team Colleague Featured Poster

How can you differentiate users ? I think you need 2 separate queries. One query to get all the user ids and in the while loop, have another query to calculate the time.

$query = "select distinct(userid) from table"; //query to each user's id
$result = mysql_query($query);

while($row  = mysql_fetch_array($result)) {
  $id = $row['userid'];
$total = 0;
 $query2 = "select * from table where userid = '$id'"; //query to get the relevant records of this user
$result2 = mysql_query($query2);
while($row2 = mysql_fetch_array($result2)) {
//display the records as you are doing now
//also calculate the total_time in this loop
$total = $total + $time; 
} //by the end of this loop, you will have $total (total time) for that particular user
echo "total : ".$total;
} //process next user

You can do it this way :)

kvdd commented: Again he did the job, in the topic: "Show a total in a while". Thanks! +1
nav33n 472 Purple hazed! Team Colleague Featured Poster
<?php
$time = "37:00";
list($hrs, $mins) = explode(":", $time);
$mins += $hrs * 60;
$endresult = $mins/5;
echo date("H:i",mktime(0,$endresult,0,0,0,0));
?>

Now ?

R0bb0b commented: Thankyou +1
kvdd commented: He gives me a complete solution, thanks nav33n! +1
nav33n 472 Purple hazed! Team Colleague Featured Poster
<html>
<head>
</head>
<body>
<script type="text/javascript" src="wz_tooltip.js"></script>
<script type="text/javascript" src="tip_centerwindow.js"></script>
<script type="text/javascript" src="tip_followscroll.js"></script>
<form method="post">
<select name="test">
<option value="1" onmouseover="Tip('Option 1');" onmouseout="UnTip();">1</option>
<option value="2" onmouseover="Tip('Option 2');" onmouseout="UnTip();">2</option>
<option value="3" onmouseover="Tip('Option 3');" onmouseout="UnTip();">3</option>
<option value="4" onmouseover="Tip('Option 4');" onmouseout="UnTip();">4</option>
<option value="5" onmouseover="Tip('Option 5');" onmouseout="UnTip();">5</option>
</select>
</form>
</body>
</html>

Works fine for <option> tag.

blufab commented: Rapid responder, with good input +2
nav33n 472 Purple hazed! Team Colleague Featured Poster

Put set_time_limit(0); on top of your script.
http://in.php.net/set_time_limit

maydhyam commented: Great Job.....Thanks :) +1
nav33n 472 Purple hazed! Team Colleague Featured Poster

I don't know what you mean by saving a php file. If you have installed apache, you can type http://localhost/php-file-name to execute your script.

Btw, If you are new to php, I would suggest you to install wamp . Wamp is a bundled package of php, mysql and apache. Just install it and start working !

Nick Evan commented: Good tip on Wamp! +6
nav33n 472 Purple hazed! Team Colleague Featured Poster

For "quick learning" you can start here . For php reference guide and detailed php functions description, you can check php.net ( http://www.php.net/manual/en/ )

sreein1986 commented: Thanx very much 4 ur quick reply +1
nav33n 472 Purple hazed! Team Colleague Featured Poster
<?php
$a = 1;
$b = 2;
$c = 3;
$alpha = $a." ".$b." ".$c;
echo $alpha;
//prints 1 2 3
echo "<br />";
list($a1,$b1,$c1) = explode (" ",$alpha);
echo $a1; //prints 1
echo $b1; //prints 2
echo $c1; //prints 3
?>

. is the concatenation operator not + !

OmniX commented: Spot on as usual ;) +1
nav33n 472 Purple hazed! Team Colleague Featured Poster

Select "I approve" to the respective post (and write some comments if you want to) and click on "Add to reputation".

tuse commented: Thanks! +1
nav33n 472 Purple hazed! Team Colleague Featured Poster

and a chisel.

chisel :-/ Why ?

scru commented: It's a trade secret. +3
nav33n 472 Purple hazed! Team Colleague Featured Poster

Umm.. A cup of coffee and a cigarette :)

Ezzaral commented: Breakfast of champions :) +9
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

Mark inappropriate threads (like this one) as "Bad post". Moderators will take care of these ad guys! ;)

peter_budo commented: Yes, we do take care of such things ;) +8
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

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

$_FILES

Shouldn't this be $_FILES :)

dottomm commented: Fantastic!!!! +1
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

Can you be more specific ?

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

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

;)

tefflox commented: Not even the MySQL.com would help. nav33n is awesome. +2