Jump to content


php mysql advice

  • Please log in to reply
2 replies to this topic

#1 aladiyat23

  • Members
  • PipPipPip
  • Advanced Member
  • 39 posts
  • Locationflorida

Posted 09 August 2006 - 06:14 PM

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. :(

#2 SharkBait

  • Members
  • PipPipPip
  • Advanced Member
  • 845 posts
  • LocationMetro Vancouver, BC

Posted 09 August 2006 - 06:41 PM

Simplified way of inserting into a database

<form action="form.php" method="POST">
My Name <input type="text" name="myName" />
<input type="submit" value="Submit" name="submit" />

Script (in the same form as the form is you wish)
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.";

#3 MikeWire

  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 09 August 2006 - 08:10 PM

What errors are you getting?  Also, for tutorials check out www.tizag.com - it helped me a ton when I first started using PHP...with SQL

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users