If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > PHP > Form won't post to Database

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #16 (permalink)  
Old 05-05-11, 02:22
healdem healdem is offline
Jaded Developer
 
Join Date: Nov 2004
Location: out on a limb
Posts: 9,262
well looking at your PHP in the zip file in post #13
what variable is $cnn meant to hold?
where is it set?
I'd remove the outer brackets when you assign a value to $sql
$sql = "INSERT INTO Casing_Job VALUES....
rather than
$sql = ("INSERT INTO Casing_Job VALUES....

as you use $cnn I'm surprised you aren't getting an error message from PHP telling you are using an unassigned variable, as you have error_reporting to include E_NOTICE, consider changing error_reporting to error_reporting(-1);

PHP: Manual Quick Reference
rather than use the old school mysql functions you may be better off using the mysqli object which is the recommended route these days

out of curiousity where do you specify the database, usually I'd expect 2 lines of PHP to connect to a db
first off the connection:-
mysql_connect
then select the database
mysql_select_db
then queries

note you can use the or dire construct to find out what is happening on the connect and select db statements

you may find this page usefull
__________________
I'd rather be riding my Versys or my Tiger 800 let alone the Norton
Reply With Quote
  #17 (permalink)  
Old 05-07-11, 02:44
Jeremy Chequer Jeremy Chequer is offline
Registered User
 
Join Date: May 2011
Posts: 9
Hello

I have rewritten the page using the information available from the w3school site. It is no longer bringing up any errors however still will not submit the data to the database. I have attached the new file to this post so that people can see to try and help.

As I no longer have an error log to work from I have absolutely no idea what is wrong.

I'd like to thank everyone for there help so far to
Attached Files
File Type: zip sql2.zip (4.3 KB, 2 views)
Reply With Quote
  #18 (permalink)  
Old 05-07-11, 03:50
healdem healdem is offline
Jaded Developer
 
Join Date: Nov 2004
Location: out on a limb
Posts: 9,262
use the or die construct in each and every MySQL interaction. one of the problems / features of PHP is that its relatively fault tolerant which can be a problem, especially for people using PHP for the first time.

PHP Code:
$con mysql_connect("localhost""tfg_ozcon""ozcon") or     die('Connection failed: ' mysql_errno().': '.mysql_error());
mysql_select_db("tfg_ozcon"$con) or die('Select DB failed: '.mysql_errno().': '.mysql_error());
$sql =  "insert your sql here"//
$sqlr=@mysql_query($sql,$con) or die('SQLfailed: '.mysql_errno().': '.mysql_error()); 
I'd always recommend that you assign the value of your sql to a variable, especially when debugging as its all to common to thinbk you know what your SQL is doing as opposed to what its actually doing

without any error message its hard to tell what is going wrong. I'm not going to plough through your script (I don't have the time or the energy or the will to do so)
what matters is where its going wrong
either
you have a problem in establishing the contact with the DB server (the connection or the select database)
OR
the query is failing because of syntax errors in the SQL or an untrapped error in selecting the database.

even if I was prepared to plough through your SQL these would be tricky to diagnose looking at your script.

I still think your db design is flaky, I wouldn't expect to see 10 repeating groups of columns. note you shouldn't need to store a start date and time as separate columns, they should be in the same column

assuming you can prove the connection and database are valid then its more likely to be an SQL syntax error
moist likely candidates for that are
date values / literals not presented in the correct style which is the ISO date standard YYYY-MM-DD
string / char / varchar values not encapsulated with " or '
eg
PHP Code:
INSERT INTO mytable (aNumericColumnaDateColumnaCharColumnvalues (21345"2011/03/28""blah di blah"); 
to prove if its a SQL syntax problem then assuming you have no required (not null columns) insert some values directly into the table
PHP Code:
$sql "INSERT INTO Casing_Job (Customer) VALUES (99901);
$sqlr=@mysql_query($sql,$con) or die('SQLfailed: ' mysql_errno().': '.mysql_error() 
this assumes that the column customer is a numeric column
if its a char / string / text column

PHP Code:
$sql "INSERT INTO Casing_Job (Customer) VALUES ("An OzCon customer");
$sqlr=@mysql_query($sql,$con) or die('SQLfailed: ' mysql_errno().': '.mysql_error() 
another thing to bear in mind is this forum cannot teach you PHP, at best it can help or provide pointers where to look
__________________
I'd rather be riding my Versys or my Tiger 800 let alone the Norton
Reply With Quote
  #19 (permalink)  
Old 05-07-11, 07:09
Jeremy Chequer Jeremy Chequer is offline
Registered User
 
Join Date: May 2011
Posts: 9
Hey

I understand that this forum can't teach me PHP and normally wouldn't be asking for help, however I have been going over this for a couple of weeks now and still can't get it to work.

I will try your suggestions and if I still can't get it to work, I'll rewrite it again and debug as I go.

I'd like to thank everyone for their help with this
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On