I wound up fooling around with the code and I figured out the issue. Broj1, your code wound up working flawlessly. I just need to alter a few things on my end. Thanks again!

It does not seem to be appending to the query from the if statements.

For some reason it is not picking up the if conditions, it is just displaying everything from the database.

Thanks for the responses guys, I'll give them a try!

Hey guys,

So I've been devloping a TV Guide website that will allow you to fill out a variety of different fields, then searches the database for that information, and returns the results. The way I have it right now, the user has to fill out all of the fields in order for the search to work properly. I want to have it so even if the user only enters information for one field, it will ignore all of the empty fields, and still search the database.

Here is the code for the form:

<form method="POST" action="guideresult.php">
    <table cellspacing="7" cellpadding="0" bgcolor="#ecedef" align="center">
    <tr>
    <td>DATE</td>
    <td>TIME</td>
    <td>TYPE</td>
    <td>GENRE</td>
    <td>RATING</td>
    <td>PROGRAM NAME SEARCH</td>
    <td>Submit</td>
    </tr>
    <tr>
    <td>
        <input type="date" name="date">
    </td>
    <td>
        <input type="time" name="startime">
    </td>
    <td>
        <select name="type">
        <option value="NULL"></option>
        <option value="TV Show">TV Show</option>
        <option value="Movie">Movie</option>
        </select>
    </td>
    <td>
        <select name="genre">
        <option value="NULL"></option>
        <option value="Action">Action</option>
        <option value="Animated">Animated</option>
        <option value="Comedy">Comedy</option>
        <option value="Crime">Crime</option>
        <option value="Drama">Drama</option>
        <option value="Entertainment">Entertainment</option>
        <option value="Family">Family</option>
        <option value="Fantasy">Fantasy</option>
        <option value="Horror">Horror</option>
        <option value="Musical">Musical</option>
        <option value="Reality">Reality</option>
        <option value="Romance">Romance</option>
        <option value="ScFi">ScFi</option>
        <option value="Sports">Sports</option>
        <option value="Talk Show">Talk Show</option>
        </select>
    </td>
    <td>
        <select name="rating" class="rating">
        <option value="NULL"></option>
        <option class="tvshow" value="TV-Y">TV-Y</option>
        <option class="tvshow" value="TV-Y7">TV-Y7</option>
        <option class="tvshow" value="TV-G">TV-G</option>
        <option class="tvshow" value="TV-PG">TV-PG</option>
        <option class="tvshow" value="TV-14">TV-14</option>
        <option class="tvshow" value="TV-MA">TV-MA</option>
        <option class="movie" value="G">G</option>
        <option class="movie" value="PG">PG</option>
        <option class="movie" value="PG-13">PG-13</option>
        <option class="movie" value="R">R</option>
        <option class="movie" value="NC-17">NC-17</option>
        </select>
    </td>
    <td><input type="text" name="programname" size="40"></td>
    <td><input type="submit" value="   Submit   "></td>
    </tr>
    </table>
    </form>

And the results page:

<?php
        require_once 'connect.php';
        $db_server = mysql_connect($db_hostname, $db_username, $db_password);
        if (!$db_server) die("Unable to connect to MySQL: " . ...

Hello,

I am currently trying to develope a perl CGI script that will allow a user to enter a name on an HTML form, and it will search the database with that name. Once it finds the matched names, it will display their name and telephone number on the screen. I'm not completely sure how to go about this, so I was wondering if anyone could share any sort of insight.

Thank you very much in advance.

HTML FORM

<HTML>
<HEAD><TITLE>Search Telephone Number</TITLE></HEAD>
<BODY BGCOLOR=#FFFFCC>
<H3>Search A Telephone Number</H3>
<FORM ACTION="project2_searchnum.pl" METHOD=POST>
<TABLE>
<TR>
    <TD>Name:</TD>
    <TD><INPUT NAME=fullname SIZE="20"></TD>
</TR>
</TABLE>
<P><INPUT TYPE=submit VALUE="Submit"> <INPUT TYPE=reset> <INPUT TYPE="button" VALUE="Go Back" onClick="history.go(-1);return true;"></P>
</FORM>

</BODY>
</HTML>

PERL SCRIPT

#!/usr/bin/perl

#use warnings;
#use strict;

use DBI;
use DBD::mysql;
use CGI qw( :standard );

my $cgi = new CGI;

print "Content-type: text/html\n\n";

#connecting to the database 
my $dbh = DBI->connect( 
"DBI:mysql:****", "******", "******" ) or
   die( "Could not make connection to database: $DBI::errstr" );

#setting params from the html form
$q=new CGI;
$name=$q->param('fullname');
$number=$q->param('number');

#Webpage creation
print "<HTML>\n";
print "<HEAD><TITLE>Project 1 - Search a Telephone Number</TITLE><BASEFONT SIZE=5></HEAD>\n";
print "<H1>Search a Telephone Number</H1>\n";
print "<BODY BGCOLOR=#FFFFCC>\n";

#Display names and numbers from search here

print "<a href='project2_main.html'><INPUT TYPE='button' VALUE='Main Menu'</a>\n";

print "</BODY>\n";
print "</HTML>\n";

$sth->finish();
$dbh->disconnect();

I have corrected some of my minor errors, but now when I execute one of the options, I get the following error.

[code]
Address Book Menu

     S - Search For Address
     A - Add Address
     R - Remove Address
     E - Edit Address
     V - View Address

     Q - Quit  a

[color=red]./addressbook: line 27: fnPhoneAdd: command not found[/color]
[/code]

Anyone?

This is what I currently have so far.

The script needs to Add, Edit, Search, and View the address_file.

Any help would be greatly appreciated.

[code]
trap "rm ./f 2> /dev/null; exit" 0 1 3
addressfile=~/address_file
loop=x
while test $loop = "x"
do
clear
tput cup 3 12; echo "Address Book Menu"
tput cup 4 12; echo "================="
tput cup 6 9; echo "S - Search For Address"
tput cup 7 9; echo "A - Add Address"
tput cup 8 9; echo "R - Remove Address"
tput cup 9 9; echo "E - Edit Address"
tput cup 10 9; echo "V - View Address"
tput cup 12 9; echo "Q - Quit"
tput cup 12 19;
read choice || continue
case $choice in

[Ss] fnSearchPhone ;;

 [Aa]) fnPhoneAdd ;;
 [Rr]) fnPhoneDelete ;;
 # [Ee]) fnEditPhone ;;
 [Vv]) fnViewPhone ;;
 [Qq]) clear ; exit ;;
 *) tput cup 14 4; echo "Invalid Code"; read choice ;;

esac
done

fnPhoneAdd()
{
testloop=y
while [ $looptest = y ]
do
clear
tput cup 1 4; echo "Address Book Phone Addition"
tput cup 2 4; echo "==========================="
tput cup 4 4; echo "Full Name : "
tput cup 5 4; echo "Phone Number: "
tput cup 6 4; echo "Office : "
tput cup 8 4; echo "Add Another? (y)es or (q)uit: "
tput cup 4 18; read phonenum
if [ "$phonenum" = "q" ]
then
clear ; exit
fi
tput cup 4 18; read name
tput cup 5 18; phonenum
tput cup ...

Anyone? Thanks in advance

Hello,

I've created a simple menu that will execute some commands, and display them on the screen. However, when I try to execute them in the menu, nothing appears. I was not sure if I went about this the right way. Any help is appreciated.

[code]
trap "rm ./f 2> /dev/null; exit" 0 1 3
projectfile=!/project1
loop=y
while test $loop = "y"
do
clear
tput cup 1 12: echo "Welcome " logname;
tput cup 3 12; echo "Project 1 Sample Menu"
tput cup 4 12; echo "====================="
tput cup 6 9; echo "P - Display List Of Current Users"
tput cup 7 9; echo "C - Display The Current Month's Calender"
tput cup 8 9; echo "L - Display The Last 20 Users In The Password File"
tput cup 10 9; echo "Q - Exit: "
tput cup 12 19;
read choice || continue
case $choice in
[Pp]) echo users ;;
[Cc]) echo cal -y ;;
[Ll]) echo sed -n '1409,1428p' /etc/passwd ;;
[Qq]) clear ; exit ;;
*)tput cup 14 4; echo "Invalid Code"; read choice ;;
esac
done
[/code]

[QUOTE=vmanes;1509146]Line 35 - what's 'i' doing there?

I take it your loop at lines 34,35 should be displaying just the high temps and you will write a similar loop for the low temps? So, how are you pointing to the correct row of temp data?[/QUOTE]

Oh wow, I see what you mean, I must have passed right over that. I had it in another loop that was dealing with 'i' and forgot to change it. Everything is printing out just fine now.

Small bugs like that always kill me haha.

Thanks.

I'm trying to create a program where it reads in the high and low temperatures for each month of the year using a 2D array. However, I cannot seem to get it working correctly. It outputs a bunch of strange numbers.

[code]

include <iostream>

include <iomanip>

using namespace std;

const int MONTHS = 12;

void getData(double [][2], int);

int main()
{
double temperatures[MONTHS][2];
getData(temperatures, MONTHS);

return 0;

}

void getData(double t[][2], int m)
{
int i, j, k;
for(i=0; i < m; i++)
{
cout << "Enter higest temperature for the month " << i+1 << ": ";
cin >> t[i][0];

    cout << "Enter lowest temperature for the month " << i+1 << ": ";
    cin >> t[i][1];
}

cout << "Jan" << setw(5) << "Feb" << setw(5) << "Mar" << setw(5) << "Apr" << setw(5) << "May" << setw(5) << "Jun" << setw(5);
cout << "Jul" << setw(5) << "Aug" << setw(5) << "Sep" << setw(5) << "Oct" << setw(5) << "Nov" << setw(5) << "Dec" << setw(5) << endl;

for(j=0; j<m; j++)
    cout << t[i][0] << setw(5);

}

[/code]

Here is what the output is suppose to look like:

[code]
Month: Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec

     High:   43   45   51   57   64   70   75   75   69   59   49   45
      Low:   34   34   38   42   49   54   58   57   52   46   39   36

[/code]

And here's what my output currently looks like.

[code]
Jan Feb Mar Apr May Jun Jul Aug Sep ...

You almost have the code for that...
You have written:

int winnerIndex(int votes[])
{
   int i;
   int maximum;
   maximum = votes[0];
   for(i=0; i<5; i++)
     {
    if(votes[i] > maximum)
      maximum = votes[i];
     }
  return maximum;
}

Now if you add something like this:

int winnerIndex(int votes[])
   // This function now returns the index in votes that is the maximum:
{
   int index(0);
   int maximum(votes[0]);
   for(int i=1; i<5; i++)
     {
    if(votes[i] > maximum)
          {
        maximum = votes[i];
            index=i;
          }
     }
  return index;
}

Note I have changed a few thing:

(a) you don't need to loop through the i=0 index because you have effectively processed that in the initialization stage.
(b) I have elected to maintain two variables, maximum and index, you could do it with
just the index value but each comparison would need to be to votes[index].
(c) There is not code to deal with a tie.

You might like to change this function to include an extra input parameter to the size of the array, at the moment it is hard coded to 5, that is really ugly. And a silent bug waiting to happen when you add/remove a candidate.

Thanks man, I finally got it working how I needed it to work. Much appreciated with the tips at the bottom, they really helped.

[QUOTE=BTW8892;1494521]Thank you so much!

I can't believe I overlooked that, stupid mistake on my part haha.[/QUOTE]

I just had one more question, how would I got about getting the name of the winner with the most votes?

[QUOTE=dkalita;1494505]before solving your problem lets look at the following code snippet
[CODE]
int x=4;
int y=8;
float z=x/y;
cout<<z;
[/CODE]

Can you try this code and see what output you get.

You might be expecting the output to be: 0.5 right ?

But have a second look at the code. You are dividing an integer by another integer, so the result will also be an integer. Hence the output of the above code snippet will be:
0
instead of 0.5.

I hope you got the problem with your code.
If you want to get the exact value after division, you will have to typecast at-least the number you are dividing or the divisor to float type.

Hence the above code snippet should be corrected to
[CODE]
int x=4;
int y=8;
float z=((float)x)/y;/or float z=(float)x/y;/
cout<<z;
[/CODE][/QUOTE]

Thank you so much!

I can't believe I overlooked that, stupid mistake on my part haha.

[QUOTE=pseudorandom21;1494486]percent[i] = totalvote;

that isn't correct.

Try making it a percentage based on totalvote and the number of votes they actually got.[/QUOTE]

Sorry, that was an error, I tried testing to see what was wrong with it before. Here is the actual line that outputs 0.

[code]percent[i] = (votes[i] / totalvote) * 100;[/code]

I'm creating a voting program in which you input the persons name and how many votes they have received. It than prints out the persons name, their amount of votes and the percentage of their votes from the total.

I can't seem to get the percent of total to work correctly, everything else is working fine. I'm also aware that nothing lines up correctly, i'll be fixing that after I get it working.

Any ideas? thanks.

[code]#include <iostream>

include <iomanip>

include <String>

using namespace std;

int sumVotes(int list[]);
int winnerIndex(int list[]);
int votes[20];
double percent[10];

int main()
{
string name[10];

int i;
for(i=0; i<5; i++)
{
    cout << "Enter the name of the candidate and the number of votes: ";
    cin >> name[i];
    cin >> votes[i];
}

int totalvote;
totalvote = sumVotes(votes);

int w;
w = winnerIndex(votes);

cout << "Name" << setw(25) << "Votes Receieved" << setw(25) << "% of Total" << endl;
for(i=0; i<5; i++)
{
    percent[i] = totalvote;
    cout << name[i] << setw(21) << votes[i] << setw(20) << percent[i] << endl;
}

cout << endl << setw(30) << "Total: " << totalvote;

return 0;

}
int sumVotes(int votes[])
{
int i;
int total = 0;
for(i=0; i<5; i++)
total = total + votes[i];

return total;

}
int winnerIndex(int votes[])
{
int i;
int maximum;
maximum = votes[0];
for(i=0; i<5; i++)
{
if(votes[i] > maximum)
maximum = votes[i];
}

return maximum;

}
[/code]

[b]Output:[/b]

[code]Enter the name of the candidate and the number of votes: Person1 5000
Enter the ...

Hey,

I want to start this new project for my own site, but I'm not really sure on how to start. Was wondering if anyone could help start me off, with some ways to organize and start it out.

Basically I want to start a hockey league script, that contains 30 teams and it tracks stats for that team, and the players on those teams.

I've created a script that can handle a single team site, now I just want to expand it to a league script that can handle multiple teams at once. If anyone knows how I would go about starting this, or if there are any pre-made scripts out there.

If you have a script like this and are selling it, you can let me know, I'd be interested. Thanks again.

Sorry about that, I completely forgot to post these two links above. Here you go.

Basically i want it to check if a player_stats field is empty, and if it is empty, it won't post it in the database.

[b]Entry Form:[/b] [url]http://pastebin.com/wU8LTpuH[/url]
[b]Insert Code:[/b] [url]http://pastebin.com/Qpb105Yv[/url]

Alrite, So i have a an entry page with a form on it, that simply enters the data into the specified database. I have a player stats entry page, and there are five lines for players. However, if not all 5 players play, I want it to check if that field is empty, and if it is, i don't want it to enter it into the database. Because when i enter a game, and i leave a player field blank, all it does is enter in all 0's for that player.

Hey,

I have yet another question, so here it is. I have a roster page, and i have multiple players on the page. The players each have a unique playerid stored in the database. Now what i want to do is link up their name on the roster list that has their playerid in the url. It will than link to another page, and post all the players information based on that specific id.

I believe its call parameter passing in a URL, if im right. Any way, here is the code i currently have.

CODE: [url]http://bryan26.pastebin.com/4mK5HGk9[/url]

hey coppercup,

I did what you said, and i got the following error after.

[img]http://img811.imageshack.us/img811/3119/testf.png[/img]

Thanks a ton! Very helpful, easy to understand and was very informative!

[QUOTE=coppercup;1262134]First, each set of Player form fields will must have unique names. You can't have "playerid" for five different form fields on the same form. So you will need something like "playerid_1", "playerid_2", etc. Each of the fields for each player must be named in the same fashion, having a suffix of "_X" at the end. This is how your script will identify the fields for each individual player.

Then, the simplest thing to do is a single insert for each set of fields – five inserts. You're done.

We have also written scripts that can identify an infinite number of such fields by evaluating the field names (the key) to find out how many [players] have been submitted, then looping through each one and doing an insert. This takes more effort to work out, but has advantages. In your case, if you only plan to insert five players' info at a time, you can either do five independent inserts or a simple loop to insert five.[/QUOTE]

Now for the five inserts, would i need to insert the desired name like playerid_1 or would i just input playerid when writing the code to insert it.

So i have a system, and i was creating a page to input player stats. However there are 5 rows that have be inserted per game from a single form. I have the code for the form and the insert code. I was just wondering if someone could help me so it will insert all 5 rows in the form into a desired table when entered through the form. Thanks

Form: [url]http://pastebin.com/C3pv2uAj[/url]
Insert Code: [url]http://pastebin.com/NDZryVZc[/url]

Any other replies?

Hey, i was wondering if it was possible to find the sum of all the values in certain row and than find the max value of all of them. I have the following code, but it only grabs the largest value from all the rows, is it possible to sum all them, and than grab the max based on the persons playerid?

[code=php]$result = mysql_query("SELECT gamertag, goals FROM player_stats WHERE goals = (select Max(goals) from player_stats)GROUP BY playerid; ");[/code]

Is it also possible to grab a profile picture from another table based on the code above?

Alrite so i am trying insert new values into my table, and when i try to, i get the following error

[code]#1062 - Duplicate entry 'Hit Em High' for key 'team_home' [/code]

Any idea how to fix this? I've heard it could be a primary key error, but im not sure.

Thanks!

Hello,

I am trying to link up a certain row i am outputting on a site. How would i go about putting multiple lines inside of one echo statement.

[code=php]echo "<a href='profile.php?player_id=>'".$row['gamertag']."</a>";[/code]

That is the current code i am using, but it is now, working, any idea on how to make it work?