Jump to content

Call for


mrlankee

Recommended Posts

I have created a form and the .php file that collects the selected data. What I cannot seem to find out is the code to put into the process.php to retrieve information from my sql db that a crawler retrieved.

 

Form

<form action="process.php" method="post"> 
Game: <select name="game"> 
<option>Select a Game</option>
<option>Counter-Strike 1.3</option>
<option>Counter-Strike: Source</option>
<option>Counter-Strike: GO</option>
<option>ArmA: 3</option>
<option>Call Of Duty: 4</option>
</select>
Slots <select name="game"> 
<option>Desired Slots</option>
<option>10</option>
<option>11</option>
<option>12</option>
<option>13</option>
<option>14</option>
<option>15</option>
<option>16</option>
<option>17</option>
<option>18</option>
<option>19</option>
<option>20</option>
<option>21</option>
<option>22</option>
<option>23</option>
<option>24</option>
<option>25</option>
<option>26</option>
<option>27</option>
<option>28</option>
<option>29</option>
<option>30</option>
</select> 
<input type="submit" />
</form>

Process.php

<?php
$quantity = $_POST['quantity'];
$item = $_POST['item'];

echo "You are looking for a ". $game . " server with " . $slots . " slots.<br />";
echo "We are processing your request!";

?>

I am looking for it to be out putted into a nice table as such

<TR>
      <TH><font color="red"><b>Company</B></font></TH>
      <TH><font color="red"><b>Slots</B></font></TH>
	  <TH><font color="red"><b>Pricing</B></font></TH>
   </TR>
   <TR ALIGN="CENTER">
      <TD>$company</TD>
      <TD>$slots</TD>
	  <TD>$price</TD>
   </TR>

Thanks for your assistance!

Link to comment
Share on other sites

All three scripts are different, which makes it very confusing and your question doesn't relate to the code provided (Well at least I don't think it does) ??? 

 

You're missing the value attribute in you <option> tag:

<form action="process.php" method="post">
  Game:
  <select name="game">
    <option>Select a Game</option>
    <option value="Counter-Strike 1.3">Counter-Strike 1.3</option>
    <option value="Counter-Striker: Source">Counter-Strike: Source</option>
    <option value="Counter-Strike: GO">Counter-Strike: GO</option>
    <option value="ArmA: 3">ArmA: 3</option>
    <option value="Call of Duty: 4">Call Of Duty: 4</option>
  </select>
  Slots
  <select name="game">
    <option>Desired Slots</option>
    <?php 
		  for ( $x = 10; $x <= 30 ; $x++ ) {
				echo '<option value="' . $x . '">' . $x . '</option>' . "\n";
			}
		?>
  </select>
  <input type="submit" name="submit" value="Submit" />
</form>
Edited by Strider64
Link to comment
Share on other sites

 

All three scripts are different, which makes it very confusing and your question doesn't relate to the code provided (Well at least I don't think it does) ??? 

 

You're missing the value attribute in you <option> tag:

<form action="process.php" method="post">
  Game:
  <select name="game">
    <option>Select a Game</option>
    <option value="Counter-Strike 1.3">Counter-Strike 1.3</option>
    <option value="Counter-Striker: Source">Counter-Strike: Source</option>
    <option value="Counter-Strike: GO">Counter-Strike: GO</option>
    <option value="ArmA: 3">ArmA: 3</option>
    <option value="Call of Duty: 4">Call Of Duty: 4</option>
  </select>
  Slots
  <select name="game">
    <option>Desired Slots</option>
    <?php 
		  for ( $x = 10; $x <= 30 ; $x++ ) {
				echo '<option value="' . $x . '">' . $x . '</option>' . "\n";
			}
		?>
  </select>
  <input type="submit" name="submit" value="Submit" />
</form>

First, thank you for the edit didn't notice that  :pirate:

 

Secondly; My desired effect. The individual submits above form request, bringing them to process.php... In the process document, I am lost as to send a request to say a "gathered" file in my database which is storing information from a crawler. ultimately out putted to a third page called "compare.php" that shows the values submited.

 

desired result

 

   <TR>
      <TH><font color="red"><b>Company</B></font></TH>
      <TH><font color="red"><b>Game</B></font></TH>
      <TH><font color="red"><b>Slots</B></font></TH>
 <TH><font color="red"><b>Pricing</B></font></TH>
   </TR>
   <TR ALIGN="CENTER">
      <TD>$company</TD>
      <TD>$game</TD>
 <TD>$slots</TD>
 <TD>$price</TD>
   </TR>
Link to comment
Share on other sites

It looks you you copy/pasted three different scripts in the forlorn hope they will magically work together.

 

1. Your first piece of code (the form) has two "selects" each with the name "game". They need different names.

 

2. You second code block is expecting form data called "item" and "quantity", neither of which are in the form.

 

3. Your third code uses variables "company", "game", "slots" and "price". None of those are defined anywhere else.

Link to comment
Share on other sites

If I'm reading this right, you're asking how to get information from the form into and out of the database, yes? If so, you'll need to look into PDO for database functionality. I'm assuming you've already got the database set up - if not, that's going to have to be step one, obviously.

Link to comment
Share on other sites

I've created a test page to show what I want on the front end..

 

http://thegoodliferpg.com/test/test.html   <-- i only set up "game servers"

 

Test html core

 

<form action="process.php" method="post">
  Game:
  <select name="game">
    <option>Select a Game</option>
    <option value="Counter-Strike 1.3">Counter-Strike 1.3</option>
    <option value="Counter-Striker: Source">Counter-Strike: Source</option>
    <option value="Counter-Strike: GO">Counter-Strike: GO</option>
    <option value="ArmA: 3">ArmA: 3</option>
    <option value="Call of Duty: 4">Call Of Duty: 4</option>
  </select>
  Slots
  <select name="slots">
    <option>Desired Slots</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
<option value="13">13</option>
<option value="14">14</option>
<option value="15">15</option>
<option value="16">16</option>
<option value="17">17</option>
<option value="18">18</option>
<option value="19">19</option>
<option value="20">20</option>




</select> 
 <input type="submit" />


</form>

Process Core

<?php
$game = $_POST['game'];
$slots = $_POST['slots'];


echo "You are looking for a ". $game . " server with " . $slots . " slots.<br />";
echo "We are processing your request!";


 

header( "refresh:2;url=servercompare.php" );    

?> 

Compare Core

<center><TABLE BORDER="5"    WIDTH="50%"   CELLPADDING="4" CELLSPACING="3">
   <TR>
      <TH COLSPAN="6"><BR><H3>Company Comparison</H3>
      </TH>
   </TR>
   <TR>
      <TH><font color="red"><b>Company</B></font></TH>
      <TH><font color="red"><b>Slots</B></font></TH>
	  <TH><font color="red"><b>Monthly</B></font></TH>
  	  <TH><font color="red"><b>Quartly</B></font></TH>
	  <TH><font color="red"><b>Semi-Annual</B></font></TH>
	  <TH><font color="red"><b>Choose</B></font></TH>
   </TR>
         <TR ALIGN="CENTER">
      <TD>Data 1</TD>
      <TD>Data 2</TD>
	  <TD>Data 3</TD>
	  <TD>Data 2</TD>
	  <TD>Data 3</TD>
	  <td><a href="#">Select</a></td>
   </TR>

what i'm stuck on is what code I put into the process to send to the db.. "here is what individual wants"... and DB to send back .. "here is what I got"..

 

 

I really appreciate the help!

Edited by mrlankee
Link to comment
Share on other sites

from what I am getting, I add the following into my process.php?

<?php
$dbhost = 'localhost';
$dbuser = 'myuser';
$dbpass = 'mypw';
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
if(! $conn )
{
die('Could not connect: ' . mysql_error());
}
$sql = "SELECT `company`, `price`, `reviews`, `locations`, `date` FROM `MYDBNAME`.`gameservers`";

mysql_select_db('MYDBNAME');
$retval = mysql_query( $sql, $conn );
if(! $retval )
{
die('Could not get data: ' . mysql_error());
}
while($row = mysql_fetch_array($retval, MYSQL_ASSOC))
{
echo "Company :{$row['company']} <br> ".
"Price : {$row['price']} <br> ".
"Locations : {$row['location']} <br> ".
"Reviews : {$row['reviews']} <br> ".
"--------------------------------<br>";
}
echo "Fetched data successfully\n";
mysql_close($conn);
?>

wondering how I would send this information to my servercompare.html

Edited by mrlankee
Link to comment
Share on other sites

First off, don't use that code. The mysql_* functions have been deprecated in php for about a decade and are slated for removal at some point. I know it'd break a lot of the internet, but I do wish they'd just remove the darned things already. What you want to do is read up on PDO by following the link I put in my last post. You'll create a new PDO object with your database credentials, query the database for the information you're looking for and use the returned data to populate the table you're building. You can do that last part by combining your last two scripts into one.

<?php
$connection = new PDO(/* credentials */);
$sql = $connection->query(/* query string */);
$returnArray = $sql->fetchAll(PDO::FETCH_OBJ);
?>
<table>
	<thead>
		<th>Company
		<th>Price
		<th>Location
		<th>Review
	</thead>
	<tbody>
<?php foreach($returnArray as $return){ ?>
		<tr>
			<td><?= $return->comapny; ?>
			<td><?= $return->price; ?>
			<td><?= $return->location; ?>
			<td><?= $return->review; ?>
		</tr>
<?php } ?>
	</tbody>
</table>

I have neither tested the above code nor had my second cup of coffee yet this morning, so understand that this is not a copy and paste solution. However, it should point you in the right direction. Once you get to this point, post back here if you're still having problems.

 

Also (and a bit off topic) don't use 'date' as a column name. I thought it was reserved, but a quick search shows me that it's not. Hunh. However, it is a MySQL function and can make things confusing.

Link to comment
Share on other sites

First off, don't use that code. The mysql_* functions have been deprecated in php for about a decade and are slated for removal at some point. I know it'd break a lot of the internet, but I do wish they'd just remove the darned things already. What you want to do is read up on PDO by following the link I put in my last post. You'll create a new PDO object with your database credentials, query the database for the information you're looking for and use the returned data to populate the table you're building. You can do that last part by combining your last two scripts into one.

<?php
$connection = new PDO(/* credentials */);
$sql = $connection->query(/* query string */);
$returnArray = $sql->fetchAll(PDO::FETCH_OBJ);
?>
<table>
	<thead>
		<th>Company
		<th>Price
		<th>Location
		<th>Review
	</thead>
	<tbody>
<?php foreach($returnArray as $return){ ?>
		<tr>
			<td><?= $return->comapny; ?>
			<td><?= $return->price; ?>
			<td><?= $return->location; ?>
			<td><?= $return->review; ?>
		</tr>
<?php } ?>
	</tbody>
</table>

I have neither tested the above code nor had my second cup of coffee yet this morning, so understand that this is not a copy and paste solution. However, it should point you in the right direction. Once you get to this point, post back here if you're still having problems.

 

Also (and a bit off topic) don't use 'date' as a column name. I thought it was reserved, but a quick search shows me that it's not. Hunh. However, it is a MySQL function and can make things confusing.

 

 

Thank you for your guidance,  I give er the old collage try and report back.

Link to comment
Share on other sites

My pleasure - let us know how it goes and if you run into any problems, just ask!

Hit a bump, i understand the fetch and return to output the data. What I don't get is how the submit form tells the DB to do the fetch process and return with the values in the submitted form? If that makes sense lol.

Link to comment
Share on other sites

Basically, your data entry form can be a separate page. Your opening tag for the form should look something like this:

<form name='myForm' action='processMyForm.php' method='post'>

where the code we've been discussing above is in the file processMyForm.php. Check at the top of that file to make sure the $_POST[] variables that you're expecting are set. If they are, do what you need to do to the values to make sure they're safe and in the format you're expecting, then run the query using those values. If they're not set, you can redirect the user to the form page or display an error or play a fun sound clip or whatever - you just won't be running the query.

 

That's the easiest way I can think of to handle it - there are many other methods, but you gotta learn to walk before attempting to run.

Link to comment
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.