Dynadot Aftermarket: discover domain gems worth investing in. Visit our aftermarket.

[Resolved] My next question (PHP)

SpaceshipSpaceship
Spacemail by SpaceshipSpacemail by Spaceship
SpaceshipSpaceship
Watch

flishess

Established Member
Impact
6
My next question (PHP)

I am trying to get the "platforms" listed in my database to show up where "$platform" is at in the drop down box.

Code:
<?
include("config.php");
?>
<html>
<form method="post" action="cp_admin/submitgame.php">

<h3>Title:</h3>
<input type="text" NAME="title">

<h3>Description:</h3>
<textarea name="description" rows="10" cols="48"></textarea>

<h3>Platform:</h3>
<select name="platform">
  <option value="[COLOR=Red]$platform[/COLOR]">
</select>
<br>
<br>
<INPUT TYPE="submit" name="submit" value="submit">
</form>
</html>

can anyone help out?
 
0
Close
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
$platform is not within php tags. It should be:-

PHP:
<?PHP echo $platform ?>
 
0
Close
Is it even set to a variable yet, from the code it doesn't look like it is, unless you set it in config.php.

I'll be on in a few hours if you need help :tu:
 
0
Close
here is what I have now, I tried it with GET and POST - neither of the two work.

Code:
<?
include("config.php");
$platform = mysql_real_escape_string($_GET['platname']);
?>
<html>
<form method="post" action="cp_admin/submitgame.php">

<h3>Title:</h3>
<input type="text" NAME="title">

<h3>Description:</h3>
<textarea name="description" rows="10" cols="48"></textarea>

<h3>Platform:</h3>
<select name="platform">
  <option value="<?PHP echo $platform ?>">
</select>
<br>
<br>
<INPUT TYPE="submit" name="submit" value="submit">
</form>
</html>

I think it needs to say something about selecting the row that the table is, or something like that instead of GET or POST.

I also tried this, and it does not work either:

Code:
<?
include("config.php");
$platform = $row['platname'];
while($row = mysql_fetch_array( $result )) {
$result = mysql_query("SELECT * FROM platform") 
or die(mysql_error());
?>
<html>
<form method="post" action="cp_admin/submitgame.php">

<h3>Title:</h3>
<input type="text" NAME="title">

<h3>Description:</h3>
<textarea name="description" rows="10" cols="48"></textarea>

<h3>Platform:</h3>
<select name="platform">
  <option value="<?PHP echo $row['platname']; ?>">
</select>
<br>
<br>
<INPUT TYPE="submit" name="submit" value="submit">
</form>
</html>
 
Last edited:
0
Close
Code:
$result = mysql_query("SELECT * FROM platform");

while ($row = mysql_fetch_assoc($result)) {

$platform = '<option value="' . $row['platname']. '">';

}
?>

<select name="platform">
<?php echo $platform; ?>
</select>

Not sure if that will work in this situation, as its just off the top of my head but test it out and let me know.
 
0
Close
edit, I don't get any errors with your version, but It doesn't show up either with the platforms.
 
0
Close
I actually forgot a pretty important part of that code

Code:
$platform = '<option value="' . $row['platname']. '">';

Should be

Code:
$platform = '<option value="' . $row['platname']. '">' . $row['platname'] . '</option>';
 
0
Close
Edit, that worked, however there are more than one Platforms listed in the database and it only shows the last one.
 
0
Close
try adding

Code:
$platform = '';

prior to the while statement. I ran a quick test on this on my home server and all came out ok. If this doesn't work, let me know and I'll continue to troubleshoot.
 
0
Close
Like, this: it didn't work...

Code:
$result = mysql_query("SELECT * FROM platform");
[COLOR=Red]$platform = '';[/COLOR]
while ($row = mysql_fetch_assoc($result)) {

$platform = '<option value="' . $row['platname']. '">';

}
?>

<select name="platform">
<?php echo $platform; ?>
</select>
 
0
Close
Try this:

PHP:
$result = mysql_query("SELECT * FROM platform");
$platform = '';
while ($row = mysql_fetch_assoc($result)) {

$platform .= '<option value="' . $row['platname']. '">' . $row['platname']. '</option>';

}
?>

<select name="platform">
<?php echo $platform; ?>
</select>
 
0
Close
mikor: Thanks that fixed it! Thanks to all those that helped!
 
0
Close
There we go, Thanks Mikor I knew I was missing a character somewhere :)
 
0
Close
DomainEasy: white label portfolios are live. Enable yours.

We're social

Escrow.com
Spaceship
Domain Recover
CryptoExchange.com

NamePros updates

Switch between accounts
You can now stay logged in to more than one NamePros account in the same browser. Click your avatar, then "Accounts in this browser", to...
AIVikings
Catchy
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back