Jump to content

Recommended Posts

This is reguarding a weather script

 

so i got this basic sql script

CREATE TABLE `cities` (
`id` int(11) NOT NULL auto_increment,
`city_name` varchar(100) NOT NULL default '',
`city_code` varchar( NOT NULL default '',
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=240 ;
-- 
-- Dumping data for table `countries`
-- 
INSERT INTO `cities` VALUES (1, 'Vancouver', 'BC-50');

 

 

now that's all done i need to connect to the database, via php so

 

<?php

    // Connect to database server

    $hd = mysql_connect("localhost", "username", "password")

          or die ("Unable to connect");



    // Select database

    mysql_select_db ("weather", $hd)

          or die ("Unable to select database");
          
              
    // Select info              
    $res = mysql_query("SELECT * FROM cities", $hd)

          or die ("Unable to run query");

<NEED HELP HERE>

?>

 

 

 

Now under the NEED HELP HERE i need the script to run a form of cities that's auto populated by the sql DB above, and when that is selected, i need it to POST the city code BC-50, and that is the directed to another script with is already setup, can someone help me please :)

Link to comment
https://forums.phpfreaks.com/topic/238001-need-help-with-php/
Share on other sites

$res = mysql_query("SELECT * FROM cities", $hd)
echo "";
while($row = mysql_fetch_array($res))
{
   echo "{$row['city']}";
}
echo "";

 

 

Internal server error :(

I don't think that has to do with the code.  Usually you get that error when you have a malformed .htaccess, missing php.ini or something like

that.

 

Check your error logs, specifically apache.

 

Link to comment
https://forums.phpfreaks.com/topic/238001-need-help-with-php/#findComment-1222943
Share on other sites

$res = mysql_query("SELECT * FROM cities", $hd)
echo "<select>";
while($row = mysql_fetch_array($res))
{
   echo "<option value='{$row['code']}'>{$row['city']}</option>";
}
echo "</select>";

 

 

Internal server error :(

 

 

 

OPPS double

while($row = mysql_fetch_array($res))

 

it work, but not populating

Link to comment
https://forums.phpfreaks.com/topic/238001-need-help-with-php/#findComment-1222944
Share on other sites

echo "{$row['city_name']}";}echo "

 

so this work to auto populate the form, but how do i POST the city_code.

 

thanks again, sorry i'm being a total noob right now  :-[

You need a form with an action.  Google and try it then come back for specific help.

Link to comment
https://forums.phpfreaks.com/topic/238001-need-help-with-php/#findComment-1222955
Share on other sites

$res = mysql_query("SELECT * FROM cities", $hd)
echo "<form action ='' method='POST'>";
echo "<select>";
while($row = mysql_fetch_array($res))
{
  echo "<option value='{$row['city_code']}'>{$row['city_name']}</option>";}echo "</select>
}
echo "</select>";

echo "<input type='submit' name='submitForm' value="Submit"/>";

</form>

Link to comment
https://forums.phpfreaks.com/topic/238001-need-help-with-php/#findComment-1222957
Share on other sites

unfortunantly this doesn't work.

 

$res = mysql_query("SELECT * FROM cities", $hd)
echo "<form action ='' method='POST'>";
echo "<select>";
while($row = mysql_fetch_array($res))
{
  echo "<option value='{$row['city_code']}'>{$row['city_name']}</option>";}echo "</select>
}
echo "</select>";

echo "<input type='submit' name='submitForm' value="Submit"/>";

</form>

Link to comment
https://forums.phpfreaks.com/topic/238001-need-help-with-php/#findComment-1223005
Share on other sites

<?php

    // Connect to database server

    $hd = mysql_connect("localhost", "root", "1064111")

          or die ("Unable to connect");



    // Select database

    mysql_select_db ("weather", $hd)

          or die ("Unable to select database");
          
              
    // Select info              
    $res = mysql_query("SELECT * FROM cities", $hd)

          or die ("Unable to run query");


$res = mysql_query("SELECT * FROM cities", $hd)
echo "<form action='' method='POST'>";
echo "<select>";
while($row = mysql_fetch_array($res))
{
echo "<option value='{$row['city_code']}'>{$row['city_name']}</option>";
}
echo "</select>";

echo "<input type='submit' name='submitForm' value="Submit"/>";
echo "</form>echo "</form>";echo "</form>";
<?php

    // Connect to database server

    $hd = mysql_connect("localhost", "root", "1064111")

          or die ("Unable to connect");



    // Select database

    mysql_select_db ("weather", $hd)

          or die ("Unable to select database");
          
              
    // Select info              
    $res = mysql_query("SELECT * FROM cities", $hd)

          or die ("Unable to run query");


$res = mysql_query("SELECT * FROM cities", $hd)
echo "<form action='' method='POST'>";
echo "<select>";
while($row = mysql_fetch_array($res))
{
echo "<option value='{$row['city_code']}'>{$row['city_name']}</option>";
}
echo "</select>";

echo "<input type='submit' name='submitForm' value="Submit"/>";
echo "</form>"; 

 

i knoe there's something wrong, but flustered right now  :'(

Link to comment
https://forums.phpfreaks.com/topic/238001-need-help-with-php/#findComment-1223243
Share on other sites

<?php

// Connect to database server

$hd = mysql_connect("localhost", "root", "1064111")

or die ("Unable to connect");



// Select database

mysql_select_db ("weather", $hd)

or die ("Unable to select database");


// Select info 
$res = mysql_query("SELECT * FROM cities", $hd)

or die ("Unable to run query");


$res = mysql_query("SELECT * FROM cities", $hd)
echo "<form action='' method='POST'>";
echo "<select>";
while($row = mysql_fetch_array($res))
{
echo "<option value='{$row['city_code']}'>{$row['city_name']}</option>";
}
echo "</select>";

echo "<input type='submit' name='submitForm' value="Submit"/>";
echo "</form>echo "</form>";
echo "</form>";

 

the other code above, had doubles.

Link to comment
https://forums.phpfreaks.com/topic/238001-need-help-with-php/#findComment-1223270
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.