FRIHOST • FORUMS • SEARCH • FAQ • TOS • BLOGS • COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


PHP/MySQL Dropdown value, and insert into database





honken
Ok.

Im no expert in this, and i have stumbled upon a problem i can΄t seem to solve.

This is the facts.

I have 1 database, and then tables under it.

DB: stats
tables: clubs, countries, cities, divisions

Im trying to make a small entry tool to make it easy for me.

1. table countries+cities has both one ID and one CONTRY that has data. eg: ID=1 CONTRY=Sweden, ID=2, CONTRY=Denmark

2. Now i created a dropbox that collects the information from these tables

Code:
Code:

function sel_co()

$sel_co=mysql_query("SELECT * from countries ORDER BY id");
echo "<select name=myselect>";
while($_POST=mysql_fetch_assoc($sel_co)) {
echo "<option value=$_POST[id]>$_POST[co_name]</a></option>";
}
echo "</select>";

}

This gives me a dropbox of the options i have in the table "countries".

But when i want to insert this info (just want to insert the ID) to my main table "club".
It gives me a blank input.

Here is some other code bits.

input.php
Code:

<?php
include 'db_inc.php';
include 'functions.php';
?>
<html>
<body>
<table  border="0" bgcolor="#fff">
<form action="input_db.php" method="post">
<tr>
    <td class="head">Name</td>
    <td class="head">Name Short</td>
    <td class="head">Nickname</td>
    <td class="head">Founded</td>
    <td class="head">Arena</td>
    <td class="head">Division</td>
    <td class="head">Country</td>
    <td class="head">City</td>
    <td class="head">Logo</td>
    <td class="head">Facts</td>
  </tr>
<tr>
<td class="input"><input type="text" name="club_name" size="12"></td>
<td class="input"><input type="text" name="club_short" size="12"></td>
<td class="input"><input type="text" name="club_nickname" size="12"></td>
<td class="input"><input type="text" name="club_founded" size="12"></td>
<td class="input"><input type="text" name="club_arena" size="12"></td>
<td class="input"><? sel_div() ?></td>
<td class="input"><? sel_co() ?></td>
<td class="input"><? sel_ci() ?></td>
<td class="input"><input type="text" name="club_logo" size="12"></td>
<td class="input"><input type="text" name="club_fact" size="12"></td>
</tr>
</table>
<input type="submit" name="submit">

</form>




</body>
</html>


input_db.php
Code:

<?php
include 'db_inc.php';
include 'functions.php';



$club_name = $_POST['club_name'];
$club_short = $_POST['club_short'];
$club_nickname = $_POST['club_nickname'];
$club_founded = $_POST['club_founded'];
$club_arena = $_POST['club_arena'];
$club_division = $_POST['club_division'];
$club_country = $_POST['club_country'];
$club_city = $_POST['club_city'];
$club_logo = $_POST['club_logo'];
$club_fact = $_POST['club_fact'];

$dbSQL = "INSERT INTO club_info(cl_club_name, cl_club_short, cl_club_nickname, cl_club_founded, cl_club_arena, cl_club_division, cl_club_country, cl_club_city, cl_club_logo, cl_club_fact)
VALUES ('$club_name', '$club_short', '$club_nickname', '$club_founded', '$club_arena', '$club_division', '$club_country', '$club_city', '$club_logo', '$club_fact')";

mysql_query($dbSQL) or die('Query "' . $dbSQL . '" failed: ' . mysql_error());

echo "OK <a href='input.php'>Input more</a><br>";

?>


Im pretty sure that there is something with the value from the function and/or the input_db.php that i need to do something else to.

Anyone have the answer to this?


/honken
Peterssidan
So you have a table named club_info? You didn't mentioned it when you listed the other tables.

Is something added to the table? If you print $dbSQL, does it look correct?

Is sel_co() called in input_db.php? I guess that would screw up things because you write to $_POST in the while loop. It's better to use a local variable inside the function.
honken
true.

i forget to mention the club_info.

basically i want to do like this (if i translate to text)


get ID from table DIVISION and INPUT to Club_info CL_CLUB_DIVISION ($club_division)

Its the fasted way i can say what i need and where i need to put it.
Related topics
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.