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 alf@alf.com

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

 

?>

 

Link to comment
Share on other sites

To get a better idea of the error - try this:

 

Change the insert to this:

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

 

see what it prints when you try the form

 

 

Link to comment
Share on other sites

'$name', '$email', '$phone', '$income', '$now', '$now'

 

'".$name."'  chage your variable like this ^^^

 

$now== maybe the db rad this as text so first try it this way now() and dont put quote just put it that way

Link to comment
Share on other sites

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

 

 

 

 

Link to comment
Share on other sites

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.");

Link to comment
Share on other sites

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 comment
Share on other sites

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);
?> 

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.