nav33n 472 Purple hazed! Team Colleague Featured Poster

Use Ajax. Refer this .

nav33n 472 Purple hazed! Team Colleague Featured Poster

First, try print_r to see all the form elements are posted correctly. Try printing the query and see if it executes in mysql console/phpmyadmin.

nav33n 472 Purple hazed! Team Colleague Featured Poster

Nothing wrong with the above code. Do you get any errors ?

nav33n 472 Purple hazed! Team Colleague Featured Poster

But how about alternate ways of handling navigation? What are the most used techniques?

I am not really sure of your question. As far as I know, there is either
* long, dirty urls, like,
http://www.somewebsite.com/edit.php?id=1234&key=xy&somevar=v
or
* friendly urls, like,
http://www.somewebsite.com/edit/1234/xy/v

I am not aware of any other navigation techniques.

Are some ways worse to handle navigation than others? Is the last mentioned way ineffective?

As long as you take good measures to sanitize user's inputs it's okay. For example,

<?php
//mysql connection
//get the page from the url, sanitize it with mysql_real_escape_string
$page = mysql_real_escape_string($_GET['page']);
// $page = home or report
switch($page) {
   case "home":
      //include/print home's contents
    break;
    case "report":
    //include/print report's contents
   break;
   default:
   //show error page
   break;
}

In the above example, a user can only access to only 2 pages, "home" and "report". If he tries anything else, it will take him to the error page [the default case].

Cheers,
Naveen

nav33n 472 Purple hazed! Team Colleague Featured Poster

It's called friendly urls. It's done through mod_rewrite with apache. Search in php forum, as there have been many threads on this already. I haven't worked on it , so this is all I can say.

nav33n 472 Purple hazed! Team Colleague Featured Poster

If you have no more questions to ask, please mark this thread as solved. :)

Cheers,
Naveen

nav33n 472 Purple hazed! Team Colleague Featured Poster
$info[] = $row['columnname'];
nav33n 472 Purple hazed! Team Colleague Featured Poster

You are welcome! Glad I could help. :)

Edit:

I am not really sure how the above code worked. Technically, It shouldn't because nothing is selected yet. :S

nav33n 472 Purple hazed! Team Colleague Featured Poster

Eg.

<?php
$rec_in_table = 2;
?>
<select name='designation'>
<option value='1' <?php if($rec_in_table == 1) { echo "selected"; } ?>>1</option>
<option value='2' <?php if($rec_in_table == 2) { echo "selected"; } ?>>2</option>
<option value='3' <?php if($rec_in_table == 3) { echo "selected"; } ?>>3</option>
</select>
nav33n 472 Purple hazed! Team Colleague Featured Poster

Great :) Good job.

Cheers!

nav33n 472 Purple hazed! Team Colleague Featured Poster

You have a typo.

if ($_POST["$submit"])
{

should be

if ($_POST["submit"])
   {

And please indent your code. Indented code is easier to debug and find faults.

nav33n 472 Purple hazed! Team Colleague Featured Poster

The point I was trying to make here was to show you how to use single and double quotes. http://php.net/manual/en/language.types.string.php

The variable $id is not expanding and hence you are facing problem with the id value that you are trying to pass. Read the above link to know more on what I am talking about.

nav33n 472 Purple hazed! Team Colleague Featured Poster

i tried another code that i found on the net but this code is giving me a problem with the id value that im tying to pass.my code is

<?php
require_once "../inc/functions.php";
require_once "../inc/vars.inc.php";
sessionCheck();
session_start();

$old_sessionid = session_id(); //i've added these lines

session_regenerate_id(); //i've added these lines

$new_sessionid = session_id(); //i've added these lines
function getdsgType(){
	global $desig;
	$output = '<select name="dsgn" id="dsgn">';
	$output .= '<option value="">Designation</option>';	
	foreach($desig as $k=> $v){
		if($_POST['dsgn'] == $k){
			$output .= '<option value="'.$k.'" selected>'.$v.'</option>';
		}else{
			$output .= '<option value="'.$k.'">'.$v.'</option>';		
		}
	}
	$output .= '</select>';
	return $output;
}
?>

<?php include_once "admin_templates/case_header.php"; ?>

<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<?php

if(!isset($cmd)) 
{
   //display all the news
   $result = caseQuery("SELECT * 
FROM dsg, designation
WHERE dsg.dsg_id
BETWEEN 1 
AND 7 
AND dsg.designation = designation.designation order by dsg.dsg_id"); 
   if(mysql_num_rows($result))
{
$output ='<table  border="1">
<tr><td>no</td><td>Name</td><td>Designation</td><td>Phone Office</td><td>Mobile</td><td>Residence</td><td>Edit</td></tr>';
while($r=mysql_fetch_array($result)) 
   { 
      //grab the title and the ID of the news
      $name=$r["name"];//take out the title
      $dsg=$r["designation"];//take out the id
      $ph_o=$r["ph_o"];
	   $ph_m=$r["ph_m"];
	    $ph_r=$r["ph_r"];
		$id=$r["sr_no"];
$output .='<tr><td>'.$id.'</td><td>'.$name.'</td><td>'.$dsg.'</td><td>'.$ph_o.'</td><td>'.$ph_m.'</td><td>'.$ph_r.'</td><td><a href="edit.php?cmd=edit&id=$id">Edit</a></td></tr>';
}
$output .= '</table>';
echo "$output";
}
}
?>

<?
if($_GET["cmd"]=="edit" || $_POST["cmd"]=="edit")
{
   if (!isset($_POST["submit"]))
   {
      $id = $_GET["id"];
	  echo "$id";
      $sql = "SELECT * 
FROM dsg, designation
WHERE dsg.dsg_id
BETWEEN 1 
AND 7 
AND dsg.designation = designation.designation WHERE designation.sr_no=$id";
      $result = caseQuery($sql);        
      $myrow = mysql_fetch_array($result);
      ?>
	  
      <form action="edit.php" method="post">
      <input type=hidden name="id" value="<?php echo $myrow["sr_no"] ?>">
   
      Name:<INPUT TYPE="TEXT" NAME="name" VALUE="<?php echo $myrow["name"] ?>" SIZE=30><br>
      Designation:<?php
  $query=caseQuery("select designation from dsg");
echo "<select name='dsgn' ><option value=''>Select one</option>";
while($noticia = mysql_fetch_array($query)) { …
nav33n 472 Purple hazed! Team Colleague Featured Poster

Just put the condition

if(isset($_POST['submit']))

outside

if($_GET["cmd"]=="edit")

ie.,

if($_GET["cmd"]=="edit") {
//blah blah blah
}
if(isset($_POST['submit'])) {
//blah blah blah
}

Cheers!

nav33n 472 Purple hazed! Team Colleague Featured Poster

You have

if(isset($_POST['submit']))

inside

if($_GET["cmd"]=="edit")

You get the form, update the details, etc etc. All fine up to this stage. But when you click on submit, the form submits to

$_SERVER['PHP_SELF']

ie., info.php .
It will never enter the first condition of

if($_GET["cmd"]=="edit")

and it never enters

if(isset($_POST['submit']))
nav33n 472 Purple hazed! Team Colleague Featured Poster

As simple as it sounds, Your code [what you have at the moment on the page] is correct, but you should name your script from ics2_design.html to ics2_design.php OR you should make your apache parse html files as php.
If you view the source of the page, you will see that the php code in the page isn't parsed.

:) Cheers!

nav33n 472 Purple hazed! Team Colleague Featured Poster

m i correct nav33n?

Didn't test, but seems good to me. :)

nav33n 472 Purple hazed! Team Colleague Featured Poster

Can you post your latest code ?

nav33n 472 Purple hazed! Team Colleague Featured Poster

http://www.tizag.com/javascriptT/javascriptredirect.php Check this for javascript redirection if you can't use header.

nav33n 472 Purple hazed! Team Colleague Featured Poster

1. It will not alert your message because you are already returning a value [1 or 0] from the function. Once you return a value, you are out of the function. Either return the value after the alert, or simply, put the alert after the function call.
2. It's not advisable to have any echo/print statements before calling the header function [not even a simple html tag]. This will generate a warning, which can be overridden by using ob_start. :)

nav33n 472 Purple hazed! Team Colleague Featured Poster

My bad, sorry. I had never used mysqli. Thanks to you, I checked how it works and it did work.

$mysqli = new mysqli("localhost", "root", "", "test2");

if (mysqli_connect_errno()) {
    printf("Connect failed: %s\n", mysqli_connect_error());
    exit();
}

$result = $mysqli->query("SELECT * from b");
echo "Total number of records: ".$result->num_rows."<br />";
while ($row = $result->fetch_row()) { 
	print "<pre>";
	print_r($row);
	print "</pre>";
}
$result->close();
$mysqli->close();

Are you sure you are not overwriting the data in pdf ? If you print $obj2, does it print 4 records ?

nav33n 472 Purple hazed! Team Colleague Featured Poster

If mysql_num_rows say 4, then something must be wrong with your function, fetch_row. Post your function and we will try to find out what is missing.

nav33n 472 Purple hazed! Team Colleague Featured Poster

I suggest you to go step by step. First make first form work, then 2nd and so on. It's easy to debug that way.

michelleradu commented: he gave some gd suggestions +1
nav33n 472 Purple hazed! Team Colleague Featured Poster

First form's <option> tag doesn't have values. So, it will never enter the switch cases of the 2nd form. And as CJesusSaves said, It's better to keep php and html separate as it is easy to manage [and you don't have to worry about escaping quotes ['] and ["]].

nav33n 472 Purple hazed! Team Colleague Featured Poster

:P Yeps! That's absolutely right!

= is an assignment operator where as, == is a comparison operator!

nav33n 472 Purple hazed! Team Colleague Featured Poster
if($_GET['country'] == "Germany")

You are missing another "=" in your statement.

nav33n 472 Purple hazed! Team Colleague Featured Poster

This above code works fine for me [apart from the insert query].
Few things to remember when dealing with databases.

1. Always sanitize user's input. Never trust your users. This can be achieved using mysql_real_escape_string .
2. If you are sure that the posted value is going to be an integer, use, is_numeric .
3. Mention all the column names in your insert query. For example,

$query = "insert into table (col1, col2) values ('val1','val2')";

Doing so will save you from the headaches you might have in future. Example, You are asked to add another field to log the time of insert. Then you have to change all the scripts in which you have an insert query.

Lastly, your query is wrong. There are no ' ' around table name.

INSERT INTO stock (mention_column_names_here) VALUES ('$item_name', '$item_model', '$item_desc', '$item_cost', '$item_qty')

P.S. It's also better to store your query in a variable. You can print out the variable incase your query isn't working and test it in phpmyadmin or mysql console.

Oh, Btw, you can also make use of die(mysql_error()); to know why your query failed.
ie.,

$result = mysql_query($query) or die(mysql_error());

Cheers,
Nav

nav33n 472 Purple hazed! Team Colleague Featured Poster

$row will have an array. You can explode only strings, not arrays. And, as JRM mentioned, I don't recommend the use of mysql_fetch_row. Since this returns an numeric index array, you will have to use $row[0], $row[1] etc.
Say, after sometime, you change the database structure, by adding/removing a field [first field for example], then that is going to be a big problem as $row[1] will now correspond to the newly added field!

Always use mysql_fetch_array or mysql_fetch_assoc.

nav33n 472 Purple hazed! Team Colleague Featured Poster

You are welcome :)

nav33n 472 Purple hazed! Team Colleague Featured Poster

Not sure what exactly I changed, but this works.

<html>
<head>
<script type="text/javascript">
function resizeText(multiplier,p,what) {
	if (document.getElementById(p).style.fontSize == "") {
		document.getElementById(p).style.fontSize = "1.0em";
  	}
  	if(what == "increase") {
  		document.getElementById(p).style.fontSize = parseFloat(document.getElementById(p).style.fontSize) + (multiplier * 0.2) + "em";
  	} else {
  		document.getElementById(p).style.fontSize = parseFloat(document.getElementById(p).style.fontSize) - (multiplier * 0.2) + "em";
  	}
}
</script>
</head>
<body>
<?php 
 $c=0;
 $c = $c +1;
 $text = "Click the button to increase the size of the font. Keep clicking it until you get tired.";
 $p="par".$c;

echo "<p align='right'><input type='button' name='button' value='Increase font' onclick='resizeText(1,\"$p\",\"increase\");' />";
echo "<p align='right'><input type='button' name='button' value='Decrease font' onclick='resizeText(1,\"$p\",\"decrease\");' />";         
echo "<p align='justify' id='".$p."'>".$text."</p>";
?>
</body>
</html>

Cheers!
Naveen

nav33n 472 Purple hazed! Team Colleague Featured Poster

Yay! You are welcome :)

nav33n 472 Purple hazed! Team Colleague Featured Poster

It outputs, three records for the user who is at the bottom of the user table, i.e date_joined DESC.

Actually, date_joined DESC should sort the records on date_joined column with the latest date on top. Can you try this query ?

SELECT media.file_name, users.username, users.creative_specialism
FROM media, users
WHERE media.user_id = users.user_id 
GROUP BY media.user_id 
ORDER BY users.date_joined DESC
LIMIT 3

GROUP BY will group all the records having common user_id in media table, more like, what DISTINCT would do.

nav33n 472 Purple hazed! Team Colleague Featured Poster

Hi, You don't have to run the select query thrice. In my opinion, this should work.

SELECT media.file_name, users.username, users.creative_specialism
FROM media, users
WHERE media.user_id = users.user_id 
ORDER BY date_joined DESC
LIMIT 3
nav33n 472 Purple hazed! Team Colleague Featured Poster

Pass $row as a parameter to this date function and return the changed value.
Eg.

function changeDate($date) {
 $newdate = date('d/n/y',strtotime($date)); 
 return $newdate;
}

Call this function wherever applicable. :)

nav33n 472 Purple hazed! Team Colleague Featured Poster

Great :) Cheers!

nav33n 472 Purple hazed! Team Colleague Featured Poster

$query = mysql_query("SELECT * FROM Employee WHERE $method = '$search'");
$result = mysql_query($query);

This is wrong. Try,

$query = "SELECT * FROM Employee WHERE $method = '$search'";
	$result = mysql_query($query);
nav33n 472 Purple hazed! Team Colleague Featured Poster

Or you could insert the data from the first page into the database as soon as it is submitted, have the user fill out the second part, and just update the row when the second part is submitted.

The only problem with this is , if a user loses his interest midway [ie., after submitting 1st form], there will be a obsolete record in the table. Or else, this is good.

nav33n 472 Purple hazed! Team Colleague Featured Poster

You can do it in 2 simple ways (maybe there are even more, but I am not aware of it).
You can either save the data of the first form in session after it is posted, and then, when the second form is posted, get all the data (session data and the 2nd form's posted data) and insert a record to the table.
The second method is to have hidden fields in the 2nd form, which will save all the values of the first form and when the 2nd form is submitted, you will have the data of 1st and 2nd form :)

nav33n 472 Purple hazed! Team Colleague Featured Poster

The echo statement is incorrect.

echo "<a href=\"inventorid.php?inventorid=".$data2['inventorid']."\">".$data2['inventorid']." ".$data2['firstname']." ".$data2['lastname']."</a>\n";

is the correct syntax.
Also, to make life simple, you can use,

$inventorid = $data2['inventorid'];
$firstname = $data2['firstname'];
$lastname = $data2['lastname'];
echo "<a href='inventorid.php?inventorid=$inventorid'>$inventorid $firstname $lastname</a>\n";

Cheers!

nav33n 472 Purple hazed! Team Colleague Featured Poster

m not student.. m professional..and this is required for my proj..
dnt worry i solved it now...no need to waste ur time..

Congrats on solving your problem. I am glad you learnt something new :)

If you post your answer, even others may get to learn something from this thread.

nav33n 472 Purple hazed! Team Colleague Featured Poster


Do not post homework problems expecting a quick answer without showing any effort yourself.

Seems like you didn't read the member rules.
Ch, ch. Read more on count and group by clauses. After reading them, you will be able to solve this query yourself. :)

Good luck.

nav33n 472 Purple hazed! Team Colleague Featured Poster

I agree because I used to solve questions like crazy in the php forum but now there are fewer questions that are not already solved by another member.

Hmm.. Maybe recession is a factor too. :)

nav33n 472 Purple hazed! Team Colleague Featured Poster

Dude, datatype as in int, varchar, date, datetime, etc.

ALTER TABLE clown_contest MODIFY COLUMN `location` varchar(40) AFTER `state`

Clear ? :)

nav33n 472 Purple hazed! Team Colleague Featured Poster

To get a new line, you should add a <br /> to your echo.
ie.,

<?php
echo $abbr['US']['MI']."<br />";  
?>
//or simply
<?php
echo $abbr['US']['MI'];  
echo "<br />";
?>

Also, can you use the php include function in arrays like I used the HTML image function in my japanesemotors example above?

That's a good one. I never did this (or even thought of having an include in an array).
But It doesn't work. Whenever you call the construct "include", it will start processing the 'included' file, ie., it will print if there is any print statement, or make the variables in the included file accessible to the 'base' file (the file where you are using include).
Here is a small example I tried out.

<?php
//include1.php
echo "From Include 1<br>";
?>
<?php
//include2.php
echo "From Include 2<br>";
?>
<?php
//include_in_array.php
$arr = array("a"=>include "include1.php", "b"=>include "include2.php" );
?>

There are 3 files, include1.php, include2.php and include_in_array.php . When you execute the file include_in_array.php , you will see 2 lines (From Include1 and From Include2) printed in the browser.
If you try printing $arr , it will print 1, which simply indicates that the file include1.php was included successfully.
So, the bottomline is, you can't include a file in an array.

network18 commented: include in a array..! really good one!! +1
nav33n 472 Purple hazed! Team Colleague Featured Poster

You forgot the datatype! (doh, even I forgot it in the syntax).
Sorry, here is the right syntax.

ALTER TABLE tablename MODIFY COLUMN columnname datatype AFTER columnname

This works for sure!

nav33n 472 Purple hazed! Team Colleague Featured Poster

:) You forgot the column name as the 2nd parameter for mysql_result.
http://php.net/manual/en/function.mysql-result.php

nav33n 472 Purple hazed! Team Colleague Featured Poster

Condition is a mysql reserved keyword. In order to use it, you have to use ` [don't confuse it for single quote]. ie., `condition`. In my opinion, use some other word instead of condition to avoid the same problem in future.
Here is a list of all the reserved keywords in mysql.
http://dev.mysql.com/doc/refman/5.1/en/reserved-words.html

nav33n 472 Purple hazed! Team Colleague Featured Poster

Yeah, ofcourse. :) $string is just a variable name. You can give any name to a variable.
See Php naming convention here .

nav33n 472 Purple hazed! Team Colleague Featured Poster

Clear @ before mysql_query and see if it throws any error. Also, you can have

$result = mysql_query($query) or die(mysql_error());

to print the error when the query fails.

P.S. @ suppresses the errors, so you shouldn't use it in testing scenarios. That will make your life hard to know where exactly the error is.

nav33n 472 Purple hazed! Team Colleague Featured Poster

you could also make a function out of it

<?php
   function arrayToString($array) {
      $string = '';
      foreach($array as $value) {
         $string .= "{$string}, {$value} ";
      }
      return $string;
   }

   echo arrayToString($_POST['Prefered_Engineers']);
?>

Or simply,

$string = implode(",",$_POST['Prefered_Engineers']);
leviathan185 commented: Turned many lines of ordinary code into 1 line of magic +1