Hi, this is probably a pretty simple question for you pro's but would appreciate some help as I have ogtten stuck.

I have a html form

<html>
<body>

<form action="com.php" method="post">
Firstname: <input type="text" name="firstname" />
Lastname: <input type="text" name="lastname" />
Age: <input type="text" name="age" />
<input type="submit" />
</form>

<form action="com.php" method="post">
<p><select size="1" name="firstname">
<option value="Glenn">Glenn</option>
<option value="two">two</option>
<option value="three">three</option>
</select></p>

<p><select size="1" name="lastname">
<option value="Bry">Bry</option>
<option value="Dave">Dave</option>
<option value="Andy">Andy</option>
</select></p>
<p><input type="submit"></p>
</form>
</body>
</html>

which posts to the selected values to mySql via php

mysql_query($sql,$con);


$sql="INSERT INTO Persons (FirstName, LastName, Age)
VALUES
('$_POST[firstname]','$_POST[lastname]','$_POST[age]')";
$result = mysql_query("SELECT * FROM Persons
WHERE FirstName= '[B]Glenn'[/B]");

while($row = mysql_fetch_array($result))
  {
  echo $row['FirstName'] . " " . $row['LastName'];
  echo "<br />";
  }

This then displays what resides in the database. But what I want to do is change the 'Glenn' which is in red, to the variable selected in the drop down box in the html. Ive tried lots of things to set this variable but i just cannot seem to crack it. What should i replace 'Glenn' with?

Hi, this is probably a pretty simple question for you pro's but would appreciate some help as I have ogtten stuck.

I have a html form

<html>
<body>

<form action="com.php" method="post">
Firstname: <input type="text" name="firstname" />
Lastname: <input type="text" name="lastname" />
Age: <input type="text" name="age" />
<input type="submit" />
</form>

<form action="com.php" method="post">
<p><select size="1" name="firstname">
<option value="Glenn">Glenn</option>
<option value="two">two</option>
<option value="three">three</option>
</select></p>

<p><select size="1" name="lastname">
<option value="Bry">Bry</option>
<option value="Dave">Dave</option>
<option value="Andy">Andy</option>
</select></p>
<p><input type="submit"></p>
</form>
</body>
</html>

which posts to the selected values to mySql via php

mysql_query($sql,$con);


$sql="INSERT INTO Persons (FirstName, LastName, Age)
VALUES
('$_POST[firstname]','$_POST[lastname]','$_POST[age]')";
$result = mysql_query("SELECT * FROM Persons
WHERE FirstName= '[B]Glenn'[/B]");

while($row = mysql_fetch_array($result))
  {
  echo $row['FirstName'] . " " . $row['LastName'];
  echo "<br />";
  }

This then displays what resides in the database. But what I want to do is change the 'Glenn' which is in red, to the variable selected in the drop down box in the html. Ive tried lots of things to set this variable but i just cannot seem to crack it. What should i replace 'Glenn' with?

Just replace it with $_POST[firstname]

I thought I tried this, it was 3 am and was getting tired. Thank you, you are of course correct. The next issue I have is that everything is in one php file including the mysql_connect string containing a database user name and password. Is there a better way as I don't feel it's very secure. Thanks

I always keep my connect string in a separate include file so it is used universally. I can use it in hundreds of scripts, but only need to modify it in one place.

Ultimately it has to be there in clear text.

Would be interested if the Security gurus have any comments to add. Google "php security" and you'll find good info on securing your server. There's a link I put on my site a couple of years ago to some good material: http://www.tutorius.com/securing-your-php-code.

Hope that helps.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.