Go Back   SitePoint Forums > Forum Index > Program Your Site > PHP
Newsletter FAQ Members List Calendar Mark Forums Read

New to SitePoint Forums? Register here for free!

SitePoint Sponsor
 
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Old Nov 7, 2006, 18:42   #1
ChrisjChrisj
SitePoint Evangelist
 
Join Date: Nov 2004
Location: calif
Posts: 481
Help setting up tables in phpmyadmin

I have, what should be a simple php script, where a buyer enters his name into a text box and then selects Submit, and the date, and buyers name, is entered in the phpmyadmin database table.

However, I don't know to set up table for this info.

Could someone look over this short script and describe to me how to set up a table to capture the info sent from this script?

I see where it says created a new table on _____________ but I don't know how to set up fields, etc.

Any help, walking me through the few fields I might need, would be greatly appreciated. Thanks.
Code:
<?php
//require_once('include/db.php');
$dbhost = 'localhost';
$dbname = 'myweb_phpb1';
$dbuser = 'myweb_ben';
$dbpasswd = '1234';

$err = '';

mysql_connect($dbhost,$dbuser,$dbpasswd) or die('Error: ' . mysql_error());
mysql_select_db($dbname) or die('Error: ' . mysql_error());

//get buyer and seller from form
$buyer = stripslashes(trim($_POST['buyer']));
$seller = stripslashes(trim($_POST['seller']));

//Define required fields to register, with the error message
$requiredFields = array("buyer" => "Buyer name required",
"seller" => "You must make a payment before you can submit a Transaction Notification.");

//Check to see if fields are empty
foreach($requiredFields as $field => $label)
{
if (!$_POST[$field])
{
//If field is empty add it's error message
$err .= "$label<br>";
}
}

$chkUser = mysql_query("Select * FROM phpbb_users where username = '$buyer'") or die(mysql_error());

//Check for valid buyer
if(!mysql_num_rows($chkUser) > 0)
{
$err .= "The buyer's username " . addslashes($buyer) . " does not exist.";
}

//check to see if the buyer has sent a receipt in the past minute.
$sql = mysql_query("SELECT date FROM receipt where buyer = '$buyer' ORDER BY date DESC LIMIT 1") or die(mysql_error());
$result = mysql_fetch_array($sql);
$last_trans = substr($result['date'],11,8);
$last_time = strtotime($last_trans);

if($last_time >= (time() - 60))
{
$err .= 'You cannot send another Payment Notification at this time. Please wait 60 seconds, while your initial transaction is processing';

$err .= ('<meta http-equiv="refresh" content="15.0; URL=index.php">');
}

$chkUser = mysql_query("Select * FROM phpbb_users where username = '$seller'") or die(mysql_error()); 

//Check for valid seller 
if(!mysql_num_rows($chkUser) > 0) 
{ 
$err .= "The Seller username " . addslashes($seller) . " does not exist."; 
} 
//If there are any errors, display them, else register user
if($err)
{
echo("<p><font color='red'><b>");
echo($err);
echo("</b></font></p>");
}
//if there are no errors, proceed
else
{
//insert buyer, seller, date into receipt
$add = mysql_query("INSERT INTO receipt (buyer,seller,date) VALUES ('$buyer','$seller',NOW())");

//get the seller's email address
$sql = mysql_query("SELECT * FROM phpbb_users WHERE username = '$seller'");
$seller_mail = mysql_fetch_array($sql);

//email setup
$to = $seller_mail['user_email'];
$from = "receipt@myweb.com";
$subject = "Transaction Notification from myweb";
$date = date('m-d-Y');
$message = ('Attention ' . $seller . ', 
This is a message from myweb.com notifiying you that a transaction has been logged to your payment account by ' . $buyer . ', on ' . $date); 
//send message 
$send = mail($to,$subject,$message,"FROM: $from"); 

//if $add and $send both are successful, display success message 
if ($add && $send) 
{ 
echo('A notification of your transaction has been sent to the seller, via email. Thank you.<br />');
echo('<a href="index.php">Continue</a>');
} 
//else, display error message 
else 
{ 
echo('There was an error with the form. Please try again later.<br>' . mysql_error()); 
} 
} 
?>

Last edited by stymiee; Nov 7, 2006 at 19:30. Reason: Please use bbcode when posting
ChrisjChrisj is offline   Reply With Quote
 

Bookmarks

« Previous Thread | Next Thread »

Thread Tools
Display Modes

 
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Sponsored Links
 
Forum Jump


All times are GMT -7. The time now is 00:50.


Powered by vBulletin® Version 3.7.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Copyright 1998-2009, SitePoint Pty Ltd. All Rights Reserved