0

Hi,,
My problem is that i have two table city and location.In city table i have 3 field city_id(Primary key),city_name,city_status where city_status is true or false.In location table i have 3 field also loc_id(Primary key),city_id,loc_city.i done a code in which city_name comes into drop down list from city table.my problem starts here when i select one of this value and want to insert into location table...then this show error..is there any code available related to my problem plz send my id......

3
Contributors
19
Replies
29
Views
6 Years
Discussion Span
Last Post by xerilagang
0

Here is my code which i am using here...........
droplistcity.php

<html>
<head>
<script language="JavaScript">
function onChange() {
  var Current=document.form1.select1.selectedIndex;
  document.form1.currentText3.value=document.form1.select1.options[Current].text;
}
</script>
</head>
<body>
<form name="form1" method="POST">
<?php include("connect.php")?>
<table border="1" align="center">
<tr><td>List of City</td>
<td><select name="select1" onChange="onChange()">
    <option value="">Select City</option>
<?php
 $reza=mysql_query("select city_id,city_name from city order by city_id");
                    while ($row=mysql_fetch_array($reza)){
					   $id1=$row["city_id"];
                      $id2=$row["city_name"];
                      
				 echo "<option value=\"$id2\">$id2</option>";
                    }
mysql_close($con);
?>
</select></td>
</tr>
<tr><td>Selected City</td>
<td><input
  name="currentText3"
  type="text"
  value=""
></td>
</tr></form>
</body>
</html>

cityname.php

<?php include("connect.php");?>
<?php 
$city_name = $_POST['currentText3'];
$result=mysql_query("select * from city where city_name='$city_name'");
while($row = mysql_fetch_array($result))
  {
  echo $row['city_name'] ;
  echo "<br />";
  }
mysql_close($con);
?>

addloc.php

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<form name="form1"action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<table border="1" align="center">
<input type="hidden"  name="l_id" />
<tr>
<?php include("droplistcity.php");?>
</tr>
<tr>
<td>Location Name</td>
<td><input type="text" name="location" /></td></tr>
<tr>
<td></td><td><input type="submit" value="added!">
</td>
</tr>
</table>
</form>
</body>
</html>
<?php include("connect.php");?>
<?php include("cityname.php");?>

<?php
$l_id = $_POST['l_id'];
$city_id = $_POST['city_name'];
$location = $_POST['location'];
$query = "INSERT INTO location (loc_id, city_id,loc_city) VALUES('$l_id',(SELECT city_id FROM city WHERE city_id = '$city_id'),'$location')";
$result = mysql_query($query) or die("Query failed: ".mysql_error());
mysql_close($con);
?>



here is my all code........plz reply as soon as possible.......
0

Here is my code which i am using here...........
droplistcity.php

<html>
<head>
<script language="JavaScript">
function onChange() {
  var Current=document.form1.select1.selectedIndex;
  document.form1.currentText3.value=document.form1.select1.options[Current].text;
}
</script>
</head>
<body>
<form name="form1" method="POST">
<?php include("connect.php")?>
<table border="1" align="center">
<tr><td>List of City</td>
<td><select name="select1" onChange="onChange()">
    <option value="">Select City</option>
<?php
 $reza=mysql_query("select city_id,city_name from city order by city_id");
                    while ($row=mysql_fetch_array($reza)){
					   $id1=$row["city_id"];
                      $id2=$row["city_name"];
                      
				 echo "<option value=\"$id2\">$id2</option>";
                    }
mysql_close($con);
?>
</select></td>
</tr>
<tr><td>Selected City</td>
<td><input
  name="currentText3"
  type="text"
  value=""
></td>
</tr></form>
</body>
</html>

cityname.php

<?php include("connect.php");?>
<?php 
$city_name = $_POST['currentText3'];
$result=mysql_query("select * from city where city_name='$city_name'");
while($row = mysql_fetch_array($result))
  {
  echo $row['city_name'] ;
  echo "<br />";
  }
mysql_close($con);
?>

addloc.php

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<form name="form1"action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<table border="1" align="center">
<input type="hidden"  name="l_id" />
<tr>
<?php include("droplistcity.php");?>
</tr>
<tr>
<td>Location Name</td>
<td><input type="text" name="location" /></td></tr>
<tr>
<td></td><td><input type="submit" value="added!">
</td>
</tr>
</table>
</form>
</body>
</html>
<?php include("connect.php");?>
<?php include("cityname.php");?>

<?php
$l_id = $_POST['l_id'];
$city_id = $_POST['city_name'];
$location = $_POST['location'];
$query = "INSERT INTO location (loc_id, city_id,loc_city) VALUES('$l_id',(SELECT city_id FROM city WHERE city_id = '$city_id'),'$location')";
$result = mysql_query($query) or die("Query failed: ".mysql_error());
mysql_close($con);
?>



here is my all code........plz reply as soon as possible.......
0

$query = "INSERT INTO location (loc_id, city_id,loc_city) VALUES('$l_id',(SELECT city_id FROM city WHERE city_id = '$city_id'),'$location')";

Why dont you try simple select query to get the city_id and then insert into location table,

That should work ok? ;)

I also want to see your error mysql prints;

0

Query failed: Access denied for user 'ODBC'@'localhost' (using password: NO)


when i am accessing file addloc1.php

plz find as soon as possible....

0

you must set password for your mysql connection.

example:

$host="localhost";
$user="root";
$pass="SeKr1t";

mysql_connect($host,$user,$pass); // You need a password set ok?

thats all ;)

0

Thanks for your reply but i have tried this one also there was no result.is there any problem on my code or query......

plz reply me....

0

please get this for me.

1. what is your database engine or type. eg ms sql, mysql, oracle, etc.

2. did you received any errors of any kind.??
a.if yes, post the error
b. if no, make sure you have data in the database for your query.

please advice. ;)

0

i am using mysql and iis for running application.....all are current version...

(if no, make sure you have data in the database for your query.) what is the meaning of this...........

0

populate at least some few data in your tables that you query.

if they are empty, you will get no data out.

Do what i told you and post all errors if any.

0

in my city table there are two entry
city_id 1,2
city_name noida ,lucknow
city_status true,true

in my location table this is empty.....because i am inserting this...

0

You error must be very simple only i cant understand what you really want.

// select from city

$query= "select city_id from city where( you know what you want)";
//exe query

$result=mysql_query($query) or die();
$row=mysql_fetch_array($rsult));
$city_id=$row['city_id'];
    // then insert into location
if($city_id){
$q= "insert into location values('','$location_nane','$city_id')";
$re=mysql_query($q) or die (mysql_error());
if($re){
echo "roger that";
}
}

this should be out last contact skyhawk 67.
roger that ;)

Edited by richieking: n/a

0

My problem is not resolved yet when i am running this code a problem is displaying

HTTP Error 500.0 - Internal Server ErrorThe page cannot be displayed because an internal server error has occurred.

what is this error????/

0

your server is not setup well. This got nothing to do with your mysql stuff.

Did you play around with the apache2 conf or the php ini? ????

need more info :)

0

Error SummaryHTTP Error 500.0 - Internal Server ErrorThe page cannot be displayed because an internal server error has occurred.Detailed Error InformationModule FastCgiModule
Notification ExecuteRequestHandler
Handler PHP_via_FastCGI
Error Code 0x00000000
Requested URL http://localhost:80/muneer/newzstreet/addloc1.php
Physical Path C:\inetpub\wwwroot\muneer\newzstreet\addloc1.php
Logon Method Anonymous
Logon User Anonymous

HOw can i remove this error?......I am using IIS server not apache.....

0

o hell no,

I dont remember the last time i used microsoft stuff.

why dont you simply use wamp or xamp.??
well thats your taste. if you care to, just google wamp or xamp and start developing. They are better for php my friend ;)

Edited by richieking: n/a

0
<?php include("connect.php");?>
<?php include("cityname.php");?>
<?php // select from city
$query= "select city_id from city where(city_name='$city_name')";
//exe query
$result=mysql_query($query) or die();
$row=mysql_fetch_array($rsult);
$city_id=$row['city_id'];
// then insert into location
if($city_id){
$l_id=$_POST['l_id'];
$location=$_POST['location'];
$q = "INSERT INTO location (loc_id,city_id,loc_city)VALUES('','$city_id','$location')";
$re=mysql_query($q) or die (mysql_error());
if($re){
echo "roger that";
}
}
?>

when i am using this code following i find this code

Warning: mysql_query() [function.mysql-query]: Access denied for user 'ODBC'@'localhost' (using password: NO) in C:\xampp\htdocs\newzstreet\addloc1.php on line 29

Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in C:\xampp\htdocs\newzstreet\addloc1.php on line 29


currently i am using Apache server

0

Check if your DB was connected.

The Link to the DB server was not established.

1. You must connect to your mysql server with your hostname, uername, password.

Do that first . ::)

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.