timmah1 Posted April 30, 2017 Share Posted April 30, 2017 I followed a tutorial on doing a contact form, works great. But, I want the information to be submitted in to my database to access later. The posted values are put into an array $fieldss = array('name' => 'First Name', 'surname' => 'Last Name', 'phone' => 'Phone', 'email' => 'Email', 'venue' => 'Venue', 'vname' => 'Contact', 'vaddress1' => 'Address', 'vaddress2' => 'Addresss', 'vcity' => 'City', 'vstate' => 'State', 'vzip' => 'Zip', 'vphone' => 'Phone', 'eventdate' => 'Event Date', 'eventtime' => 'Event Time', 'eventname' => 'Event Name', 'message' => 'Message'); Then the values are sent to my email. How can I take these values, and put them into my database? I've tried numerous different things, searched, and followed tutorials, but nothing is working. Here is the code I tried, but nothing gets inserted except my date fieild, but this is the first time something was inserted into the database if(is_array($fieldss)){ foreach ($_POST as $keys => $row) { $book_first = mysql_real_escape_string($fieldss[$row][0]); $book_last = mysql_real_escape_string($fieldss[$row][1]); $book_email = mysql_real_escape_string($fieldss[$row][2]); $query ="INSERT INTO booking (book_first, book_last, book_email) VALUES ( '". $book_first."','".$book_last."','".$book_email."' )"; mysqli_query($conn, $query); } if ($conn->query($query) === TRUE) { $okMessage = 'Form successfully submitted.<br>'; } else { $errorMessage = 'There was an error while submitting. '; } } Can somebody help me out here? Thank you in advance Quote Link to comment Share on other sites More sharing options...
benanamen Posted April 30, 2017 Share Posted April 30, 2017 (edited) You are off to a really bad start. The code you found out on the Internet is obsolete, insecure and has been completely removed from PHP. You need to use PDO with prepared statements. You are also mixing MySQL with mysqli. You never ever put variables in a query. Edited April 30, 2017 by benanamen Quote Link to comment Share on other sites More sharing options...
timmah1 Posted April 30, 2017 Author Share Posted April 30, 2017 Alright, I noticed mixing the 2, that was a screw up. I fixed that, but still get nothing. So your only solution is using PDO? I don't want to use PDO, But thank you for your suggestion. Now, would anybody else be able to help me out? Quote Link to comment Share on other sites More sharing options...
Jacques1 Posted April 30, 2017 Share Posted April 30, 2017 Well, what do you want? Right now, all I see is a random collection of half-understood features from three(!) different APIs: the old MySQL extension, the procedural mysqli API and then the object-oriented mysqli API. If you want to use mysqli, you have to actually learn it from the ground up using the PHP manual. It's complicated, counter-intuitive and not very well understood in the PHP community, so following tutorials isn't going to help. You're also likely to spend more time (re)learning mysqli than simply switchting to PDO. In any case, there is no magical fix for your code, if that's what you expected. You need to make a decision, learn the basics and then come back with halfway sane code and more information (like the HTML form). 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.