PHP not inserting to MySQL

Problems with the Windows version of XAMPP, questions, comments, and anything related.

PHP not inserting to MySQL

Postby adelmeyer » 03. December 2003 01:15

I have been trying to get php to insert information into the mysql database, but it will not insert data. It will go to the next page though.

Is there something that I haven't set up. The fields in the form are the same as the fields in the table.


Thanks for any help!

Andy
adelmeyer
 
Posts: 1
Joined: 02. December 2003 23:28

Postby lubber » 08. December 2003 06:52

Complex question with few details? It sounds like you are using a multi-page form, in which case you should register your variables

session_register("variable1");
session_register("variable2");

In a nutshell and oversimplified,

You have to create your variables for PHP
$variable1 = "";
$variable2 = "";

Create a form to collect your data, using POST, not GET.

Establish a connection to MySQL
$link=mysql_connect(localhost,username,password) or die ("link failed!);

Establish a connection to your database
$select_db=mysql_select_db(databasename, $link);

Query using INSERT or UPDATE (as the situation requires) to MYSQL
$Query="Insert into tablename values ('variable1',variable2'...); or
$Query="Update tablename set field1='variable1', field2='variable2'...";

Perform the query
$result=mysql_query($Query, $link) or die ("Query failed!);

Check your query
if ($result && mysql_num_rows($result) > 0 {
return FALSE;
} else {
return TRUE;

THEN display the next page.

Try adjusting your error_reporting in PHP (or the form) so that you can see what errors are occuring. I assure you, if PHP can't talk to MySQL, it will appear in the log file.

You should also modify the following page with a "debug table", displaying the variables you collected in the previous page. If the variables aren't there, then there is nothing for MySQL to do. You can comment out the debug table once you have finished developing the form. Once you get your form working the way you like (and I am sure you will), turn off the error reporting so that the page will run faster. There ain't nothing like a lot of undeclared variable assumptions filling a production error log to slow things down and to gobble up your disk space.

Hopefully, I won't get larted for this, but you can locate some good tutorials on PHP and MySQL with multi-page forms at http://www.hotscripts.com.
lubber
 
Posts: 2
Joined: 08. December 2003 06:16


Return to XAMPP for Windows

Who is online

Users browsing this forum: No registered users and 117 guests