nav33n 472 Purple hazed! Team Colleague Featured Poster

You are welcome :) Cheers!

nav33n 472 Purple hazed! Team Colleague Featured Poster

Okay.. This is a sloppy example, just to give you an idea.

<?php
if(isset($_POST['submit'])) {
	print "<pre>";
	print "Id array => <br />";
	print_r($_POST['id']);
	print "Order no array => <br />";
	print_r($_POST['orderno']);
	print "</pre>";
       for($i=0;$i< count($_POST['orderno']); $i++) { //there will be equal number of elements in both id array and orderno array. 
		echo $_POST['id'][$i]." -> ".$_POST['orderno'][$i]."<br />";
	}
}
?>
<html>
<body>
<form method="post">
<?php 
for($i=0;$i<5;$i++) {
?>
<input type='hidden' name='id[]' value='<?php echo $i; ?>'> 
Order <?php echo $i; ?>:<input type="text" name="orderno[]"><br />
<?php 
}
?>
<input type="submit" name="submit" value="submit">
</form>
</body>
</html>

Instead of for loop, you will have while($row = mysql_fetch_array($result)) . Instead of assigning $i as value to the hidden field, you will have the counter/id field of the table.
You can then map the values of the array entered by the user in the orderno field to id field.

nav33n 472 Purple hazed! Team Colleague Featured Poster

You need to mention http:// in your hyperlinks. See this for example.

<?php
echo "<a href='www.google.com'>Click here </a><br />";
echo "<a href='http://www.google.com'>Click here too</a>";
?>
nav33n 472 Purple hazed! Team Colleague Featured Poster

Yeah, possible. Have a hidden field in the form to store the id. When the user clicks submit, update the table :)

update table set orderno='".$_POST['orderno']."' where id='".$_POST['id']."'";
nav33n 472 Purple hazed! Team Colleague Featured Poster

I guess this can't be fixed (or so it seems!). No word from Dani so far.

nav33n 472 Purple hazed! Team Colleague Featured Poster

Nothing wrong with the script. Umm.. Check if it enters the loop, If (isset($_POST['submit'])) { .
Try mysql_error to know what exactly is the error message. ie.,

$sql = mysql_query("INSERT INTO accesscarduse (SchoolName, SchoolEmail, UserName, pscode) 
VALUES ('$SchoolName', '$SchoolEmail', '$UserName', '$pscode')") or die (mysql_error());

Also check if error reporting is turned on on your server.

nav33n 472 Purple hazed! Team Colleague Featured Poster

No. It doesn't work that way with torrents. Btw, Its a taboo subject to discuss it here. :)

nav33n 472 Purple hazed! Team Colleague Featured Poster

Great :) You are welcome!

nav33n 472 Purple hazed! Team Colleague Featured Poster

:) You are welcome!

nav33n 472 Purple hazed! Team Colleague Featured Poster

You can set up a cron job to run every day (or night) and have this query. If you can't have crons, you can run this script whenever the main page is loaded.

DELETE FROM Table
WHERE datecolumn < DATE(DATE_SUB(now() , INTERVAL 15 DAY))
nav33n 472 Purple hazed! Team Colleague Featured Poster

You can start with w3schools for basics. w3schools cover most of the things you need to know. For more information, you can check php.net .

P.S. In my earlier example, there is an extra " for input type=submit.

nav33n 472 Purple hazed! Team Colleague Featured Poster

:) You are welcome!

nav33n 472 Purple hazed! Team Colleague Featured Poster

sorry people - i thought i did use the tags but anyway thank you all for your replies - will play with it tomorrow

@phpNewbie, We aren't talking about you. Vinothkumarc didn't use [code] tags. Infact, I appreciate you for using code tags. :)

nav33n 472 Purple hazed! Team Colleague Featured Poster

Hmm.. There was a little mistake in that query. Here, this works fine.

select * from images where fbid IN (
select fbid
from rating
group by fbid
HAVING count( fbid ) > 150
)

Cheers!

nav33n 472 Purple hazed! Team Colleague Featured Poster

@cwarn23, mail function works fine in if condition. The mail function returns true on success and false on failure. It works just like, if(empty($var)) { @OP, check your spam folder. On many occasions, mails sent using php function lands up in spam folder!

nav33n 472 Purple hazed! Team Colleague Featured Poster

Simply use double quotes.
ie., $num="0024"; Adding 0 before a number forces php to consider this as a octal number.
http://us3.php.net/int

nav33n 472 Purple hazed! Team Colleague Featured Poster

hey... y u copied... and pasted without any comments (my code)

:icon_rolleyes:

nav33n 472 Purple hazed! Team Colleague Featured Poster

start quote:

<html>
    <head>
    </head>
    <body>
        <?php
            // MySQL Connection Information
            $server = "localhost";
            $username = "sharlene";
            $password = "";
            $dbname = "baby_names";

            // MySQL Connect String
            $connection = mysql_connect($server,$username,$password) or die("Can't Connect to Mysql Server: 

".mysql_error());

            // Select the database
            mysql_select_db($dbname) or die("Can't connect to database: ".mysql_error());

            $gender = mysql_real_escape_string($_POST['gender']);
            $meaning = mysql_real_escape_string($_POST['meaning']);
            $name = mysql_real_escape_string($_POST['name']);
            $origin = mysql_real_escape_string($_POST['origin']);
      if($gender) {
        $whereArr[] = "gender = '" . $gender . "' ";
      }
      if($name) {
        $whereArr[] = "name LIKE '" . $name . "%'";
      }
      if($meaning) {
        $whereArr[] = "meaning LIKE '%" . $meaning . "%'";
      }
      if($origin) {
        $whereArr[] = "origin = '" . $origin . "' ";
      }
      if(count($whereArr)) {
        $where = @implode(" AND ", $whereArr);
        $where = ' WHERE '.$where;
      }

$sql = "SELECT * FROM names $where";

/*
if ($gender == 'both') { // no specific gender
  if ($origin == 'any') { // no specific origin
    $sql = 'select * from names';
  else { // an origin was specified
    $sql = "select * from names where origin = '".$origin."'"; 
  }

else { // a gender was specified

  if ($origin == 'any') { // no specific origin
    $sql = "select * from names where gender ='".$gender."'";
  else { // an origin was also specified
    $sql = "select * from names where origin = '".$origin."' and  gender ='".$gender."'"; 
}
/**/

            //execute SQL query and get result
            $sql_result = mysql_query($sql, $connection) or die(mysql_error());

        ?>
            <table border="0" align="center">
                <tr>
                    <th style="background: #ffd" >Name</th>
                    <th style="background: #efe">Gender</th>
                    <th style="background: …
nav33n 472 Purple hazed! Team Colleague Featured Poster

Maybe this example will help you understand better.

<?php
if(isset($_POST['preview'])) {
	print "<pre>";
	print "Preview button pressed..<br>";
	print_r($_REQUEST);
	print "</pre>";
}
if(isset($_POST['submit'])) {
	print "<pre>";
	print "Submit button pressed..<br>";
	print_r($_REQUEST);
	print "</pre>";
}
?>
<form method='POST' action='postAd.php'>
<tr>
    <td width="26%" height="30" align="right"><font face="Calibri">Category:</font></td>
 	<input type="text" name="category" size="30"></td>
 
    <td width="26%" height="30" align="right"><font face="Calibri">City:</font></td>
 	<input type="text" name="city" size="30"></td>
    
	<td width="26%" height="30" align="right"><font face="Calibri">Ad Title:</font></td>
 	<input type="text" name="adTitle" size="30"></td>
 
 </tr>
</table>

<p align="center">
<input name="submit" type="submit" value="Submit""> 
<input name="preview" type="submit" value="Preview"">
</p>
</form>

I have named the buttons differently. I also don't need onclick events.

nav33n 472 Purple hazed! Team Colleague Featured Poster
select * from images where fbid IN (select fbid from ratings HAVING count(fbid) > 150 group by fbid)

The subquery returns fbid of all the records which has a count of 150+ . The main query returns all the records which matches these fbid.
Read more about having clause here.. http://www.techonthenet.com/sql/having.php

Not sure if this will work. If it doesn't, we ll try some other way :)
Cheers!

nav33n 472 Purple hazed! Team Colleague Featured Poster

What does your query do ? Query the table 'photos' and for every photo, You are again querying the table 'ratings' if that photo's fbid has a count > 150 ?
I didn't get the question or what you actually want. Do these 2 tables have any common 'linking' field ? What is fbid ?

nav33n 472 Purple hazed! Team Colleague Featured Poster
$services = implode(",",$_POST['service']);
//This will combine the array $_POST['service'] and form a string
Use it in $msg. 
$msg = $services." are the services which are checked\n";

Clear enough ?

nav33n 472 Purple hazed! Team Colleague Featured Poster

If the user has selected "All" or "any", exclude it from your query condition list. :-/
For example, If he search for "rent" and keeps district as "all" and price as "2 lakh", your query should look something like,

select * from table where `for`='rent' and price='2 lakhs'

I still don't understand how is this advance search. :)

nav33n 472 Purple hazed! Team Colleague Featured Poster

After

$result = mysql_query("SELECT * FROM clients WHERE clientID=$_POST[bookingID]");

Use

if(mysql_num_rows($result) > 0 ) {
// record exists.. Do whatever you want to do with that record
} else {
echo "<a href='backpage.php'>Click here to go back and change your booking id.. </a>";
}
nav33n 472 Purple hazed! Team Colleague Featured Poster

Use $action == 'preview' and $action=='submit' .
Also, mention Form's 'method'. If you don't mention it, I guess, the default method is GET.

nav33n 472 Purple hazed! Team Colleague Featured Poster

select * from database would work just fine since you want all the records without satisfying any condition :)
Btw, 'for' and 'type' are mysql reserve keywords and requires ` to be wrapped around it.
like, `for`, `type`.

nav33n 472 Purple hazed! Team Colleague Featured Poster

Use mysql_num_rows($result) For example,

$query = "select *from table where id='".$_POST['id']."'";
$result = mysql_query($query);
if(mysql_num_rows($result) > 0 ) {
//record exists
} else {
//record doesnt exit
}
nav33n 472 Purple hazed! Team Colleague Featured Poster

Ehm.. Okay :confused:

nav33n 472 Purple hazed! Team Colleague Featured Poster

Emm.. You can mark this thread as solved if all your questions have been answered. If you are extremely happy with Maxmumford's help, you can add to his reputation. Click on 'Add to MaxMumford's Reputation', click on 'I approve', type your comment and Click the button!

nav33n 472 Purple hazed! Team Colleague Featured Poster

First of all, this question belongs to Javascript forum. Its a javascript related question. 2nd, Post your code and tell us what is not working. We aren't 24/7 free coding service to provide you with ready made code when you say "Please help me asap", or, "Its urgentttt".

nav33n 472 Purple hazed! Team Colleague Featured Poster

Hi
So how can we apply this to my query if you think it’s going to work?
Regards
HB25

It wont. You have to save it in varchar datatype, which again would cause you problems. For example, you can't sort the fields on date. You can't calculate the difference (or add) x number of days to this date field , etc.
Why do you want to store it in that format anyway ?

nav33n 472 Purple hazed! Team Colleague Featured Poster

My suggestion is, store date in YYYY-mm-dd format itself. You can change the format using php's date function. As maxmumford has already mentioned, you can convert that date to unixtimestamp and use it in whatever format you want.

nav33n 472 Purple hazed! Team Colleague Featured Poster

Hmm.. Okay! From what I have read so far, this is what STR_TO_DATE do.

STR_TO_DATE(date_string, format);

STR_TO_DATE function will format string and insert it to the date column. The second parameter 'format' is just to let mysql know in what format is the first parameter 'date_string' is in.

insert into table123 (reg_date) values (STR_TO_DATE('31/2004/04', '%d/%Y/%m'))

In the above example, date_string is 31/2004/04. I am asking mysql to insert this value to the table and the format in which I have given the date is, %d/%Y/%m. ie., date/Year/month .

nav33n 472 Purple hazed! Team Colleague Featured Poster

Btw, Java is totally different from Javascript. :)

nav33n 472 Purple hazed! Team Colleague Featured Poster
print "<pre>";
print_r($_POST['checkbox_element_name'];
print "</pre>";

Does it print anything ? There is nothing wrong in your code except the checkbox name may be wrong :)

Edit: And a thumbs up for using [code] tags in your first post You should close the tag correctly next time. :)

nav33n 472 Purple hazed! Team Colleague Featured Poster

echo your query. Execute it in phpmyadmin. See what's the exact error.
P.S. I tried to work with str_to_date and I simply can't get it to work ! :-/

nav33n 472 Purple hazed! Team Colleague Featured Poster
<?php

// open database connection code and then my code as follows

$sql="UPDATE bookings SET startdate ='$_POST[startdate]',enddate='$_POST[enddate]',adults='$_POST[adults]',children='$_POST[children]',roomtype='$_POST[roomtype]', requirements='$_POST[requirements]'
WHERE bookingID = '$_POST[bookingID]'";
 
if (!mysql_query($sql,$con))
  {
  die('Error:  ' . mysql_error());
  } 

  print "Your booking ID ".$bookingID;
  
  echo "    has been changed";


$result = mysql_query("SELECT * FROM bookings WHERE bookingID='".$_POST['bookingID']."'");
if(mysql_num_rows($result) > 0 ) { 
 //only print this if there is atleast 1 row. This will avoid a lot of problems which could arise from mysql_fetch_array if there are no rows in the table
//I would also declare the table headers when I am sure at least 1 record exist. If there aren't any records, it wont print the html table 
echo '<table border=1>
<tr><td>Start Date</td><td>End Date</td><td>Adults</td><td>Children</td><td>Roomtype</td><td>Requirements</td></tr>';
$result_array = mysql_fetch_array($result);

echo '<td>'.$result_array['startdate'].'</td>';
echo '<td>'.$result_array['enddate'].'</td>';
echo '<td>'.$result_array['adults'].'</td>';
echo '<td>'.$result_array['children'].'</td>';
echo '<td>'.$result_array['roomtype'].'</td>';
echo '<td>'.$result_array['requirements'].'</td>';
echo '</tr>';
echo '</table>'; // this way it looks more neat
}
mysql_close($con);
?>

Also, mysql stores date in the default format yyyy-mm-dd . If you want to change this, you have to specify the column datatype as varchar. I don't recommend it since you can do so many date functions if the column is of date datatype.
Also, php's date function is so vast, you can modify any of your date format to whatever format you want.
Check here.
http://in.php.net/date

nav33n 472 Purple hazed! Team Colleague Featured Poster

http://www.daniweb.com/forums/thread177977.html

Multiple threads for the same problem ? Not good.

nav33n 472 Purple hazed! Team Colleague Featured Poster

Its not showing the values in the textbox because you are using header function to redirect the user back to guess.php . Learn more about $_GET and $_POST here.
http://www.w3schools.com/PHP/php_get.asp
http://www.w3schools.com/PHP/php_post.asp

nav33n 472 Purple hazed! Team Colleague Featured Poster

How does your code look like ?


P.S. I will be out of town for 3 days, so, If not me, someone else will help you with your problem :)

nav33n 472 Purple hazed! Team Colleague Featured Poster

Yay! Finally..

Thanks.. I will try.. :)

nav33n 472 Purple hazed! Team Colleague Featured Poster

Dude!

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

http://in.php.net/function.mysql-query
It will return false on error. There is no error in your query. Since there is no error, it will always return TRUE !!! Its better you use mysql_affected_rows.

God! Why did it take so long to realise this :D Yeah alright! I can sleep peacefully now.

Edit:

(@mysql_affected_rows($sql)==1) {

Thats not the correct syntax. mysql_affected_row takes only 1 parameter and thats the connection link identifier).

if(mysql_affected_row() == 1) { // if you are sure it affects only 1 row or else if(mysql_affected_rows() > 0 ) {
   echo "Updated...";
} else {
  echo "Not updated..";
}
nav33n 472 Purple hazed! Team Colleague Featured Poster

Yep. Since it doesn't update anything, no rows are affected.

http://in.php.net/mysql_affected_rows

When using UPDATE, MySQL will not update columns where the new value is the same as the old value. This creates the possibility that mysql_affected_rows() may not actually equal the number of rows matched, only the number of rows that were literally affected by the query.

nav33n 472 Purple hazed! Team Colleague Featured Poster

Okay ! Found it.
Even though mysql_query returns a boolean value, you can't compare its value as

if($run === TRUE)

It has to be

if($run === "TRUE")  //or in lower case. It doesnt matter!

I am sure this will fix it.
Its 3.40 in the morning and I need to get my sleep :D

nav33n 472 Purple hazed! Team Colleague Featured Poster

1st query is correct and the 2nd is wrong. What does mysql_affected_rows print ? Did you also check in phpmyadmin ? Does it update any record ? Umm.. for a change, try using == instead of === . Lets see how it goes..

nav33n 472 Purple hazed! Team Colleague Featured Poster

:-S Check if all the variables are set properly, echo the query and execute it in phpmyadmin/mysql console ! Tell us if it still updates in phpmyadmin/mysql console.
I executed the first 2 queries and I noticed the difference.
The query

$q="UPDATE login SET password='".SHA1($newPassword)."' WHERE id='$loginID' AND password='".SHA1($oldPassword)."'";

prints this.

UPDATE login SET password='9b2f1fe6da132ed153cd613cb453dca9285af4b9' WHERE id='10' AND password='2fc535a9fd9760b71e76f92dff31ea719625b652'

Whereas, this query,

$q="UPDATE login SET password='".SHA1('$newPassword')."' WHERE id='$loginID' AND password='".SHA1('$oldPassword')."'";

prints this.

UPDATE login SET password='a4c20b3df57a6a1b409d16274aafd91b35447cee' WHERE id='10' AND password='6ce6bf140f3611ce3133244a69b10a76bb412a47'

In both the cases, I have declared the variables,

$newPassword = "thisismynewpassword";
$oldPassword = "thisismyoldpassword";

Edit: You could also try using mysql_affected_rows to see how many rows were really affected!

nav33n 472 Purple hazed! Team Colleague Featured Poster

Dang! Stupid me.. A variable inside ' ' is considered as string.. :icon_rolleyes:

This should fix it.

$q="UPDATE login SET password='".SHA1($newPassword)."' WHERE id='$loginID' AND password='".SHA1($oldPassword)."'";
nav33n 472 Purple hazed! Team Colleague Featured Poster

password column is of datatype varchar (I think). Try this.

$q="UPDATE login SET password='".SHA1('$newPassword')."' WHERE id='$loginID' AND password='".SHA1('$oldPassword')."'";
nav33n 472 Purple hazed! Team Colleague Featured Poster

First, query the table and get all the details of that particular bookingID and then display it. You can also give an option for the user saying something like, "Are you sure want to delete ?" :) Have a hidden variable in your form to hold the bookingID. If he clicks yes, then, delete the record. If he clicks no, then redirect him to some other page. Many users might give a second thought before deleting :)
And about making your report look better, well, add some style to it.
Its 2 in the morning and I ll probably hit the sack!

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