Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 07-31-2002, 03:53 PM   PM User | #1
itotakao
New to the CF scene

 
Join Date: Jul 2002
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
itotakao is an unknown quantity at this point
PHP script

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

<html>
<body>
<?php
$con = mysql_connect("localhost","itohideo","1234");
if(!$con) {
print("Fail DB Connection<br>\n");
exit;
}
if(!mysql_select_db("itohideo")) {
print("Fail DB Selection<br>\n");
exit;
}
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));
if(mysql_insert_id()){
$rets = "Thank you for filling out my form";
}
mysql_close($con);
}
?>

<?
if($rets){
echo $rets;
?>
<?}else{?>
<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">
</form>
<?}?>
</body>
</html>
itotakao is offline   Reply With Quote
Old 08-01-2002, 04:06 PM   PM User | #2
dillieo
New Coder

 
Join Date: Aug 2002
Location: Henderson, NV
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
dillieo is an unknown quantity at this point
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
__________________
Peace out homeskillets!!!
dillieo is offline   Reply With Quote
Old 08-01-2002, 05:00 PM   PM User | #3
mordred
Senior Coder


 
Join Date: Jun 2002
Location: frankfurt, german banana republic
Posts: 1,848
Thanks: 0
Thanked 0 Times in 0 Posts
mordred is an unknown quantity at this point
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?
mordred is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 08:27 PM.


Advertisement
Log in to turn off these ads.