Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Getting a value for radio buttons with SQL
Old 12-08-2010, 01:16 PM Getting a value for radio buttons with SQL
Junior Talker

Posts: 1
Name: Kathleen
Trades: 0
I have FlightSurvey.html, EnterFlightSurvey.php, and ShowSurveyResults.php

When entering data, i cannot figure out how to get the radio buttons to be entered into the database... they don't show up on the 'surveys' table.
Secondly, it tells me error #1064 when i press the submit button
third, when I try to see 'past survey results" i get a bunch of undefined indexes for ShowSurveryResults.php for the radio button names- and they don't show up in the table. Any help would be appreciated... I've tried this a few different ways and nothing seems to be working.


HTML Code:
<h2> Tell us how we did! Enter your flight information and rate our services</h2>
<form method="POST" action="EnterFlightSurvey.php">
<p>Flight Date <input type="text" name="flight_date" /></p>
<p>Flight Time <input type="text" name="flight_time" /></p>
<p>Flight Number <input type="text" name="flight_number" /></p>

<p><b>Friendliness of Staff:</b>
<input type="hidden" name="friendly" value="">
<input type="radio" name="friendly" value="No Opinion" SELECTED  />No Opinion
<input type="radio" name="friendly" value="Poor"  />Poor
<input type="radio" name="friendly" value="Fair"  />Fair
<input type="radio" name="friendly" value="Good"  />Good
<input type="radio" name="friendly" value="Excellent"  />Excellent <br /> </p>

<p><b>Space for luggage storage:</b>
<input type="hidden" name="space" value="">
<input type="radio" name="space" value="No Opinion" checked /> No Opinion
<input type="radio" name="space" value="Poor" /> Poor
<input type="radio" name="space" value="Fair" /> Fair
<input type="radio" name="space" value="Good" /> Good
<input type="radio" name="space" value="Excellent" /> Excellent <br /> </p>

<p><b>Comfort of seating:</b>
<input type="hidden" name="comfort" value="">
<input type="radio" name="comfort" value="No Opinion" checked /> No Opinion
<input type="radio" name="comfort" value="Poor" /> Poor
<input type="radio" name="comfort" value="Fair" /> Fair
<input type="radio" name="comfort" value="Good" /> Good
<input type="radio" name="comfort" value="Excellent" /> Excellent <br /> </p>

<p><b>Cleanliness of aircraft:</b>
<input type="hidden" name="clean" value="">
<input type="radio" name="clean" value="No Opinion" checked /> No Opinion
<input type="radio" name="clean" value="Poor" /> Poor
<input type="radio" name="clean" value="Fair" /> Fair
<input type="radio" name="clean" value="Good" /> Good
<input type="radio" name="clean" value="Excellent" /> Excellent <br /> </p>

<p><b>Noise level of aircraft:</b>
<input type="hidden" name="noise" value="">
<input type="radio" name="noise" value="No Opinion" checked /> No Opinion
<input type="radio" name="noise" value="Poor" /> Poor
<input type="radio" name="noise" value="Fair" /> Fair
<input type="radio" name="noise" value="Good" /> Good
<input type="radio" name="noise" value="Excellent" /> Excellent <br /> </p>

<p><input name="" type="submit" value="Submit" /><input name="" type="reset" value="Clear" /></p>

</form>

<p><a href="ShowSurveyResults.php">Show Past Surveys</a></p>
PHP Code:
<?php
if(empty($_POST['flight_time']) || empty($_POST['flight_date'])  || empty($_POST['flight_number']) || empty($_POST['friendly'])
|| empty(
$_POST['space']) || empty($_POST['comfort']) || empty($_POST['space']) || empty($_POST['noise'])) {
    echo 
"<p>You must enter the flight time, date, and number! Clck your browser's Back button to return to the Guest Book form.</p>";
} else {
    
$DBConnect = @mysql_connect("127.0.0.1""root""root");
    if(
$DBConnect === FALSE) {
        echo 
"<p>Unable to connect to the database server.</p>"
            
"<p>Error code ".mysql_errno()
            . 
": ".mysql_error()."</p>";
    } else {
        
$DBName "flightsurvey";
        if(!@
mysql_select_db($DBName$DBConnect)){
            
$SQLstring "create database  $DBName";
            
$QueryResult = @mysql_querry($SQLstring$DBConnect);
            if(
$QueryResult === FALSE){
                echo 
"<p>Unable to execute the query.</p>"
                
"<p>Error code ".mysql_errno($DBConnect)
                . 
": ".mysql_error($DBConnect)
                .
"</p>";
            } else {
                echo 
"<p>You are the first to complete the survey!</p>";
            }
        }
        
mysql_select_db($DBName$DBConnect);
        
        
$TableName "surveys";
        
$SQLstring "show tables like '$TableName'";
        
$QueryResult = @mysql_query($SQLstring$DBConnect);
        if(
mysql_num_rows($QueryResult) == 0){
            
$SQLstring "create table $TableName
                (countID smallint not null auto_increment primary key,
                flight_date varchar(8), flight_number varchar(20), flight_time varchar(40), friendly , space , comfort , clean , noise )"
;
            
$QueryResult = @mysql_query($SQLstring$DBConnect);
            }
            if(
$QueryResult === FALSE){
                echo 
"<p>Unable to create the table.</p>"
                
"<p>Error code ".mysql_errno($DBConnect)
                . 
": ".mysql_error($DBConnect)
                .
"</p>";     
            }
        }
        
        
$FlightDate stripslashes($_POST['flight_date']);
        
$FlightNumber stripslashes($_POST['flight_number']);
        
$FlightTime stripslashes($_POST['flight_time']);
        
$Friendly stripslashes($_POST'friendly']);
        if (
$Friendly == "No opinion") {
         echo 
'No opinion';
         }
        
$Space stripslashes($_POST['space']);
        
$Comfort stripslashes($_POST['comfort']);
        
$Clean stripslashes($_POST['clean']);
        
$Noise stripslashes($_POST['noise']);
        
        
$SQLstring "insert into $TableName values(NULL, '$FlightDate', '$FlightNumber', '$FlightTime', '$Friendly', '$Space', '$Comfort'. '$Clean', '$Noise')";
        
$QueryResult = @mysql_query($SQLstring$DBConnect);
        if(
$QueryResult === FALSE){
            echo 
"<p>Unable to execute the query.</p>"
                
"<p>Error code ".mysql_errno($DBConnect)
                . 
": ".mysql_error($DBConnect)
                .
"</p>";
        } else {
            echo 
"<h1>Thank you for taking our survey!</h1>";
        }
    }
    
mysql_close($DBConnect);

?>
PHP Code:
<?php
$DBConnect 
= @mysql_connect("127.0.0.1""root""root");
if(
$DBConnect === FALSE) {
    echo 
"<p>Unable to connect to the database server.</p>"
        
"<p>Error code ".mysql_errmo()
        . 
": ".mysql_error()."</p>";
} else {
    
$DBName "flightsurvey";
    if(!@
mysql_select_db($DBName$DBConnect)){
        echo 
"<p>There are no entries in the guest book!</p>";
    } else {
        
$TableName "surveys";
        
$SQLstring "select * from $TableName";
        
$QueryResult = @mysql_query($SQLstring$DBConnect);
        if(
mysql_num_rows($QueryResult) == 0){
            echo 
"<p>There are no surveys completed</p>";    
        } else {
            echo 
"<p>The following surveys are completed:</p>";    
            echo 
"<table with='100%' border='1'>";
            echo 
"<tr><th>FlightNumber</th><th>Flight Time</th><th>Flight Date</th><th>Friendliness of staff</th><th>Space for luggage storage</th><th>Comfort of seating</th><th>Cleanliness of aircraft</th><th>Noise level of aircraft</th></tr>";
            
            while((
$Row mysql_fetch_assoc($QueryResult)) !== FALSE){
                echo 
"<tr><td>{$Row['flight_date']}</td>";
                echo 
"<td>{$Row['flight_number']}</td>";
                echo 
"<td>{$Row['flight_time']}</td>";
                echo 
"<td>{$Row['friendly']}</td>";
                echo 
"<td>{$Row['space']}</td>";
                echo 
"<td>{$Row['comfort']}</td>";
                echo 
"<td>{$Row['clean']}</td>";
                echo 
"<td>{$Row['noise']}</td></tr>";                
            }
            
            echo 
"</table>";
        }
        
mysql_free_result($QueryResult);
    }
}
mysql_close($DBConnect);
?>
getbrutal is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 12-08-2010, 02:59 PM Re: Getting a value for radio buttons with SQL
Super Spam Talker

Posts: 879
Name: Paul W
Trades: 0
1) Don't create tables in public-facing code: bad habit. 2) Use datetime, time or date where appropriate -- sensible and allows appropriate ordering and range-based queries.3) use varchars for char fields4) you have a !== FALSE (double =)Sort those then try again.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE


*** New:
Please login or register to view this content. Registration is FREE
PaulW is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Getting a value for radio buttons with SQL
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.10626 seconds with 12 queries