putting data in mysql from php form help

A

Anonymous

Guest
Hi! Yes, of course you script is not woking. I think this code help you undestend you error :

Filename: insert.php
Code:
<html>
<body>
<?php
if ((!$First_Name)||(!$Last_Name)||(!$How_many)||(!$Children)) {

$db = mysql_connect("localhost", "root", "my_password");

mysql_select_db("mydb",$db);

$sql = "INSERT INTO employees (First_Name, Last_Name, How_Many, Children) VALUES
('$First_Name','$Last_Name','$How_many','$Children')";

mysql_db_query("myd",$sql);
header("locate: done.php");
}

?>



<form method="post" action="insert.php">

First name:<input type="Text" name="First_Name"><br>

Last name:<input type="Text" name="Last_Name"><br>

How Many:<input type="Text" name="How_Many"><br>

Children:<input type="Text" name="Children"><br>

<input type="Submit" name="submit" value="Enter information">

</form>
</body>
</html>
 
Dmitriy this is one string from your code...

Code:
if ((!$First_Name)||(!$Last_Name)||(!$How_many)||(!$Children)) {

do you think it is true ? =)



Code:
<html> 
<body> 
<?php 
if (isset($First_Name) && isset($Children) && isset($Last_Name) && isset($How_many)) { 

$db = mysql_connect("localhost", "root", "my_password"); 

mysql_select_db("mydb",$db); 

$sql = "INSERT INTO employees (First_Name, Last_Name, How_Many, Children) VALUES 
('$First_Name','$Last_Name','$How_many','$Children')"; 

mysql_db_query("myd",$sql); 
header("locate: done.php"); 
} 

?> 



<form method="post" action="insert.php"> 

First name:<input type="Text" name="First_Name"><br> 

Last name:<input type="Text" name="Last_Name"><br> 

How Many:<input type="Text" name="How_Many"><br> 

Children:<input type="Text" name="Children"><br> 

<input type="Submit" name="submit" value="Enter information"> 

</form> 
</body> 
</html>
 
Yes, I think it's true.
Because, if any fields not empty this record will be insering into DB.




Ya vas dobre rozumiju, panove :).
 
Back
Top