View Full Version : PHP script

07-31-2002, 04:53 PM
Hi how are you? I try to run this script but it isn't working. After entering dates, it should only come up "Thank you for fill out" Not (texts ex name country and so on)

And I would like to make a link to Home.

My php editor says "Undefined variable: rets in c:\itohideo\kkk.php on line 27"

Here is my code

$con = mysql_connect("localhost","itohideo","1234");
if(!$con) {
print("Fail DB Connection<br>\n");
if(!mysql_select_db("itohideo")) {
print("Fail DB Selection<br>\n");
if (isset($_POST["submit"])){
$number = $_POST["number"];
$name = $_POST["name"];
$country = $_POST["country"];
$query_insert = "insert into takao (number, name, country) values ('$number', '$name', '$country')";
$query_result_insert = mysql_query($query_insert, $con) or die (mysql_error($con));
$rets = "Thank you for filling out my form";

echo $rets;
<form method="post" action="<?php $_SERVER['PHP_SELF']; ?>">
<P>please fill out this form and it goes to my database</P>
Number<input name="number" type="text"><br>
Name<input name="name" type="text"><br>
You country<input name="country" type="text"><br>
<input type="submit" name="submit">
<input type="reset" name="reset">

08-01-2002, 05:06 PM
Unfortunately I can't provide you a direct answer, but there might be a couple issues to take a peek at.

First: In prociessing your result inquiry, it isn't necessary for you to reconnect to the database, you only need one connection per page, unless you're doing some crazy stuff. Try omitting the $con part of the statement.

Second: Sometimes the results of a query are deceptive. Testing for a simple mysql_insert_id might be providing deceptive results. For a few tries, try printing out the mysql_error() to see what results you're actually getting. I had a recent project where I was formatting my e-mai addresses wrong and still getting a successful result.

Hope this helps

08-01-2002, 06:00 PM
I can't find any obvious errors in your code. The error message points to the mysql_insert_id() functions, because it returns false, the variable $rets does not get set and PHP complains about that at a later stage.

Was your insert actually successful? Also, does your mysql table "takao" have an AUTO_INCREMENT column specified correctly?