aladiyat23 Posted August 9, 2006 Share Posted August 9, 2006 ok i feel like an idiot. i have a table created and a database waiting to be filled... this was created using phpmyadmin that my host provides. ok... now for why i feel like an idiot... i cant find any tutorials or what to search for or where to look even for help on getting my contact form to write to this database. or am i ass backwards on this? frustrated. :( Link to comment https://forums.phpfreaks.com/topic/17044-php-mysql-advice/ Share on other sites More sharing options...
SharkBait Posted August 9, 2006 Share Posted August 9, 2006 Simplified way of inserting into a databaseForm[code]<form action="form.php" method="POST">My Name <input type="text" name="myName" /><input type="submit" value="Submit" name="submit" /></form> [/code]Script (in the same form as the form is you wish)[code]<?phpif(isset($_POST['submit'])) { // User submitted the form if(!empty($_POST['myName'])) { // Field 'myName' was not left empty $name = trim($_POST['myName']); } // Hopefully database connection has already been made // Having a string for the query statement is easier for troubleshooting bad data when the query buggers up $strqry = "INSERT INTO myDatabase (id, name, date_entered) VALUES (NULL, '{$name}', NOW())"; // Execute the query with the string provided $query = mysql_query($strqry) or die("MySQL Error: <br />{$strqry} <br />".mysql_error()); if(mysql_affected_rows > 0) { // Item was added successfully echo "Entry was added into the database"; } else { // Item was not successful echo "There was an error when adding to the database."; }}?>[/code] Link to comment https://forums.phpfreaks.com/topic/17044-php-mysql-advice/#findComment-71953 Share on other sites More sharing options...
MikeWire Posted August 9, 2006 Share Posted August 9, 2006 What errors are you getting? Also, for tutorials check out [url=http://www.tizag.com]www.tizag.com[/url] - it helped me a ton when I first started using PHP...with SQL Link to comment https://forums.phpfreaks.com/topic/17044-php-mysql-advice/#findComment-72001 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.