flowingwindrider Posted July 15, 2007 Share Posted July 15, 2007 I'm attempting to write data from a form into a MySQL database. The script runs without errors and I am connecting to the db, but the data does not appear in the db. Can anyone tell me if I have written the script incorrectly? In the script below I have replaced my username and password with "user" and "password". <?php $wage = doubleval($_POST['Wage']); $type = addslashes($_POST['TypeJob']); $description = addslashes($_POST['Description']); $comp_name = addslashes($_POST['Company Name']); $contact = addslashes($_POST['Contact']); $addresss = addslashes($_POST['Address']); $telephone = addslashes($_POST['Telephone']); $email = addslashes($_POST['Email']); $counter_file = "counter.cnt"; $pre_conf = "E-"; $date = date("m/d/y"); if (! ereg('[A-Za-z0-9_-]+\@[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+', $email)) { header("Location: ../error.htm"); exit; } $count_file = fopen("$counter_file", "r"); while (!feof($count_file)) { $number = fread($count_file, 1024); } $conf_no = "$pre_conf$number"; fclose($count_file); $fileopen = fopen("$counter_file", "w"); flock($fileopen, LOCK_EX); $new_number = ($number + 1); fwrite($fileopen, "$new_number"); fclose($fileopen); $dbh = mysql_connect("localhost", "user", "password"); if (!$dbh) { echo "Error: Could not connect to database. Please try again later."; exit; } mysql_select_db ("bransone_classifieds"); $query = "insert into bransone_classifieds values ('".$conf_no."','".$date."','".$wage."','".$type."','".$description."','".$comp_name."','".$contact."','".$address."','". $telephone."','".$email."')"; mysql_query($query); header("Location: ../submission thanks.htm"); ?> As always, thanks for the help. Quote Link to comment Share on other sites More sharing options...
trq Posted July 15, 2007 Share Posted July 15, 2007 Pretty hard to tell whats going on with your distinct lack of endentaion. At the very least use... mysql_query($query) or die(mysql_error()); And let us know what that outputs. Quote Link to comment Share on other sites More sharing options...
flowingwindrider Posted July 15, 2007 Author Share Posted July 15, 2007 Sorry about the lack of indentation,I'm quite new to PHP and am not sure where your are supposed to indent. I have managed to figure out what was wrong, I listed the name of the db where it should have been the name of the table I was writing to. Thanks for the code suggestion, it did the trick. Quote Link to comment Share on other sites More sharing options...
trq Posted July 15, 2007 Share Posted July 15, 2007 Cool. Indentation should occur within logical blocks of code. Something like... <?php if ($expression) { echo "this is within the if logical block"; } else { echo "this is within the else logical block"; } if ($expression) { if ($expression2) { echo "this is even further in"; } } ?> Its kinda difficult to explain, but I hope you can see how it makes it much easier to see which } belong to which if. Quote Link to comment Share on other sites More sharing options...
flowingwindrider Posted July 15, 2007 Author Share Posted July 15, 2007 I see, that does improve readability. Thanks again. 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.