...

View Full Version : Vaule / Question might be really easy



bigredkacy
06-11-2005, 06:21 AM
on this adddealer page (http://pastebin.com/298760) how can i have to country option save to rcnitror_zipcode.dealer.country ?
since its getting the vaules from rcnitror_zipcode.countrys.name
starts at line 22


<?php
if(isset($_GET['submit'])){
mysql_connect("localhost", "rcnitror_kacy", "");
mysql_select_db("rcnitror_zipcode");
$query = "insert into dealers(`address1`,`country`,`name`,`phone`,`url`,`fulltime`,`onroad`,`offroad`,`fax`,`email`,`zip`, `hours`,`carry`,`order`) values ('".$_GET["Address1"]."','".$_GET["Country"]."','".$_GET["Name"]."','".$_GET["Phone"]."','".$_GET["URL"]."','".$_GET["fulltime"]."','".$_GET["onroad"]."','".$_GET["offroad"]."','".$_GET["Fax"]."','".$_GET["Email"]."','".$_GET["Zip"]."','".$_GET["hours"]."','".$_GET["carry"]."','".$_GET['order']."')";
mysql_query($query) or die(mysql_error());
if(!$query){
echo "Sorry but there was an error when processing your request. Please try again. " . mysql_error();
}
else
{
echo "Success! <a href='search.html'>Return to search</a>";
}
}
else
{
?>
<body>
<form action='adddealer.php' method='get'>
<?php
mysql_connect("localhost", "rcnitror_kacy", "");
mysql_select_db("rcnitror_zipcode");
$select = "SELECT DISTINCT name FROM countries ORDER BY name";

//the result of the query will be stored here
$rs = mysql_query($select) or die(mysql_error());

echo "<label>Please select your country: ";
echo "<select name='country' id='country'>";


//Each row in the rs will be an option
while ($row = mysql_fetch_assoc($rs))
{
echo "<option value='".$row['name']."'>".$row['name']."</option>";
}
}

//this closes the open .html tags
echo "</label>";
echo "</select>";
?>
<br>
Dealer Name: <input type='text' name='Name'><br>
Hours: <input type='text' name='Hours'><br>
Telephone Number: <input type='text' name='Phone'><br>
Fax Number: <input type='text' name='Fax'><br>
Email Address: <input type='text' name='Email'><br>
Website: <input type='text' name='URL'><br>
Postcode: <input type='text' name='Zip'><br>
Address: <input type='text' name='Address1'><br>
Full time hobby shop:
<input type='radio' name='fulltime' value='yes'>Yes
<input type='radio' name='fulltime' value='No'>No<br>
On-road track:
<input type='radio' name='onroad' value='Yes'>Yes
<input type='radio' name='onroad' value='No'>No<br>
Off-road track:
<input type='radio' name='offroad' value='Yes'>Yes
<input type='radio' name='offroad' value='No'>No<br>
Carry Integy parts in stock:
<input type='radio' name='carry' value='Yes'>Yes
<input type='radio' name='carry' value='No'>No<br>
Special order Integy parts:
<input type='radio' name='order' value='Yes'>Yes
<input type='radio' name='order' value='no'>No<br>

<input type='submit' name='submit'>
</form>
</body>
</html>

<?php ?>

SeeIT Solutions
06-11-2005, 06:23 AM
save the id of the country in the dealers table and then when you need to get the name out search the country names table to find the name.

bigredkacy
06-11-2005, 06:26 AM
im 2 new at this how would i do that? or what?

SeeIT Solutions
06-11-2005, 06:44 AM
I'm assuming you country table has columns id and name (at least) with id being an auto incrementing key column.


This will be the new code you need.


<?php
if(isset($_GET['submit'])){
mysql_connect("localhost", "rcnitror_kacy", "");
mysql_select_db("rcnitror_zipcode");
$query = "insert into dealers(`address1`,`country`,`name`,`phone`,`url`,`fulltime`,`onroad`,`offroad`,`fax`,`email`,`zip`, `hours`,`carry`,`order`) values ('".$_GET["Address1"]."','".$_GET["Country"]."','".$_GET["Name"]."','".$_GET["Phone"]."','".$_GET["URL"]."','".$_GET["fulltime"]."','".$_GET["onroad"]."','".$_GET["offroad"]."','".$_GET["Fax"]."','".$_GET["Email"]."','".$_GET["Zip"]."','".$_GET["hours"]."','".$_GET["carry"]."','".$_GET['order']."')";
mysql_query($query) or die(mysql_error());
if(!$query){
echo "Sorry but there was an error when processing your request. Please try again. " . mysql_error();
}
else
{
echo "Success! <a href='search.html'>Return to search</a>";
}
}
else
{
?>
<body>
<form action='adddealer.php' method='get'>
<?php
mysql_connect("localhost", "rcnitror_kacy", "");
mysql_select_db("rcnitror_zipcode");
$select = "SELECT name,id FROM countries ORDER BY name";

//the result of the query will be stored here
$rs = mysql_query($select) or die(mysql_error());

echo "<label>Please select your country: ";
echo "<select name='country' id='country'>";


//Each row in the rs will be an option
while ($row = mysql_fetch_assoc($rs))
{
echo "<option value='".$row['id']."'>".$row['name']."</option>";
}
}

//this closes the open .html tags
echo "</label>";
echo "</select>";
?>
<br>
Dealer Name: <input type='text' name='Name'><br>
Hours: <input type='text' name='Hours'><br>
Telephone Number: <input type='text' name='Phone'><br>
Fax Number: <input type='text' name='Fax'><br>
Email Address: <input type='text' name='Email'><br>
Website: <input type='text' name='URL'><br>
Postcode: <input type='text' name='Zip'><br>
Address: <input type='text' name='Address1'><br>
Full time hobby shop:
<input type='radio' name='fulltime' value='yes'>Yes
<input type='radio' name='fulltime' value='No'>No<br>
On-road track:
<input type='radio' name='onroad' value='Yes'>Yes
<input type='radio' name='onroad' value='No'>No<br>
Off-road track:
<input type='radio' name='offroad' value='Yes'>Yes
<input type='radio' name='offroad' value='No'>No<br>
Carry Integy parts in stock:
<input type='radio' name='carry' value='Yes'>Yes
<input type='radio' name='carry' value='No'>No<br>
Special order Integy parts:
<input type='radio' name='order' value='Yes'>Yes
<input type='radio' name='order' value='no'>No<br>

<input type='submit' name='submit'>
</form>
</body>
</html>

<?php ?>

And anywhere you need to display the country name you will need to use this.


mysql_connect("localhost", "rcnitror_kacy", "");
mysql_select_db("rcnitror_zipcode");
$query = "SELECT * FROM `dealers` WHERE `id` = '$id' LIMIT 1;";
$results = mysql_query($query) or die(mysql_error());
$row = (mysql_fetch_assoc($results));
//variables accessible by $row['columnname']
var_dump($row); //show all results

//get country name
$query2 = "SELECT name FROM `countries` WHERE `id` = '".$row['country']."';";
$results2 = mysql_query($query2) or die(mysql_error());
$row2 = (mysql_fetch_assoc($results2));
$country = $row2['name'];

echo $country;//show country name

bigredkacy
06-11-2005, 07:03 AM
ok let me try



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum