I would appreciate some pointers on PHP. Im very much a beginner and am not sure how to get my head around what i want to achieve.
Basically, i have uploaded a stock list to a MySQL database. I have then created a simple search form using PHP to display the results.
What i would like, is for each result to have a check box next to it, which the user could then tick and then click to request a quotation for those parts that have been selected. Have a look here at what i currently have, and here at what i am trying to achieve.
Here is all i have so far:
<?php
// Check if form submitted
if (isset($_POST['Search']) || isset($_POST['Alternatives'])){
// Get form input
$PartSearch = $_POST['PartNumber'];
// Strip everything except letter, digit, underscore, dash or space
$PartSearch = preg_replace("/[^\w| |-]/i", "", $PartSearch);
echo "Results for \"". $PartSearch ."\":<br /><br />";
// Connect to database
mysql_connect("localhost", "Username", "Password") or die(mysql_error());
mysql_select_db("Database") or die(mysql_error());
// Search the database
$query = mysql_query("SELECT * FROM `Stock Search` WHERE `Part Number` LIKE '%$PartSearch%'") or die(mysql_error());
// Display the results
$NumberResults = mysql_num_rows($query);
if ($NumberResults == 0) {
echo "No exact results were found for: \"".$PartSearch."\"<br />";
echo "<a href=\"/search.php\">Click here</a> to go back <br />";
} else {
echo "$NumberResults matching parts found <br />";
echo "<a href=\"/search.php\">Click here</a> to go back <br />";
echo "<table border=\"1\" align=\"center\">";
echo "<tr><th>Part Number</th>";
echo "<th>Manufacturer</th>";
echo "<th>Quantity</th>";
echo "<th>RFQ</th></tr>";
while ($rows = mysql_fetch_array($query)) {
echo "<tr><td>";
echo $rows['Part Number'];
echo "</td><td>";
echo $rows['Manufacturer'];
echo "</td><td>";
echo $rows['Quantity'];
echo "</td><td>";
echo "<input type=\"checkbox\" value=\"1\" name=\"RFQ\"></td></tr>";
}
echo "</table>";
}
} else {
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
Part Number: <input name="PartNumber" type="text" /><br />
<input name="Search" type="submit" value="Search" />
</form>
<?php
}
?>
Question
Bollard
Hello,
I would appreciate some pointers on PHP. Im very much a beginner and am not sure how to get my head around what i want to achieve.
Basically, i have uploaded a stock list to a MySQL database. I have then created a simple search form using PHP to display the results.
What i would like, is for each result to have a check box next to it, which the user could then tick and then click to request a quotation for those parts that have been selected. Have a look here at what i currently have, and here at what i am trying to achieve.
Here is all i have so far:
<?php // Check if form submitted if (isset($_POST['Search']) || isset($_POST['Alternatives'])){ // Get form input $PartSearch = $_POST['PartNumber']; // Strip everything except letter, digit, underscore, dash or space $PartSearch = preg_replace("/[^\w| |-]/i", "", $PartSearch); echo "Results for \"". $PartSearch ."\":<br /><br />"; // Connect to database mysql_connect("localhost", "Username", "Password") or die(mysql_error()); mysql_select_db("Database") or die(mysql_error()); // Search the database $query = mysql_query("SELECT * FROM `Stock Search` WHERE `Part Number` LIKE '%$PartSearch%'") or die(mysql_error()); // Display the results $NumberResults = mysql_num_rows($query); if ($NumberResults == 0) { echo "No exact results were found for: \"".$PartSearch."\"<br />"; echo "<a href=\"/search.php\">Click here</a> to go back <br />"; } else { echo "$NumberResults matching parts found <br />"; echo "<a href=\"/search.php\">Click here</a> to go back <br />"; echo "<table border=\"1\" align=\"center\">"; echo "<tr><th>Part Number</th>"; echo "<th>Manufacturer</th>"; echo "<th>Quantity</th>"; echo "<th>RFQ</th></tr>"; while ($rows = mysql_fetch_array($query)) { echo "<tr><td>"; echo $rows['Part Number']; echo "</td><td>"; echo $rows['Manufacturer']; echo "</td><td>"; echo $rows['Quantity']; echo "</td><td>"; echo "<input type=\"checkbox\" value=\"1\" name=\"RFQ\"></td></tr>"; } echo "</table>"; } } else { ?> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> Part Number: <input name="PartNumber" type="text" /><br /> <input name="Search" type="submit" value="Search" /> </form> <?php } ?>Thanks for any help
Link to comment
Share on other sites
7 answers to this question
Recommended Posts