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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.