List:General Discussion« Previous MessageNext Message »
From:Paul DuBois Date:March 23 2003 10:38pm
Subject:Re: MySQL Two Tables - PHP Query Insert UPdate
View as plain text  
At 10:46 +0000 3/22/03, Andrew wrote:
>Hi MySQL
>
>I am now working on the insert into two tables :)
>
>items and items_city
>
>In each table there is the ID which is unique.  This is what I have 
>so far and I
>am not getting very far with it.
>
>select from city and display ready for check box selection.
>
>[code]
>echo "Select Cities and Towns<br>";
>echo "</td></tr>";
>$queryC="SELECT CountyID, City, CityID FROM city WHERE CountyID=".$CountyID."
>ORDER BY City";
>$result=mysql_query($queryC,$con_id);
>$count=0;
>echo "<tr>";
>while($row=mysql_fetch_array($result)){
>
>$county_id=$row['CountyID'];
>         $city_id=$row['CityID'];
>		$city=$row['City'];
>if ($CityID == $city_id)
>
>$city="city_".$cityId;
>echo"<td width=\"25%\"><input type=\"checkbox\"
> name=\"$city_id\">$city</td>";
>$count++;
>  if($count ==3){
>   echo "</tr><tr>";
>   $count=0;
>  }
>}
>
>
>[/code]
>
>once selected this is the form that should do the inserts ->
>
>
>
>[code]
>
><?
>require("connection.php");
>DBInfo();
>Root();
>$con_id=mysql_connect("$DBHost","$DBUser","$DBPass");
>mysql_select_db($DBName);
>mysql("$DBName","INSERT INTO Items VALUES(
>'$ItemSKU',
>'$ItemName',
>'$ItemDescription',
>'$PostCode',
>'$Category',
>'$CityID',
>'$CTelephone',
>'$ItemID',
>'$Cfax',
>'$Cemail',
>'$Caddress',
>'$CTown',
>'$Cwww')");
>$nItemId=mysql_insert_id();
>
>$queryC="select * from city";
>$result=mysql_query($queryC,$con_id);
>
>while($row=mysql_fetch_array($result)){
>
>$cityId=$row['CityID'];
>$city="city_".$cityId;
>  $c=$$city;
>if($c == "on"){
>	$query1="insert into item_city 
>(item_id,city_id)values('$nItemId','$cityId')";
>	$result1=mysql_query($query1);
>  }
>}
>/////////////////////////
>?>



>
>
>I have looked at this for too long and seem to be seeing the same thing :(  so
>if someone can see something aloof that would be great :)
>
>Andrew

I can see one thing: You're continuing to ignore the advice that you
have received several times on this list to include some error checking,
and to print some information when an error occurs.

The code above includes error checking for not one MySQL call.  That's
a sure way to get nowhere in your efforts to figure out why things go
wrong when things go wrong.

Why shoot yourself in the foot?
Thread
MySQL Two Tables - PHP Query Insert UPdateAndrew22 Mar
  • Re: MySQL Two Tables - PHP Query Insert UPdatePaul DuBois23 Mar