Tag Archives: Development Tools

use php process a web form feedback-insert data-continue1

you already  had a page collect information from use input, and build a page connect to your serves databases, here is the page use for process the data, (insert the information to your databases)

here is your process_chinese_zodaic.php page sourse code;

<?php
$sender = trim($_POST[‘fname’]);
$feedback =trim($_POST[‘feedback’]);
$agree = $_POST[‘agree’];
$submit = $_POST[‘submit’];
$error=0;

if(empty($sender)||empty($feedback))
{
echo “Your must write your first name,last name,feedback”;
++$error;
}
if($agree == 1)
{
$agree = “N”;

}
else
{
$agree = “Y”;
}
if($error == 0)
{
include(“inc_connect.php”);
if($DBConnect)
{
$table = “zodiacfeedback”;
$data = date(“Y-m-d”);
$time = date(“H:i:s”);
$query = “insert into $table(message_date,message_time,sender,message,public_message)values(‘$date’,’$time’,’$sender’,’$feedback’,’$agree’)”;
$result = @mysql_query($query);
if(!$result)
{
echo “<p>unable to insert the values “. mysql_error().”</p>”;
}
else
{
echo “<p>”.htmlentities($sender).”,Thanks you for giving us feedback.</p>”;
echo “<p><a href=’view_zodiac_feedback.php’>View all of the feedback</a></p>”;

}
mysql_close($DBConnect);
}

}

?>

use php code query data from Mysql

$result = mysql_query(“SELECT * FROM example”)

That line of code is valid PHP, but it also contains valid MySQL. The text that appears between the quotations “SELECT * FROM example”, is the MySQL code.

Create a php page that will process the order using an array and display the results on another page.

your html form must look like blown:
———————————————————————————————————————————

<form action=”hardware_order.php” method=”post”>
<fieldset>
<legend>Order Form</legend>
<p><label for=”user”> Name</label> <input type=”text” name=”name” id=”user” /></p>
<p><strong>Select Some Products:</strong> <br>
<select name=”products[]” multiple>
<option value=”Sonic Screwdriver”>Sonic Screwdriver</option>
<option value=”Hammer”>Hammer</option>
<option value=”Drill”>Drill</option>
<option value=”Spanner”>Spanner</option>
</select>
<p><input type=”submit” name=”submit” value=”send”></p>
</fieldset>
</form>

————————————————————————————————————————
there are two ways can proceed this: one is :
————————————————————————————————————————-
<?php
$name =trim($_POST[‘name’]);
if(empty($_POST[‘products’])||empty($name))
{
echo “nothing has been selected”;
}
else
{
echo “Thanks “.$name.” your select products is “;

foreach($_POST[‘products’] as $o)
{
echo $o.”<br/>”;
}
}
?>
————————————————————————————————————————–
another ways is teacher’s answers:
———————————————————————————————————————————<?php
$name =trim($_POST[‘name’]);
if (!empty($name))
{     echo “<p>Welcome <b>$name</b>!</p>”;
}
else
{
echo “<p>Enter a name</p>”;
}

if(!empty($_POST[‘products’]))
{
echo “<ul>”;
echo “<p>Your product choices are:<br/>”;
foreach ($_POST[‘products’] as $value)
{
echo “<li>$value</li>”;
}
echo “</ul>”;
}
else
{
echo “<p> Nothing selected</p>”;
}
?>