Stevens3 Posted December 3, 2007 Share Posted December 3, 2007 I have an html document which has POST variables PANAS1 - PANAS20, which passes the data to the PANAS.php processor when submitted. However, when I click submit, the screen pauses a second (as if sending data), then brings up the same HTML page, and when I check the MySQL database no data is entered. Here is the code for PANAS.php: <?php $mysqli = mysqli_connect("localhost", "**", "**", "unified"); $sql = 'INSERT INTO unified.PANAS (PANAS1, PANAS2, PANAS3, PANAS4, PANAS5, PANAS6, PANAS7, PANAS8, PANAS9, PANAS10, PANAS11, PANAS12, PANAS13, PANAS14, PANAS15, PANAS16, PANAS17, PANAS18, PANAS19, PANAS20) VALUES ("'.{$_POST["PANAS1"].'","'. $_POST["PANAS2"].'","'. $_POST["PANAS3"].'","'. $_POST["PANAS4"].'","'. $_POST["PANAS5"].'","'. $_POST["PANAS6"].'","'. $_POST["PANAS7"].'","'. $_POST["PANAS8"].'","'. $_POST["PANAS9"].'","'. $_POST["PANAS10"].'","'. $_POST["PANAS11"].'","'. $_POST["PANAS12"].'","'. $_POST["PANAS13"].'","'. $_POST["PANAS14"].'","'. $_POST["PANAS15"].'","'. $_POST["PANAS16"].'","'. $_POST["PANAS17"].'","'. $_POST["PANAS18"].'","'. $_POST["PANAS19"].'","'. $_POST["PANAS20"].'"'; mysqli_query($mysqli, $sql); mysqli_close($mysqli); ?> It may not be very efficient code, but I think it should work? Any help would be greatly appreciated. Quote Link to comment Share on other sites More sharing options...
revraz Posted December 3, 2007 Share Posted December 3, 2007 You have this backwards mysqli_query($mysqli, $sql); should be mysqli_query($sql); Quote Link to comment Share on other sites More sharing options...
trq Posted December 3, 2007 Share Posted December 3, 2007 You have this backwards mysqli_query($mysqli, $sql); should be mysqli_query($sql); No, mysqli_query() requires the connection resource and the arguments are in the correct order. For debugging, try... mysqli_query($mysqli, $sql) || die(mysqli_error() . "<br />" . $sql); What do you get? Quote Link to comment Share on other sites More sharing options...
Stevens3 Posted December 3, 2007 Author Share Posted December 3, 2007 Thanks for the quick replies. Unfortunately, no error messages display when I run the script with that update, just the original page reappears, and no data is entered when I query the database. Quote Link to comment Share on other sites More sharing options...
trq Posted December 3, 2007 Share Posted December 3, 2007 Place this at the top of the script. <?php error_reporting(E_ALL) ; ini_set('display_errors','1'); ?> ps: Your code isn't terribly innificient, though it has no error handling. Your database design on the other hand leaves alot to be desired. You should look at some tutorials on dtabase normalization. Quote Link to comment Share on other sites More sharing options...
Stevens3 Posted December 3, 2007 Author Share Posted December 3, 2007 Ugh, still returns the same page (the submission form). Here's the only thing that might be relevant from apache error_log [Mon Dec 03 09:54:15 2007] [error] [client 127.0.0.1] File does not exist: /usr/local/apache2/htdocs/favicon.ico, referer: http://localhost/PANAS.html/ I have no idea why it cares about a favicon, but thought I would put this info here is case it was any help in ascertaining the problem. Here is the Apache server_log for one of the submissions. 127.0.0.1 - - [03/Dec/2007:10:54:17 -0500] "POST /PANAS.html/PANAS.php HTTP/1.1" 200 9733 Perhaps it's looking for the script in the wrong place? Sorry for any trouble, but I greatly appreciate the help. Quote Link to comment Share on other sites More sharing options...
revraz Posted December 3, 2007 Share Posted December 3, 2007 Are mysqli commands available to all version of MySQL? Does it have to be enabled? What version of MySQL are you running? Have you tried using mysql commands instead? Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted December 3, 2007 Share Posted December 3, 2007 Let us see the form (at least the <form tag with the action="..." statement.) It sounds like the form is not submitting to the correct URL. Quote Link to comment Share on other sites More sharing options...
Stevens3 Posted December 3, 2007 Author Share Posted December 3, 2007 Thanks for all help so far. MySQL version is 5.1.22. Here is the form tag and submit button - <form action="PANAS.php" method="post"> <br><center> <input value="Submit Data" name="submit" type="submit"> </center><br> </form> Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted December 3, 2007 Share Posted December 3, 2007 Are you doing any url rewriting in a .htaccess file? The URL in the lines for the log looks unusual (it would appear you have a folder called PANAS.html or you are typing the / on the end of the URL.) For a form to submit and cause the same page to be displayed when the action="..." parameter is to a different page would mean the form is incorrectly coded or the browser could not figure out the URL to submit to. Take a more basic approach, find out if your form is submitting to the form processing code. Echo out some of the $_POST variables. Once you know the form is working, then debug the mysqli code. Quote Link to comment Share on other sites More sharing options...
PHP_PhREEEk Posted December 3, 2007 Share Posted December 3, 2007 Ugh, still returns the same page (the submission form). Here's the only thing that might be relevant from apache error_log [Mon Dec 03 09:54:15 2007] [error] [client 127.0.0.1] File does not exist: /usr/local/apache2/htdocs/favicon.ico, referer: http://localhost/PANAS.html/ I have no idea why it cares about a favicon, but thought I would put this info here is case it was any help in ascertaining the problem. Here is the Apache server_log for one of the submissions. 127.0.0.1 - - [03/Dec/2007:10:54:17 -0500] "POST /PANAS.html/PANAS.php HTTP/1.1" 200 9733 Perhaps it's looking for the script in the wrong place? Sorry for any trouble, but I greatly appreciate the help. Favicon is a request from IE for a favorites icon. It always asks for it. If you don't have a favicon on the server, it'll generate a 404 error. Not a problem! Just ignore it... The other log entry you posted is generating a 200, which is a successful transfer, and it is reporting that it successfully transferred 9733 bytes. Ok, so now back to your original problem... PhREEEk Quote Link to comment Share on other sites More sharing options...
Stevens3 Posted December 3, 2007 Author Share Posted December 3, 2007 Ok, some good things are happening. On the hint that the form itself may not be working, I changed the form action to "/PANAS.php" and now I get output from echoing some post variables instead of the previous page simply reappearing after submitting the form. However, nothing has been entered into the database yet. Here is the error message I get: Warning: mysqli_error() expects exactly 1 parameter, 0 given in /usr/local/apache2/htdocs/PANAS.php on line 11 INSERT INTO unified.PANAS (PANAS1, PANAS2, PANAS3, PANAS4, PANAS5, PANAS6, PANAS7, PANAS8, PANAS9, PANAS10, PANAS11, PANAS12, PANAS13, PANAS14, PANAS15, PANAS16, PANAS17, PANAS18, PANAS19, PANAS20) VALUES ("3","4","3","4","4","4","4","3","4","4","3","4","4","4","4","3","3","4","4","4" (This is where the numbers are the submitted radio button values - note no right parentheses at the end, I don't know if this means anything) Here is the code (line 11 is the mysqli_query() line): <?php error_reporting(E_ALL) ; ini_set('display_errors','1'); echo $_POST["PANAS2"]; echo $_POST["PANAS1"]; $mysqli = mysqli_connect("localhost", "root", "", "unified"); $sql = 'INSERT INTO unified.PANAS (PANAS1, PANAS2, PANAS3, PANAS4, PANAS5, PANAS6, PANAS7, PANAS8, PANAS9, PANAS10, PANAS11, PANAS12, PANAS13, PANAS14, PANAS15, PANAS16, PANAS17, PANAS18, PANAS19, PANAS20) VALUES ("'. $_POST["PANAS1"].'","'. $_POST["PANAS2"].'","'. $_POST["PANAS3"].'","'. $_POST["PANAS4"].'","'. $_POST["PANAS5"].'","'. $_POST["PANAS6"].'","'. $_POST["PANAS7"].'","'. $_POST["PANAS8"].'","'. $_POST["PANAS9"].'","'. $_POST["PANAS10"].'","'. $_POST["PANAS11"].'","'. $_POST["PANAS12"].'","'. $_POST["PANAS13"].'","'. $_POST["PANAS14"].'","'. $_POST["PANAS15"].'","'. $_POST["PANAS16"].'","'. $_POST["PANAS17"].'","'. $_POST["PANAS18"].'","'. $_POST["PANAS19"].'","'. $_POST["PANAS20"].'"'; mysqli_query($mysqli, $sql) || die(mysqli_error() . "<br>" . $sql); mysqli_close($mysqli); ?> Thanks again for all help. Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted December 3, 2007 Share Posted December 3, 2007 Actually, the current error is because the mysqli_error() syntax is wrong, but because it is trying to execute the or die() statement means that the query failed. Make the following correction to the mysqli_error() - mysqli_query($mysqli, $sql) || die(mysqli_error($mysqli) . "<br>" . $sql); You are correct about a missing ) near the end of the query, that is probably what is causing the query to fail. Quote Link to comment Share on other sites More sharing options...
Stevens3 Posted December 3, 2007 Author Share Posted December 3, 2007 YES it works! That last suggestion got the error reporting working correctly, and I could deduce the small syntax errors from there. Thanks all for your help, this is a very important small project to me. 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.