ChronicleX.com 06-10-2005, 09:03 AM this is also coming up with an error
Notice: Undefined variable: first in \\insert.php on line 9
Notice: Undefined variable: last in \\insert.php on line 9
Notice: Undefined variable: phone in \\insert.php on line 9
Notice: Undefined variable: mobile in \\insert.php on line 9
Notice: Undefined variable: fax in \\insert.php on line 9
Notice: Undefined variable: email in \\.php on line 9
Notice: Undefined variable: web in \\insert.php on line 9
line 9
$query = "INSERT INTO contacts VALUES ('','$first','$last','$phone','$mobile','$fax','$email','$web')";
<?
include("dbinfo.php");
$first=$_POST['first'];
$last=$_POST['last'];
$phone=$_POST['phone'];
$mobile=$_POST['mobile'];
$fax=$_POST['fax'];
$email=$_POST['email'];
$web=$_POST['web'];
mysql_connect("xxx.xxx.xxx.xxx",$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query = "INSERT INTO contacts VALUES ('','$first','$last','$phone','$mobile','$fax','$email','$web')";
mysql_query($query);
mysql_close();
?>
this is how am submiting the data
<form action="insert.php" method="post">
First Name: <input type="text" name="first"><br>
Last Name: <input type="text" name="last"><br>
Phone: <input type="text" name="phone"><br>
Mobile: <input type="text" name="mobile"><br>
Fax: <input type="text" name="fax"><br>
E-mail: <input type="text" name="email"><br>
Web: <input type="text" name="web"><br>
<input type="Submit">
</form>
gsoft 06-10-2005, 09:40 AM For the first one what is the actual error?
Where is $first coming from? Is it POST or GET are using using SuperGlobals $_POST or $_GET?
If not Id suggest doing so and validating the data before going into the database, you dont want any nasties happening.
ChronicleX.com 06-10-2005, 09:46 AM it seems that my 1st error has fixed it self? :thumbsup: but the 2nd error i posted at the top i still have no idea why it dont work??? :confused:
[HELP]
gsoft 06-10-2005, 09:55 AM Instead of
$query = "INSERT INTO contacts VALUES ('','$first','$last','$phone','$mobile','$fax','$email','$web')";
Which will only work with register_globals On Like i said use $_POST
$query = "INSERT INTO contacts VALUES ('','".$_POST['first']."','".$_POST['last']."','".$_POST['phone']."','".$_POST['mobile']."','".$_POST['fax']."','".$_POST['email']."','".$_POST['web']."')";
Just remember if its post data use $_POST if its in the Query string or a form using get use $_GET
ChronicleX.com 06-10-2005, 10:19 AM where do i start!!!!
Notice: Undefined index: first in \\insert.php on line 4
Notice: Undefined index: last in \\insert.php on line 5
Notice: Undefined index: phone in \\insert.php on line 6
Notice: Undefined index: mobile in \\insert.php on line 7
Notice: Undefined index: fax in \\insert.php on line 8
Notice: Undefined index: email in \\insert.php on line 9
Notice: Undefined index: web in \\insert.php on line 10
Notice: Undefined index: first in \\insert.php on line 15
Notice: Undefined index: last in \\insert.php.php on line 15
Notice: Undefined index: phone in \\insert.php on line 15
Notice: Undefined index: mobile in \\insert.php on line 15
Notice: Undefined index: fax in \\insert.php on line 15
Notice: Undefined index: email in \\insert.php on line 15
Notice: Undefined index: web in \\insert.php on line 15
line4,5,6,7,8,9,10
$first=$_POST['first'];
$last=$_POST['last'];
$phone=$_POST['phone'];
$mobile=$_POST['mobile'];
$fax=$_POST['fax'];
$email=$_POST['email'];
$web=$_POST['web'];
line 15
$query = "INSERT INTO contacts VALUES ('','".$_POST['first']."','".$_POST['last']."','".$_POST['phone']."','".$_POST['mobile']."','".$_POST['fax']."','".$_POST['email']."','".$_POST['web']."')";
delinear 06-10-2005, 10:28 AM You usually get this when the variables you're trying to access don't exist or haven't been declared. Generally you can get around the problem using isset($variable) to test each of the variables before you try and use them. For instance, with the variables you're calling from $_POST, try this to make sure that any that are empty are still declared and don't cause an error. You can either do this for each of your $_POST variables:
if(isset($_POST['first'])) {
$first = $_POST['first'];
} else {
$first = '';
}
Or a neater way to write the same thing that won't take up so much space is:
$first = (isset($_POST['first']) ? $_POST['first'] : '');
gsoft 06-10-2005, 10:31 AM Try using print_r($_POST) also if your going to define $first = $_POST['first'] you dont need the $_POST['first'] in the Query.
Also before you do the insert into the query maybe even try this
// maybe changing <input type="Submit"> to <input type="Submit" name="submit"> as this is how its going to work
if (isset($_POST['submit']))
{
include("dbinfo.php");
$first=$_POST['first'];
$last=$_POST['last'];
$phone=$_POST['phone'];
$mobile=$_POST['mobile'];
$fax=$_POST['fax'];
$email=$_POST['email'];
$web=$_POST['web'];
mysql_connect("xxx.xxx.xxx.xxx",$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query = "INSERT INTO contacts VALUES ('','$first','$last','$phone','$mobile','$fax','$email','$web')";
mysql_query($query);
mysql_close();
}
else
{
echo "Error Didnt press Submit";
}
ChronicleX.com 06-10-2005, 12:06 PM how come when i press submit it opens like am trying to download it? php is working i did phpinfo;
[code]
<form action="insert.php" method="post">
First Name: <input type="text" name="first"><br>
Last Name: <input type="text" name="last"><br>
Phone: <input type="text" name="phone"><br>
Mobile: <input type="text" name="mobile"><br>
Fax: <input type="text" name="fax"><br>
E-mail: <input type="text" name="email"><br>
Web: <input type="text" name="web"><br>
<input type="Submit" name="submit">
[code]
delinear 06-10-2005, 12:12 PM I just tried it here and it seems fine. I can only think that there's either a problem with php or apache/IIS whatever you have unless there is something in insert.php or one of the included files that's sending a header prompting the download dialogue.
mhunt 06-10-2005, 04:12 PM try this:
$query = "INSERT INTO contacts VALUES ('','{$first}','{$last}','{$phone}','{$mobile}','${fax}','{$email}','{$web}')";
mysql_query($query);
ChronicleX.com 06-10-2005, 04:38 PM I just tried it here and it seems fine. I can only think that there's either a problem with php or apache/IIS whatever you have unless there is something in insert.php or one of the included files that's sending a header prompting the download dialogue.
after looking at my code for 4 hours and kicking the pc a few times i found what it was i must of saved the file wrong and not as a php file even though it say insert.php
so when i pressed submit it tried to download
grrrrrrr or maybe not
when i take this away
<html xmlns="http://www.w3.org/1999/xhtml">
it trys to download but when i add it back in it shows php as html even with <?php tags
any ideas guys?????
delinear 06-10-2005, 04:43 PM Ah, the joys of programming :thumbsup: The problem is never what you expect it to be.
|
|