PDA

View Full Version : If textbox containes default value dont display


big-dog1965
02-11-2007, 12:38 AM
Hi Newbie here Ive tried several things in the way of php and javascript and none seem to work,
I have a form that the user fills out and submits the information gets stored in mysql. then a php file pulls information from mysql and displays it on a page.
On the form theres a drop down box that is optional "Second Cass" the default value is Select One if the user doesnt select one then select one is stored in mysql which I dont care about that, but when the php file pulls the information and displays it if the information from that drop down is select one I dont want to display it if its any thing else it can display it. ANY IDEAS
Remember Im a newbie heres php code page.
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query = 'DELETE FROM Registration WHERE DATE_SUB(CURDATE(),INTERVAL 1 DAY) >= `Race_Date`';
mysql_query($query);
$query = 'DELETE FROM Registration WHERE Race_Date = \'0000-00-00\'';
mysql_query($query);
$query="SELECT First_Name, First_Class, Second_Class, Race_Date FROM Registration ORDER BY Race_Date DESC";
$result=mysql_query($query);

$num=mysql_numrows($result);

if ($num==0) {
echo "<b>NO Drivers Registered Yet</b><br>";
}else{

}
mysql_close();
echo "<b>Registered Drivers</b><br>";

$i=0;
while ($i < $num) {

$First_Name=mysql_result($result,$i,"First_Name");
$First_Class=mysql_result($result,$i,"First_Class");
$Second_Class=mysql_result($result,$i,"Second_Class");
$Race_Date=mysql_result($result,$i,"Race_Date");
echo "<b>$First_Name<br>$Race_Date</b><br>$First_Class<br>$Second_Class<hr>";

$i++;
}

?>

Haroon
02-11-2007, 09:13 AM
Just Explain ur Question a bit more or attach rar file of ur code it all getting messy with ur words

big-dog1965
02-11-2007, 11:21 AM
The code is there in my 1st post. Basicly I want the $Second_Class not to echo if the value or results of it is Select One.
The choises for that drop down are Select One (which is the default) Truggy, Monster Truck, Stadium Truck, Elec Buggy, and Elec Truck

So if the user DOES NOT Select One the code echos Select One In that case I dont want the code to echo anything. If the user DOES selects one of the other choises then it echos which ever choise they made.

neomaximus2k
02-11-2007, 11:28 AM
then simple...


if ($First_Class !== "Select one"){
echo "$First_Name<br>$Race_Date</b><br>$First_Class<br>$Second_Class<hr>";
} else {
echo "$First_Name<br>$Race_Date</b><br>$Second_Class<hr>";
}

big-dog1965
02-15-2007, 06:17 PM
Where do I put the code at in the above php. Ive tried several different places and still displays Select One.

then simple...


if ($First_Class !== "Select one"){
echo "$First_Name<br>$Race_Date</b><br>$First_Class<br>$Second_Class<hr>";
} else {
echo "$First_Name<br>$Race_Date</b><br>$Second_Class<hr>";
}

neomaximus2k
02-15-2007, 07:26 PM
Well because I am in a decent mood this is the full code with a lot of code changes, see how I have done things and compare it to your code.



<?php
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");

@mysql_query("DELETE FROM Registration WHERE DATE_SUB(CURDATE(),INTERVAL 1 DAY) >= `Race_Date`")
or die ("Error - ".mysql_error()."<br />DELETE FROM Registration WHERE DATE_SUB(CURDATE(),INTERVAL 1 DAY) >= `Race_Date`");

mysql_query("DELETE FROM Registration WHERE Race_Date = '0000-00-00'");
or die ("Error - ".mysql_error()."<br />DELETE FROM Registration WHERE Race_Date = '0000-00-00'");

$sql = mysql_query("SELECT First_Name, First_Class, Second_Class, Race_Date FROM Registration ORDER BY Race_Date DESC");

if (@mysql_num_rows($sql) < 1){
echo "<b>NO Drivers Registered Yet</b><br>";
} else {
$result = mysql_fetch_array($sql);
$First_Name = $result['First_Name'];
$First_Class = $result['First_Class'];
$Second_Class = $result['Second_Class'];
$Race_Date = $result['Race_Date'];

echo "<b>Registered Drivers</b><br>";

if ($First_Class !== "Select one"){
echo "$First_Name<br>$Race_Date</b><br>$First_Class<br>$Second_Class<hr>";
} else {
echo "$First_Name<br>$Race_Date</b><br>$Second_Class<hr>";
}
}
@mysql_free_result($sql);
mysql_close();

?>

Nightfire
02-15-2007, 07:28 PM
Well I'm glad I didn't post a decent reply in the other identical thread http://www.codingforums.com/showthread.php?t=107567 Would've been a waste of time :/

big-dog1965
02-15-2007, 09:58 PM
neomaximus2k I have a problem can you help the code you wrote errors error, unexpected T_LOGICAL_OR in /home//public_html//use/Registration/registered.php on line 22

I marked it out to continue on and changed the if else first class stuff to second class stuff because the second class is what im trying to get the differant result from. Any way what is happening now is its only displaying one record and I checked the database and there are several.
Thanks for you time