Jump to content

Need Help With My Html Form Code


drscmd1

Recommended Posts

Hello...I'm new to this site and to html/php coding...As you can tell I'm trying to connect to and query my DB and return the results...Here is my search_percentage.php...Can someone please look this over and point me in the right direction...

 

//Here is my HTML part

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<title>Search Contacts</title>

<style type="text/css" media="screen">

ul li{

  list-style-type:none;

}

</style>

</head>

 

<p><body>

 

//I'm not sure my action part is correct

<center>

<form method="post" action="search_percentage.php?go" id="searchform">

<table width="80%" border="1" cellpadding="10" cellspacing="0">

 

<tr><td>Work tickets evaluation percentages

<select name="summary"> 

    <option>summary</option>

    <option>High</option>

    <option>Medium</option>

    <option>Low</option>

</select>

 

<select name="status"> 

    <option>status</option>

    <option>Completed</option>

    <option>Not Completed</option>

</select> 

 

<div align="right"><input type="submit" value="Search"></div>

</td></tr>

 

</table>

</form>

</center>

</body>

</p>

</html>

 

//Here is my php part. 

<?php

 

    if(isset($_POST['submit']) && !empty($_POST['query'])){   

 

    $db=mysql_connect (" ", " ") or die ('I cannot connect to the database because: ' . mysql_error()); 

 

//-select the database to use

    $mydb=mysql_select_db(" ");

 

    if ((summary==High) && (status==Completed)){

    $result_two = mysql_query("(SELECT I.priority AS priority, COUNT(*) AS items, ROUND(COUNT(*) / T.total * 100) AS   percent FROM project as I, 

(SELECT COUNT(*) AS total FROM project WHERE status='completed') AS T WHERE status = 'completed' AND priority = 'High')" . $priority);}

    elseif ((summary==High) && (status==Not_Completed)){

    $result_two = mysql_query("(SELECT I.priority AS priority, COUNT(*) AS items, ROUND(COUNT(*) / T.total * 100) AS percent FROM project as I, 

(SELECT COUNT(*) AS total FROM project WHERE status='not completed') AS T WHERE status = 'not completed' AND priority = 'Low')" . $priority);}

    elseif ((summary==Medium) && (status==Completed)){

    $result_two = mysql_query("(SELECT I.priority AS priority, COUNT(*) AS items, ROUND(COUNT(*) / T.total * 100) AS percent FROM project as I, 

(SELECT COUNT(*) AS total FROM project WHERE status='completed') AS T WHERE status = 'completed' AND priority = 'Medium')" . $priority);}

    elseif ((summary==Medium) && (status==Not_Completed)){

    $result_two = mysql_query("(SELECT I.priority AS priority, COUNT(*) AS items, ROUND(COUNT(*) / T.total * 100) AS percent FROM project as I, 

(SELECT COUNT(*) AS total FROM project WHERE status='not completed') AS T WHERE status = 'not completed' AND priority = 'Medium')" . $priority);}

    elseif ((summary==Low) && (status==Completed)){

    $result_two = mysql_query("(SELECT I.priority AS priority, COUNT(*) AS items, ROUND(COUNT(*) / T.total * 100) AS percent FROM project as I, 

(SELECT COUNT(*) AS total FROM project WHERE status='completed') AS T WHERE status = 'completed' AND priority = 'Low')" . $priority);}

    elseif ((summary==Low) && (status==Not_Completed)){

    $result_two = mysql_query("(SELECT I.priority AS priority, COUNT(*) AS items, ROUND(COUNT(*) / T.total * 100) AS percent FROM project as I, 

(SELECT COUNT(*) AS total FROM project WHERE status='not completed') AS T WHERE status = 'not completed' AND priority = 'Low')" . $priority);}

 

 

 

    while($row = mysql_fetch_array($result_two)) {

        echo $Not_Completed=$row['Not_Completed'];

        echo $Completed=$row['Completed'];

        echo $High=$row['High'];

        echo $Medium=$row['Medium'];

        echo $Low=$row['Low'];

 

}

}

 

 

 

?>
Link to comment
Share on other sites

I think the problem is bad html.

 

<p> tag does not precede the <body> tag (that I know of.

 

The first td tag contains two select tags and a div and an input tag - an awful lot of stuff in one table element for some reason.  I think having the div in the middle of the form creates problems sometimes.  I know it's confounded me in the past.

Link to comment
Share on other sites

@ Jessica...A)To query my database...B)

( ! ) Notice: Undefined variable: sql in C:\wamp\www\search1.php on line 32 Call Stack # Time Memory Function Location 1 0.0010 147528 {main}( ) ..\search1.php:0
( ! ) Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\wamp\www\search1.php on line 34 Call Stack # Time Memory Function Location 1 0.0010 147528 {main}( ) ..\search1.php:0 2 0.0129 154376 mysql_fetch_array ( ) ..\search1.php:34

 

C)I changed my code again will post...

Link to comment
Share on other sites

<?php

 

if(isset($_POST['summary']) && !empty($_POST['status'])){

 

$db=mysql_connect (" ", " ") or die ('I cannot connect to the database because: ' . mysql_error()); 

 

//-select the database to use

$mydb=mysql_select_db(" ");

 

    if (('summary'=='High') && ('status'=='Completed')){

$sql="(SELECT I.priority AS priority, COUNT(*) AS items, ROUND(COUNT(*) / T.total * 100) AS percent FROM project as I, 

(SELECT COUNT(*) AS total FROM project WHERE status='completed') AS T WHERE status = 'completed' AND priority = 'High')";}

    elseif (('summary'=='High') && ('status'=='Not_Completed')){

$sql="(SELECT I.priority AS priority, COUNT(*) AS items, ROUND(COUNT(*) / T.total * 100) AS percent FROM project as I, 

(SELECT COUNT(*) AS total FROM project WHERE status='not completed') AS T WHERE status = 'not completed' AND priority = 'Low')";}

    elseif (('summary'=='Medium') && ('status'=='Completed')){

$sql="(SELECT I.priority AS priority, COUNT(*) AS items, ROUND(COUNT(*) / T.total * 100) AS percent FROM project as I, 

(SELECT COUNT(*) AS total FROM project WHERE status='completed') AS T WHERE status = 'completed' AND priority = 'Medium')";}

    elseif (('summary'=='Medium') && ('status'=='Not_Completed')){

$sql="(SELECT I.priority AS priority, COUNT(*) AS items, ROUND(COUNT(*) / T.total * 100) AS percent FROM project as I, 

(SELECT COUNT(*) AS total FROM project WHERE status='not completed') AS T WHERE status = 'not completed' AND priority = 'Medium')";}

    elseif (('summary'=='Low') && ('status'=='Completed')){

$sql="(SELECT I.priority AS priority, COUNT(*) AS items, ROUND(COUNT(*) / T.total * 100) AS percent FROM project as I, 

(SELECT COUNT(*) AS total FROM project WHERE status='completed') AS T WHERE status = 'completed' AND priority = 'Low')";}

    elseif (('summary'=='Low') && ('status'=='Not_Completed')){

$sql="(SELECT I.priority AS priority, COUNT(*) AS items, ROUND(COUNT(*) / T.total * 100) AS percent FROM project as I, 

(SELECT COUNT(*) AS total FROM project WHERE status='not completed') AS T WHERE status = 'not completed' AND priority = 'Low')";}

 

    $result=mysql_query($sql);

 

    while($row=mysql_fetch_array($result)) {

        echo $Not_Completed=$row['Not_Completed'];

        echo $Completed=$row['Completed'];

        echo $High=$row['High'];

        echo $Medium=$row['Medium'];

        echo $Low=$row['Low'];

 

}

}

 

?>
Link to comment
Share on other sites

your first code has this - if ((summary==High). how are you expecting the defined constant summary to be equal to the defined constant High?

 

then you changed it to - if (('summary'=='High'). how are you expecting the string 'summary' to be equal to the string 'High'?

 

summery is from your form field, which you correctly used $_POST['summery'] in one place. you would need to use $_POST['summery'] every time you want to reference the submitted form field, same for $_POST['status'].

Link to comment
Share on other sites

@mac_gyver I did as you said and now I get these notices:

 

 

( ! ) Notice: Undefined index: Not_Completed in C:\wamp\www\search1.php on line 36 Call Stack # Time Memory Function Location 1 0.0043 148904 {main}( ) ..\search1.php:0
( ! ) Notice: Undefined index: Completed in C:\wamp\www\search1.php on line 37 Call Stack # Time Memory Function Location 1 0.0043 148904 {main}( ) ..\search1.php:0
( ! ) Notice: Undefined index: High in C:\wamp\www\search1.php on line 38 Call Stack # Time Memory Function Location 1 0.0043 148904 {main}( ) ..\search1.php:0
( ! ) Notice: Undefined index: Medium in C:\wamp\www\search1.php on line 39 Call Stack # Time Memory Function Location 1 0.0043 148904 {main}( ) ..\search1.php:0
( ! ) Notice: Undefined index: Low in C:\wamp\www\search1.php on line 40 Call Stack # Time Memory Function Location 1 0.0043 148904 {main}( ) ..\search1.php:0
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.