Hi,i'm new in php. :)
Now i have to use this as per project requirement.
So i just started to learn it as fast as possible.
As first attempt, i wanna add some data into mysql database table which has been created by MySQL Command Line Client.
I installed php5 , apache2.2 and PHP Coder Pro . As i'm window-base application programmer using .net, first i tested php code which print some string on localhost.That's fine. But now when i tried to insert data into mysql, i got some problem which keeps me hitting my head a few hours.
i can see some form, but after i fill in required data, webpage comes blank and mysql table is not actual filled by data. :-/
Is there some other configuration do i need to change in mysql or php or apache?
Here's my code.
I do hope somebody can help me out.
Thanks in advance.

///Insert_Test.php code///
<title>Add New Key Info</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">


include 'library/configDB.php';
//include 'library/openDB.php';

global $username;
global $password;

$username = $_POST["username"];
$password = $_POST["password"];

// test2 is my database table name
$query="INSERT INTO test2(username,password) VALUES ('$username', PASSWORD('$password'))";
mysql_query($query) or die('Error, insert query failed');

mysql_query($query) or die('Error, insert query failed');

include 'library/closeDB.php';
echo "New MySQL data added";


<form method="post">
<table width="400" border="0" cellspacing="1" cellpadding="2">
<td width="100">Username</td>
<td><input name="username" type="text" id="username"></td>
<td width="100">Password</td>
<td><input name="password" type="text" id="password"></td>
<td width="100"> </td>
<td> </td>
<td width="100"> </td>
<td><input name="add" type="submit" id="add" value="Add New Data"></td>

//echo '<pre>';
//echo print_r($_POST['add']);
//echo '</pre>';
//echo "

<style type="text/css"> .style1 { width: 615px; } .style2 { text-align: right; width: 85px; } </style>
///configDB.php code///
$dbname='test'; // this is database name
$connec=mysql_connect($dbhost,$dbuser,$dbpassword) or die ('Error Connecting to MySQL:');

i typed in my browser(IE) " http://localhost/Insert_Test.php "

i also set following configuration in my php.ini file
error_reporting = E_ALL
display_errors = On
But i still got above problem. Help me please :'(

6 Years
Discussion Span
Last Post by Dragonbaki

Try this....

$query="INSERT INTO test2(´username´, ´password´) VALUES ('$username', '$password')";

Hmmm... Your code is fine.. But see at line 37.. You did not specify where the submitted values to go.. So only you have such problem. Try this..

<form method="post" action="">  // for passing the values to this same page.

Surely it will work. If still any probs, pls let me know..

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.