0

I'm receiving an 'undefined index' error when calling a new window and I can't quite figure out why. Seems to me like the variable is not being passed, or holds no value, and again I can't figure out why. I use an identical code for 'state' with no issues.
Here is the code:

// Here is the initial page where i pass the variable
$state=$_GET['state'];

$sql="SELECT DISTINCT city FROM users WHERE state='$state' GROUP BY city";
$res=mysql_query($sql);
while($r=mysql_fetch_array($res)){
	$city=$r['city'];?>

	<a href="javascript: void(0)" 
   onclick="window.open('num_users.php?id=<?=$city?>', 
  'windowname3', 
  'width=125, \
   height=500, \
   directories=no, \
   location=no, \
   menubar=no, \
   resizable=no, \
   scrollbars=1, \
   status=no, \
   toolbar=no,'); 
  return false;">
  <?=$city?></a><br />
    <? } ?>

// Here is the page  where I receive the variable
$city=$_GET['city'];

$sql="SELECT id FROM users WHERE city='$city'";
$res=mysql_query($sql);
$num=mysql_num_rows($res);

echo "".$num." users";

?>

Perhaps I've been staring at this thing for too long. I must be overlooking something simple. Any ideas?

3
Contributors
3
Replies
5
Views
8 Years
Discussion Span
Last Post by mwita
0

And there you have it ... LOL. An extra set of eyes always helps. I knew I was overlooking something simple. Thanks Ardav, Problem solved.

0

I,m getting : Undefined index: submit in C:\wamp\www\tag\chur\Maelezoyakiroho.php on line 2 help me

<?php
if($submit =!$_POST)
{
?>

<form action="Registration.php" method="post" return onsubmit="formSubmit()" >
<table align="center">

<tr><td>Idara aliyopo:</td><td><input type="text" name="departmentid" /></td></tr>
<tr><td>Namba ya usajili:</td><td><input type="text" name="nambayamuumini" /></td></tr>
<tr><td>Jina kamili:</td><td><input type="text" name="jinakamili" /></td></tr>

<tr><td>Tarehe ya kuzaliwa</td><td><input type="text" name="tareheyakuzaliwa" /></td>


<tr><td>Mahali alipozaliwa :</td><td><input type="text" name="mahali" /></td></tr>
<tr><td>Wilaya :</td><td><input type="text" name="Wilaya" /></td></tr>
<tr><td>Mkoa :</td><td><input type="text" name="mkoa" /></td></tr>
<tr><td>Uraiya wake :</td><td><input type="text" name="uraiya" /></td></tr>
<tr><td>Jinsia :</td><td><select name="jinsia" ><option></option><option>Mume</option><option>Mke</option></select> </td></tr>
<tr><td>Kabila :</td><td><input type="text" name="kabila" /></td></tr>
<tr><td>Hali ya ndoa :</td><td><select name="ndoa"><option></option><option>Nimeolewa</option><option>Nimeoa</option></option><option>Sijaoa</option></option><option>Sijaolewa</option></option><option>Tumetengana</option></option><option>Mjane</option></select></td></tr>
<tr><td>Kama una ndoa Jina la mwenzi wako :</td><td><input type="text" name="mwenzi" /></td></tr>
<tr><td>Mwenzi wako ameokoka :</td><td><select name="ameokoka" ><option></option><option>Ndiyo</option><option>Hapana</option></select></td></tr>
<tr><td>Mahali anapo abudu :</td><td><input type="text" name="anapoabudu" /></td></tr>
<tr><td>Mwaka wa ndoa :</td><td><input type="text" name="mwakawandoa" /></td></tr>
<tr><td>Idadi ya watoto :</td><td><input type="text" name="idadiyawatoto" /></td></tr>
<tr><td>Wanaoabudu hapa kanisani :</td><td><input type="text" name="wanaoabudu" /></td>
</tr>
<tr><td>Jina la mtaa unapoishi :</td><td><input type="text" name="mtaa" /></td></tr>
<tr><td>kata :</td><td><input type="text" name="kata" /></td></tr>
<tr><td>Unapoishi ni : </td><td><select name="unapoishini"><option></option><option>Kwako</option><option>Umepanga</option></option><option>Nakaa kwa ndugu</option></option><option>Nyingine</option></select></td></tr>
<tr><td>Namba ya simu yako</td><td><input type="text" name="simuyake" /></td></tr>
<tr><td>Barua pepe(Email)</td><td><input type="text" name="email" /></td></tr>
<tr><td>Kazi yako</td><td><input type="text" name="kazi" /></td></tr>
<tr><td>Ndugu wa karibu</td><td><input type="text" name="ndugu" /></td></tr>
<tr><td>Mahali Anapoishi</td><td><input type="text" name="nduguanapoishi" /></td></tr>
<tr><td>Namba yake ya simu ndugu</td><td><input type="text" name="simuyandugu" /></td></tr>
<tr><td>Uhusiano wake na wewe</td><td><input type="text" name="uhusiano" /></td></tr>
<tr><td colspan="2"><b>Maoni ya kanisa</b></td></tr>
<tr><td colspan="2"><textarea cols="40" rows="5" name="maoni"></textarea></td></tr>
</table>
<p align="center"><input type="submit" value="submit" name="submit" ><input type="reset" value="FUTA" name="reset" onclick="formSubmit()" ></p>

<p align="center"><font color="#0000FF" size="4" face="Geneva, Arial, Helvetica, sans-serif" ><a href="reportusajil.php"><font color="#FFFFFF">Report ya usajili</font></a>|</font></p>
</form>
<?PHP
}
else
{
{
$departmentid=(trim($_POST)=='')?
die ('Ingiza namba ya idara ya usajili') : mysql_escape_string($_POST);
$nambayamuumini=(trim($_POST)==''?
die ('UMEKOSEA: Ingiza a namba ya muumini') : mysql_escape_string($_POST));
$jinakamili=(trim($_POST)==''?
die ('UMEKOSEA: Ingiza jina kamili') : mysql_escape_string($_POST));

$tareheyakuzaliwa=(trim($_POST)==''?
die ('UMEKOSEA: Ingiza tarehe ya kuzaliwa') : mysql_escape_string($_POST));

$mahali=(trim($_POST)==''?
die ('UMEKOSEA: Ingiza mahali alipozaliwa') : mysql_escape_string($_POST));

$Wilaya=(trim($_POST)==''?
die ('UMEKOSEA: Ingiza wilaya aliyozaliwa') : mysql_escape_string($_POST));
$mkoa=(trim($_POST)==''?
die ('UMEKOSEA: Ingiza mkoa alikozaliwa') : mysql_escape_string($_POST));


$uraiya=(trim($_POST)==''?
die ('UMEKOSEA: Ingiza uraiya yake') : mysql_escape_string($_POST));
$jinsia=(trim($_POST)==''?
die ('UMEKOSEA: Ingiza jinsia') : mysql_escape_string($_POST));
$kabila=(trim($_POST)==''?
die ('UMEKOSEA: Ingiza kabila lake') : mysql_escape_string($_POST));

$ndoa=$_POST;
//die ('ERROR: Jaza sehemu ya ndoa') : mysql_escape_string($_POST));

$mwenzi=$_POST;
// die ('ERROR: Jaza sehemu ya mwenzi wake') : mysql_escape_string($_POST));
$ameokoka=$_POST;
// die ('ERROR: Jaza sehemu ya mwenzi ameokoka') : mysql_escape_string($_POST));
$anapoabudu=$_POST;
//die ('ERROR: Jaza sehemu ya anapoabudu') : mysql_escape_string($_POST));
$mwakawandoa=$_POST;
// die ('ERROR: Jaza sehemu ya mwaka wa ndoa') : mysql_escape_string($_POST));
$idadiyawatoto=$_POST;
// die ('ERROR: Jaza sehemu ya idadi ya watoto') : mysql_escape_string($_POST));

$wanaoabudu=$_POST;
//die ('ERROR: Jaza sehemu ya wanapoabudu') : mysql_escape_string($_POST));
$mtaa=(trim($_POST)==''?
die ('ERROR: Jaza sehemu ya mtaa unapoishi') : mysql_escape_string($_POST));

$kata=(trim($_POST)==''?
die ('UMEKOSEA: Jaza sehemu ya kata') : mysql_escape_string($_POST));
$unapoishini=(trim($_POST)==''?
die ('UMEKOSEA: Jaza sehemu ya unapoishi') : mysql_escape_string($_POST));
$simuyake=(trim($_POST)==''?
die ('UMEKOSEA: Jaza sehemu ya namba simu ') : mysql_escape_string($_POST));

$email=(!isset($_POST)|| !ereg('^([a-zA-Z0-9_-]+)([\.a-zA-Z0-9_-]+)@([a-zA-Z0-9_-]+)([\.a-zA-Z0-9_-]+)+$', $_POST))? die ('UMEKOSEA: Email imekusewa kuandikwa'):mysql_escape_string(trim($_POST));

$kazi=(trim($_POST)==''?
die ('UMEKOSEA: Jaza sehemu ya kazi') : mysql_escape_string($_POST));
$ndugu=(trim($_POST)==''?
die ('UMEKOSEA: Jaza sehemu ya ndugu wa karibu') : mysql_escape_string($_POST));

$nduguanapoishi=(trim($_POST)==''?
die ('UMEKOSEA: Jaza sehemu ya ndugu anapoishi') : mysql_escape_string($_POST));
$simuyandugu=(trim($_POST)==''?
die ('UMEKOSEA: Jaza sehemu ya simu ya ndugu') : mysql_escape_string($_POST));
$uhusiano=(trim($_POST)==''?
die ('UMEKOSEA: Jaza sehemu ya uhusiano') : mysql_escape_string($_POST));
$maoni=(trim($_POST)==''?
die ('UMEKOSEA: Jaza sehemu ya maoni ya kanisa') : mysql_escape_string($_POST));

$connection=mysql_connect('localhost', 'root','')
or die ('Unable to connect!');
mysql_select_db('tagt') or die ('Unable to select database');


$query="INSERT INTO `tagt`.`registration` (`departmentid`, `nambayamuumini`, `jinakamili`, `tareheyakuzaliwa`, `mahali`, `Wilaya`, `mkoa`, `uraiya`, `jinsia`, `kabila`, `ndoa`, `mwenzi`, `ameokoka`, `anapoabudu`, `mwakawandoa`, `idadiyawatoto`, `wanaoabudu`, `mtaa`, `kata`, `unapoishini`, `simuyake`, `email`, `kazi`, `ndugu`, `nduguanapoishi`, `simuyandugu`, `uhusiano`, `maoni`) values('$departmentid', '$nambayamuumini', '$jinakamili', '$tareheyakuzaliwa', '$mahali', '$Wilaya', '$mkoa', '$uraiya', '$jinsia', '$kabila', '$ndoa', '$mwenzi', '$ameokoka', '$anapoabudu', '$mwakawandoa', '$idadiyawatoto', '$wanaoabudu', '$mtaa', '$kata', '$unapoishini', '$simuyake', '$email', '$kazi', '$ndugu', '$nduguanapoishi', '$simuyandugu', '$uhusiano', '$maoni')";


$result=mysql_query($query) or die ("Error in query: $query. " . mysql_error());
//echo 'New record inserted with ID ' . mysql_insertde_id(). '<br\>';
echo mysql_affected_rows() . 'Umesajili muumini';
mysql_close($connection);

}
?>

help me to remove and error above .

This question has already been answered. 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.