Jump to content

PHP Echo result


Go to solution Solved by Ch0cu3r,

Recommended Posts

Still learning...............So I have now been able to make my dropdown menu pass the results to the php page from the data stored in mysql and show the results with echo on the php page. But I would like those results to be displayed on the same page. How would I start going about this?

Edited by fisher7679
Link to comment
https://forums.phpfreaks.com/topic/282616-php-echo-result/
Share on other sites

So the form and database code are in two separate files? For example the the html form is in form.php and it submits the form to add_to_database.php.

 

But what you're wanting it do is display the form and database results on same page? If so make the form in form.php submit to itself (<form action="form.php" method="post">) Then  just include add_to_database.php in form.php where you want the results to appear. Example

<?php include 'add_to_database.php'; ?>

<form action="form.php" method="post">
   // your form fields here
</form>
Edited by Ch0cu3r
Link to comment
https://forums.phpfreaks.com/topic/282616-php-echo-result/#findComment-1452107
Share on other sites

  • Solution

Change the html page to a php page (by changing the file extension to .php). Then change the forms submit action to submit to itself. And include the php page below the form using include (like my example above)

Edited by Ch0cu3r
Link to comment
https://forums.phpfreaks.com/topic/282616-php-echo-result/#findComment-1452109
Share on other sites

Ok, not sure why but the echo results are not showing on the page. Here is the form code. Also I changed it to .php, added the include and set the action to post to itself like stated above.

<form  action="f0rm.php" method="post">
<p align="center" style="margin-bottom: 0">
<b><font size="3">Test</font></b></p>
<p align="center" style="margin-bottom: 0">
<option value=""></option>
<option value=""></option>
<option value=""></option>
<option value=""></option>
</select>
<br />
<br />
</p>
<p align="center">  <input class="button" type="submit" name="submit" value="Submit">
</p>
</form>
<!--?php include 'data.php'; ?-->

Could it be an issue with the echo?

 

Here us the php code I am using for tetsting

<?php 
mysql_connect("", "", "") or die(mysql_error());  
mysql_select_db("") or die(mysql_error()); 

$term1 = $_POST['term1'];
$term2 = $_POST['term2'];
$term3 = $_POST['term3'];
$term4 = $_POST['term4'];
$term5 = $_POST['term5'];
$term6 = $_POST['term6'];
$term7 = $_POST['term7'];
$term8 = $_POST['term8'];
$term9 = $_POST['term9'];
$term10 = $_POST['term10'];

$sql = ("my sql string here");


$rs_result = mysql_query ($sql);
$num_rows = mysql_num_rows($rs_result);
$total_rows = mysql_num_rows($data2);
$result = ($num_rows/($total_rows));
$percent = round($result*100, 4, PHP_ROUND_HALF_UP);
{ 

} 
echo "$percent%";
?> 

Any further help her would be appreciated as I am stumped. Thanks in advance.

Edited by fisher7679
Link to comment
https://forums.phpfreaks.com/topic/282616-php-echo-result/#findComment-1452124
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.