Frank100 Posted June 25, 2007 Share Posted June 25, 2007 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); ?> Quote Link to comment Share on other sites More sharing options...
matto Posted June 25, 2007 Share Posted June 25, 2007 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 Quote Link to comment Share on other sites More sharing options...
teng84 Posted June 25, 2007 Share Posted June 25, 2007 '$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 Quote Link to comment Share on other sites More sharing options...
mmarif4u Posted June 25, 2007 Share Posted June 25, 2007 I did not see any db selected so try this 1st under ur connection code. mysql_select_db($database) or die ($database . " Database not found."); Quote Link to comment Share on other sites More sharing options...
suma237 Posted June 25, 2007 Share Posted June 25, 2007 Try this... mysql_select_db("dbname"); Quote Link to comment Share on other sites More sharing options...
matto Posted June 25, 2007 Share Posted June 25, 2007 the mysqli_connect() function takes the database name as a parameter....I would be interested in knowing what you get from mysqli_error() as I mentioned in my previous post. Quote Link to comment Share on other sites More sharing options...
Frank100 Posted June 25, 2007 Author Share Posted June 25, 2007 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"); Quote Link to comment Share on other sites More sharing options...
mmarif4u Posted June 25, 2007 Share Posted June 25, 2007 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."); Quote Link to comment Share on other sites More sharing options...
matto Posted June 28, 2007 Share Posted June 28, 2007 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(). Quote Link to comment Share on other sites More sharing options...
corbin Posted June 28, 2007 Share Posted June 28, 2007 mmarif4u, the mysql functions and the mysqli functions are not related at all if I remember correctly.... Quote Link to comment Share on other sites More sharing options...
redarrow Posted June 28, 2007 Share Posted June 28, 2007 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); ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.