Jump to content

php mysql advice


aladiyat23

Recommended Posts

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

Simplified way of inserting into a database

Form
[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]
<?php
if(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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.