putting data in mysql from php form help

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

kat
New php-forum User
New php-forum User
Posts: 3
Joined: Mon Nov 25, 2002 8:14 pm

putting data in mysql from php form help

Postby kat » Mon Nov 25, 2002 8:21 pm

I am trying to update a mysql database from a php form. My confirmation page comes up after submitting the form and there are no errors or anything peculiar. But nothing gets put into the database.
Any help or suggestions would be appreciated.

Here is my code:

<html>
<body>
<?php


$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')";

?>



<form method="post" action="done.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>

Dmitrit Plakhotnik
New php-forum User
New php-forum User
Posts: 13
Joined: Fri Nov 01, 2002 6:56 am

Postby Dmitrit Plakhotnik » Mon Nov 25, 2002 11:19 pm

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

Filename: insert.php

Code: Select all

<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>


User avatar
Oleg Butuzov
Last Samuray
Last Samuray
Posts: 831
Joined: Sun Jun 02, 2002 3:09 am

Postby Oleg Butuzov » Tue Nov 26, 2002 5:58 am

Dmitriy this is one string from your code...

Code: Select all

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


do you think it is true ? =)



Code: Select all

<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>

Dmitrit Plakhotnik
New php-forum User
New php-forum User
Posts: 13
Joined: Fri Nov 01, 2002 6:56 am

Postby Dmitrit Plakhotnik » Thu Nov 28, 2002 6:22 am

Yes, I think it's true.
Because, if any fields not empty this record will be insering into DB.




Ya vas dobre rozumiju, panove :).


Return to “PHP coding => General”

Who is online

Users browsing this forum: Google [Bot] and 4 guests