Dynadot โ€” .com Registration $8.99

[Resolved] My next question (PHP)

Spaceship Spaceship
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
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
AfternicAfternic
$platform is not within php tags. It should be:-

PHP:
<?PHP echo $platform ?>
 
0
•••
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
•••
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
•••
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
•••
edit, I don't get any errors with your version, but It doesn't show up either with the platforms.
 
0
•••
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
•••
Edit, that worked, however there are more than one Platforms listed in the database and it only shows the last one.
 
0
•••
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
•••
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
•••
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
•••
mikor: Thanks that fixed it! Thanks to all those that helped!
 
0
•••
There we go, Thanks Mikor I knew I was missing a character somewhere :)
 
0
•••
Appraise.net
Unstoppable Domains
Domain Recover
DomainEasy โ€” Live Options
  • The sidebar remains visible by scrolling at a speed relative to the pageโ€™s height.
Back