solution 4 php+mysql+js

guys finally i got it

Page 1 of 1

2 Replies - 2163 Views - Last Post: 10 March 2006 - 05:41 AM Rate Topic: -----

#1 gayatri  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 2
  • View blog
  • Posts: 62
  • Joined: 13-February 06

solution 4 php+mysql+js

Posted 09 March 2006 - 03:43 AM

let me 1st xplain what i needed to do
i have a form which has a select box and some text boxes
so if i select certain option from select box,
i wanted to fill up the text boxes with the information related to selected option from database.
i don't know how much simple/difficult it was,
but now i have solution to it
posting here just bcuz i feel, it could help someone like me

code
<?php
$regid=$_GET["reg_id"];
$handle1=mysql_query("select fname,lname,dob,age,sex from Registration where registerID='$regid'");
while($row1=mysql_fetch_array($handle1))
{
  $temp_fname=$row1["fname"];
  $temp_lname=$row1["lname"];
  $temp_dob=$row1["dob"];
  $temp_age=$row1["age"];
  $temp_sex=$row1["sex"];
}

$temp_out = '<script language="javascript">
function dispfun() {
	box = document.getElementById("edit-reg_id");
	id = box.options[box.selectedIndex].text;
	if (id) 
        {
             location.href = ("get", "/somepath?reg_id="+id);
        }
}</script>';
$handle=mysql_query("select registerID from Registration");
while($row=mysql_fetch_array($handle))
{
  $opt[0]="Choose";
  $opt[] .=$row["registerID"];
}

$temp_out .= select('reg_id','',$opt, 'onchange=dispfun()');

//make necessary changes in form select box
//it's just input type select with options in $opt array and path to onchange to js function

//$temp_out .= form text boxes to be filled up with the value filled in as $temp_fname;
//as calculated above n so on
echo $temp_out;
?>


i don't know how much this will help u,
in case u have any doubts regarding this
i am here
hope it helps someone needful

cheers!!

GaYaTrI

This post has been edited by hotsnoj: 09 March 2006 - 12:02 PM


Is This A Good Question/Topic? 0
  • +

Replies To: solution 4 php+mysql+js

#2 snoj  Icon User is offline

  • Married Life
  • member icon

Reputation: 64
  • View blog
  • Posts: 3,505
  • Joined: 31-March 03

Re: solution 4 php+mysql+js

Posted 09 March 2006 - 12:23 PM

A few things I'd like to point out that could be done better.

$regid=$_GET["reg_id"];

You're directly inserting unknown data into a query. That is a no-no! ALWAY, ALWAYS verify that data is what you want/need and make sure to at least use addslashes() on it if it's a string.

I'm assuming this is just a number so we can do this. This following example will cast whatever $_GET['reg_id'] is into a number (integer). So if someone trys to send "hello world!1" it will be converted to 1.
$regid= (int) $_GET["reg_id"];


$handle1=mysql_query("select fname,lname,dob,age,sex from Registration where registerID='$regid'");
while($row1=mysql_fetch_array($handle1))
{
 $temp_fname=$row1["fname"];
 $temp_lname=$row1["lname"];
 $temp_dob=$row1["dob"];
 $temp_age=$row1["age"];
 $temp_sex=$row1["sex"];
}

Why loop when you're only getting one row? Since you're only getting one row, there isn't much point in even reassigning $row1 array values to new variables.

Why not just do this?
$reg_info=mysql_fetch_assoc(mysql_query("select fname,lname,dob,age,sex from Registration where registerID='$regid' LIMIT 1"));

See we've limited our query return data to one and only one row, as well as put everything on one row. Now if you were going to be needing the resource from mysql_query() you'd want this on two lines. But it doesn't look like you are.
Was This Post Helpful? 0
  • +
  • -

#3 gayatri  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 2
  • View blog
  • Posts: 62
  • Joined: 13-February 06

Re: solution 4 php+mysql+js

Posted 10 March 2006 - 05:41 AM

thanx it's very much helpful
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1