Jump to content

Can't get this input query to work ... since a day


Frank100

Recommended Posts

The output always is :

 

name is alf

email is [email protected]

phone is 310.222-3333

income is 200

Couldn't execute insert query

 

 

 

 

 

 

 

"The form file"

 

<html>

<body>

 

Fill out test data "test/table_01"<p>

 

<form name="form1" method="POST"

action="test_input_initial_process_01_02.php">

 

name: <input type="text" name="name"><p>

email: <input type="text" name="email"><p>

phone: <input type="text" name="phone"><p>

income: <input type="text" name="income"><p>

 

 

<input type="submit" name="Submit"

value="Submit">

</form>

 

</body>

</html>

 

 

 

"The processor file"

 

<?php

 

$user="root";

$host="localhost";

$password="";

$database = "test";

 

$cxn = mysqli_connect($host,$user,$password,$database)

        or die ("Couldn't connect to server");

 

$name = $_POST["name"];

$email = $_POST["email"];

$phone = $_POST["phone"];

$income = $_POST["income"];

$now = date("Y-m-d");

 

print "name is $name<br>\n";

print "email is $email<br>\n";

print "phone is $phone<br>\n";

print "income is $income<br>\n";

 

$query = "insert into test.table_01

          (name, email, phone, income, signup_date, last_access) values

          ('$name', '$email', '$phone', '$income', '$now', '$now')";

 

$result = mysqli_query($cxn,$query)

           or die ("Couldn't execute insert query");

 

if ($result) {

print <<<EOT

 

Inserting successfull !

 

EOT;

}

else {

print "Inserting went wrong !";

}

 

mysqli_close($cxn);

 

?>

 

Thx for the replys,

haven't thought that a input can be so very complicated for a newbie. Thx Matto, I've tried out :

 

$result = mysqli_query($cxn,$query) or die("<tt>Couldn't execute insert query. Reason: " . mysqli_error() . "</tt>");

 

 

 

and the result is :

 

Warning: mysqli_error() expects exactly 1 parameter, 0 given in /var/www/vhosts/lodgecity.com/work/test_input_initial_process_01_02.php on line 27

Couldn't execute insert query. Reason:

 

 

 

 

the database is defined with :

 

 

$user="root";

$host="localhost";

$password="";

$database = "test";

 

$cxn = mysqli_connect($host,$user,$password,$database)

        or die ("Couldn't connect to server");

 

 

 

 

You define it but not select it.

So try this code:

 

$user="root";
$host="localhost";
$password="";
$database = "test";

$cxn = mysqli_connect($host,$user,$password)
        or die ("Couldn't connect to server");
mysql_select_db($database) or die ($database . " Database not found.");

Sorry about that, the mysqli_error() function needs one parameter, so try this:

 

$result = mysqli_query($cxn,$query) or die("<tt>Couldn't execute insert query. Reason: " . mysqli_error($cxn) . "</tt>");

 

This should give you the exact problem.

 

;)

 

 

There shouldn't be any need to use mysqli_select_db or mysql_select_db as others have mentioned. This is what it states in the PHP manual:

 

mysqli_select_db:

 

Note: This function should only be used to change the default database for the connection. You can select the default database with 4th parameter in mysqli_connect().

link to everythink you ever need to no for mysqli ok.

 

http://www.phpbuilder.com/manual/en/function.mysqli-connect.php

 

<?php
$mysqli = new mysqli("localhost", "my_user", "my_password", "world");

/* check connection */ 
if (mysqli_connect_errno()) {
   printf("Connect failed: %s\n", mysqli_connect_error());
   exit();
}

printf("Host information: %s\n", $mysqli->host_info);

/* close connection */
$mysqli->close();
?> 

 

 


<?php
$link = mysqli_connect("localhost", "my_user", "my_password", "world");

/* check connection */ 
if (!$link) {
   printf("Connect failed: %s\n", mysqli_connect_error());
   exit();
}

printf("Host information: %s\n", mysqli_get_host_info($link));

/* close connection */
mysqli_close($link);
?> 

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.