reading/submission into mysql

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
eoinmick
Forum Newbie
Posts: 22
Joined: Fri Mar 26, 2004 12:30 pm

reading/submission into mysql

Post 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>
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post 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
Illusionist
Forum Regular
Posts: 903
Joined: Mon Jan 12, 2004 9:32 pm

Post 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
}
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post 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
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

BTW,

Code: Select all

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

Mac
eoinmick
Forum Newbie
Posts: 22
Joined: Fri Mar 26, 2004 12:30 pm

Post 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.
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

What is the error?

Mac
magicrobotmonkey
Forum Regular
Posts: 888
Joined: Sun Mar 21, 2004 1:09 pm
Location: Cambridge, MA

Post by magicrobotmonkey »

Its at the bottom of the post
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

<?php echo $_SERVER['PHP_SELF']?>
Illusionist
Forum Regular
Posts: 903
Joined: Mon Jan 12, 2004 9:32 pm

Post 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.
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post 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
magicrobotmonkey
Forum Regular
Posts: 888
Joined: Sun Mar 21, 2004 1:09 pm
Location: Cambridge, MA

Post by magicrobotmonkey »

heh I know, sorry, didnt mean to be a smartass
Post Reply