Page 1 of 1

reading/submission into mysql

Posted: Wed Mar 31, 2004 6:56 am
by eoinmick
Am still trying to read from the fields into mysql database but proving unsuccessful from the code below...have named all field names exactly the same??..If anyone can help thanks...and if anyone can give me inspiration on how to make sure all fields contain data before submission and if not report which field was missed??
Thanks__________

Code: Select all

<html>
<head><title>Flight Details</title></head>
<body text="blue" bgcolor="FFFFCC">
<HR SIZE=4 style="background-color: blue">
<body>
<?
$db   = "u2ell";
$host = "mysql";
$user = "u2ell";
$pass = "";
mysql_connect($host,$user,$pass) or die(mysql_error());
mysql_select_db($db) or die (mysql_error());
//the connection to the database was successful

$flightid = $HTTP_POST_VARS['flightid'];
$flyday = $HTTP_POST_VARS['flyday'];
$time = $HTTP_POST_VARS['time'];
$destinationfrom = $HTTP_POST_VARS['destinationfrom'];
$destinationtill = $HTTP_POST_VARS['destinationtill'];

if(empty($flightid)or(empty($flyday)or($time)or(empty($destinationfrom)or(empty($destinationtill))

$query = "INSERT INTO flights 
(flightid,flyday,time,destinationfrom,destinationtill)
VALUES
('$flightid','$flyday','$time','$destinationfrom','$destinationtill')"; 

$result =mysql_query($query) or die(mysql_error()); 

}
?>

<h1 align="center" h1><b><FONT COLOR="blue">FIND THE RIGHT TIME TO FLY!!<br>Flight Details</b></font></h1> 
<center><img src="http://images.google.com/images?q=tbn:PFur1okFNCUJ:danenet.danenet.org/ywen/calender"</center> 
<HR SIZE=4 style="background-color: blue">
<h2><center>Flights</h2>

<form method="post"action="<?php echo $PHP_SELF?>"> 
<table cellpadding=2 cellspacing=0 border=1>

<td>Flight Id    :</td><td>     <input type="text" size="10" maxlength="4"  name="flightId"  value=""></td><tr>

<td>Fly Day:</td><td><input type="text" size="20" maxlength="10" name="flyday" value=""></td></tr>

<td>Time:</td><td> <input type="decimal" size="10"    name="time"value=" "></td></tr>

<td>Destination From</td><td>	<input type="text" size="20" maxlength="15" name="destinationfrom" value=""></td></tr>

<td>Destination Till</td><td> <input type="text" size="20" maxlength="15" name="destinationtill" value=""> </td><tr>

</table>
<input type="Submit" name="flights" value="Enter Flight Details">
<HR SIZE=4 style="background-color: blue">
</form>
</body>
</html>

Posted: Wed Mar 31, 2004 7:02 am
by JayBird
Just a quick note. You have posted a few messages now with code in. Can you please put [syntax=php][/syntax] tags around the code so the forum highlights it. It is muche easier to read.

Mark

Posted: Wed Mar 31, 2004 7:06 am
by Illusionist
what in the world:

Code: Select all

if(empty($flightid)or(empty($flyday)or($time)or(empty($destinationfrom)or(empty($destinationtill))

$query = "INSERT INTO flights
(flightid,flyday,time,destinationfrom,destinationtill)
VALUES
('$flightid','$flyday','$time','$destinationfrom','$destinationtill')";

$result =mysql_query($query) or die(mysql_error());

}
What is up with that if statement? its wong. you missing an empty, a lot of ) and a { and its just wrong, you should have it there. It should never be there. If they are all empty then you have it insert empty fields into the database. That doesn't make much since. try this instead:

Code: Select all

if (isset($_POST['flights'])){
$flightid = $_POST['flightid'];
$flyday = $_POST['flyday'];
$time = $_POST['time'];
$destinationfrom = $_POST['destinationfrom'];
$destinationtill = $_POST['destinationtill']; 
$query = "INSERT INTO flights (flightid,flyday,time,destinationfrom,destinationtill) VALUES ('$flightid','$flyday','$time','$destinationfrom','$destinationtill')";
echo $query; //testing to see if everyhting is right.
$result =mysql_query($query) or die(mysql_error()); 
}else{
//display your form
}

Posted: Wed Mar 31, 2004 7:15 am
by twigletmac
Make sure that you have this in the top of your PHP file:

Code: Select all

ini_set('display_errors', 1);
error_reporting(E_ALL);
to make sure that you're seeing all the errors that are arising.

Mac

Posted: Wed Mar 31, 2004 7:19 am
by twigletmac
BTW,

Code: Select all

$host = 'mysql';
normally that's localhost, seems strange as just mysql.

Mac

Posted: Wed Mar 31, 2004 7:32 am
by eoinmick
Put in the code as displayed but gat error???
_____________

<html>
<head><title>Flight Details</title></head>
<body text="blue" bgcolor="FFFFCC">
<HR SIZE=4 style="background-color: blue">
<body>

Code: Select all

<?
ini_set('display_errors', 1); 
error_reporting(E_ALL);
$db   = "u2ell";
$host = "mysql";
$user = "u2ell";
$pass = "";
mysql_connect($host,$user,$pass) or die(mysql_error());
mysql_select_db($db) or die (mysql_error());
//the connection to the database was successful

if (isset($_POST['flights'])){ 
$flightid = $_POST['flightid']; 
$flyday = $_POST['flyday']; 
$time = $_POST['time']; 
$destinationfrom = $_POST['destinationfrom']; 
$destinationtill = $_POST['destinationtill']; 
$query = "INSERT INTO flights (flightid,flyday,time,destinationfrom,destinationtill) VALUES ('$flightid','$flyday','$time','$destinationfrom','$destinationtill')"; 
echo $query; //testing to see if everyhting is right. 
$result =mysql_query($query) or die(mysql_error()); 
}else{ 
//display your form 
} 
?>
<h1 align="center" h1><b><FONT COLOR="blue">FIND THE RIGHT TIME TO FLY!!<br>Flight Details</b></font></h1>
<center><img src="http://images.google.com/images?q=tbn:P ... r"</center>
<HR SIZE=4 style="background-color: blue">
<h2><center>Flights</h2>

<form method="post"action="<?php echo $PHP_SELF?>">
<table cellpadding=2 cellspacing=0 border=1>

<td>Flight Id :</td><td> <input type="text" size="10" maxlength="4" name="flightId" value=""></td><tr>

<td>Fly Day:</td><td><input type="text" size="20" maxlength="10" name="flyday" value=""></td></tr>

<td>Time:</td><td> <input type="decimal" size="10" name="time"value=" "></td></tr>

<td>Destination From</td><td> <input type="text" size="20" maxlength="15" name="destinationfrom" value=""></td></tr>

<td>Destination Till</td><td> <input type="text" size="20" maxlength="15" name="destinationtill" value=""> </td><tr>

</table>
<input type="Submit" name="flights" value="Enter Flight Details">
<HR SIZE=4 style="background-color: blue">
</form>
</body>
</html>
____________________________
ERROR
The requested URL /~u2ell/<br /><b>Notice</b>: Undefined variable: PHP_SELF in <b>/home/u2ell/public_html/flightsinput.php</b> on line <b>37</b><br /> was not found on this server.

Posted: Wed Mar 31, 2004 7:55 am
by twigletmac
What is the error?

Mac

Posted: Wed Mar 31, 2004 8:07 am
by magicrobotmonkey
Its at the bottom of the post

Posted: Wed Mar 31, 2004 10:54 am
by markl999
<?php echo $_SERVER['PHP_SELF']?>

Posted: Wed Mar 31, 2004 11:06 am
by Illusionist
Also in my code, where i commented out, display form here, that is where you should've put all that HTML that displays the form. And as mark said, $host = "mysql"; sounds pretty strange, i've never seen mysql alone as a host before. Try looking more into that.

Posted: Wed Mar 31, 2004 11:52 am
by twigletmac
magicrobotmonkey wrote:Its at the bottom of the post
This is why the are so much better than unformatted text - I didn't read the error because I thought it was a signature :evil:

Mac

Posted: Wed Mar 31, 2004 12:22 pm
by magicrobotmonkey
heh I know, sorry, didnt mean to be a smartass