hisham
IS-IT--Management
- Nov 6, 2000
- 194
I tried the following codes to test mysql in my linux server
1- to create a MySQL database :
<?php
$result = mysql_create_db ("test_database"
if ($result == false)
echo mysql_errno() . ": " . mysql_error() . "<BR>";
?>
after running this code, the database was created successfully
2- to connect to a database and execute an SQL query. this code is to create a table that holds email information for a person:
<?php
$connection = mysql_connect ("192.168.0.2:3306", "root", "mypassword"
if ($connection == false){
echo mysql_errno().": ".mysql_error()."<BR>";
exit;
}
$query = "create table email_info " .
"(fullname varchar(255), email_address varchar(255))";
$result = mysql_db_query ("test_database", $query);
if ($result)
echo "Table 'email_info' was successfully created!";
else
echo mysql_errno().": ".mysql_error()."<BR>";
mysql_close ();
?>
after running the code, the connection and the tables was created successfully too.
3- When the following code is executed by a browser, it will show a form requesting a name and an email address. Once the submit button is clicked, the two fields will be stored into the table 'email_info', in the test_database.:
<?php
if ($submit == "click"{
// The submit button was clicked!
// Get the input for fullname and email then store it in the database.
$connection = mysql_connect ("192.168.0.2:3306", "root", "mypasswrd"
if ($connection == false){
echo mysql_errno().": ".mysql_error()."<BR>";
exit;
}
$query = "insert into email_info values ('$fullname', '$email')";
$result = mysql_db_query ("test_database", $query);
if ($result){
echo "Success!";
}
else{
echo mysql_errno().": ".mysql_error()."<BR>";
}
mysql_close ();
}
else{
echo "
<html><body>
<form method=\"post\" action=\"insert.php\">
Enter your full name
<input type=\"text\" name=\"fullname\"></input><br>
Enter your email address
<input type=\"text\" name=\"email\"></input><br>
<input type=\"submit\" name=\"submit\" value=\"click\"></input>
</form>
</body></html>
";
}
?>
but the two fields data never stored into the table, just refresh the page when the submit button is clicked. User “root” has full privileges to insert, delete, etc… I tried many codes to insert data into tables but always face this same problem !!
Thanks in advance for your help.
1- to create a MySQL database :
<?php
$result = mysql_create_db ("test_database"
if ($result == false)
echo mysql_errno() . ": " . mysql_error() . "<BR>";
?>
after running this code, the database was created successfully
2- to connect to a database and execute an SQL query. this code is to create a table that holds email information for a person:
<?php
$connection = mysql_connect ("192.168.0.2:3306", "root", "mypassword"
if ($connection == false){
echo mysql_errno().": ".mysql_error()."<BR>";
exit;
}
$query = "create table email_info " .
"(fullname varchar(255), email_address varchar(255))";
$result = mysql_db_query ("test_database", $query);
if ($result)
echo "Table 'email_info' was successfully created!";
else
echo mysql_errno().": ".mysql_error()."<BR>";
mysql_close ();
?>
after running the code, the connection and the tables was created successfully too.
3- When the following code is executed by a browser, it will show a form requesting a name and an email address. Once the submit button is clicked, the two fields will be stored into the table 'email_info', in the test_database.:
<?php
if ($submit == "click"{
// The submit button was clicked!
// Get the input for fullname and email then store it in the database.
$connection = mysql_connect ("192.168.0.2:3306", "root", "mypasswrd"
if ($connection == false){
echo mysql_errno().": ".mysql_error()."<BR>";
exit;
}
$query = "insert into email_info values ('$fullname', '$email')";
$result = mysql_db_query ("test_database", $query);
if ($result){
echo "Success!";
}
else{
echo mysql_errno().": ".mysql_error()."<BR>";
}
mysql_close ();
}
else{
echo "
<html><body>
<form method=\"post\" action=\"insert.php\">
Enter your full name
<input type=\"text\" name=\"fullname\"></input><br>
Enter your email address
<input type=\"text\" name=\"email\"></input><br>
<input type=\"submit\" name=\"submit\" value=\"click\"></input>
</form>
</body></html>
";
}
?>
but the two fields data never stored into the table, just refresh the page when the submit button is clicked. User “root” has full privileges to insert, delete, etc… I tried many codes to insert data into tables but always face this same problem !!
Thanks in advance for your help.