Forum Moderators: coopster
function make_page_lable($artist) {
$sql = $sql = 'SELECT *'
. 'FROM artists'
. 'WHERE artist LIKE "%'. $artist .'%"';
$result = mysql_query($sql);
if (!$result) {
print mysql_error() . "Error - discriptor Query Failed";
}
$content="";
$row .= mysql_query($result);
$content = '<h1 align="center">' . $row['artist'] . '</h1>';
$content .= '<p align="center">'. $row['artistbio'].'</p>';
return $content;
}
I'm using LIKE because the field in the DB is likely to have upper case letters - and to use the same value throughout the page I strlower($artist).
I've tried all sorts of variations on the punctuation. I'm sure its something simple, but my newbie eyes are missing it... Please help?
John
I wouldn't use that script unless you want to send attachments. Just use the mail function that comes with php. It's really quite simple. Go here in the manual [php.net] to get more of the specifics.
Just when I think I have a handle on it...
What is wrong with this code?
/* get variables */
$cname = $_POST['fullname'];
$ccompany = $_POST['company'];
$caddr1 = $_POST['address1'];
$caddr2 = $_POST['address2'];
$ccity = $_POST['city'];
$cstate = $_POST['state'];
$ccountry = $_POST['country'];
$isbill = $_POST['isbilladdress'];
$baddr1 = $_POST['billaddress1'];
$baddr2 = $_POST['billaddress2'];
$bcity = $_POST['billcity'];
$bstate = $_POST['billstate'];
$bzip = $_POST['billzip'];
$bctry = $_POST['billcountry'];
$cphone = $_POST['telephone'];
$cfax = $_POST['fax'];
$cemail = $_POST['email'];
$payby = $_POST['paymentmethod'];
$instruct = $_POST['specialinstructions'];
$termsok = $_POST['acceptterms'];
$maillist = $_POST['maillist'];
$itemdesc = $_POST['itemdesc'];
$price = $_POST['price'];
$itemno = $_POST['itemno'];
$class = $_POST['table'];
/* now build functions */function make_confirm (){
echo '<h2 align="center">Your order is Confirmed</h2>';
if ($isbill!= 'yes') {echo '<p> Your billing and shipping addresses are different.
These addresses must be confirmed before shipment will be made.</p>';}
echo '<p>Pay Pal purchases will only be shipped to a confirmed Pay Pal address. </p>';
if ($ccountry!= 'United States') {echo '<p>Your international shipping options will be sent to you in the followup email.</p>';}
echo '<p>Your order for '.$itemdesc . 'priced at $'.$price .' has been submitted. You will receive a confirmation email shortly.</p>';
echo '<p>Within 36 hours you should also receive email from us regarding shipping and confirming your payment method.</p>';
echo '<p>Thank you for your purchase! We look forward to serving your needs in the future.</p>';
$sql = 'UPDATE '. $class . 'SET itemstatus=0 WHERE item ='.$itemno;
mysql_query($sql);
}
print make_confirm();
When I run the loop
foreach ($_POST as $fieldname => $value) {
echo "$fieldname is $value<br />";
}
it echos the fields... but in the code above, none of the variables show up!
John
I would suggest that you do not draw the price from the $_POST array, or that if you do that you should compare to the price in the DB.
Failure to do this opens the door to someone calling the script with altered form fields and obtaining the item for far less than you are selling it for!
WBF
When I run the function with your 'foreach' loop (above) it echos the content of the _post array!
<h2 align="center">Order Form</h2>
<form name="orderform" action="postorder.php" method="post" onSubmit="return fcheckfields(document.forms[0])">
<?php
echo '<input name="table" type="hidden" value="'.$table.'">'."\n";
echo '<input name="itemno" type="hidden" value="'.$itemnum.'">'."\n";
echo '<input name="itemdesc" type="hidden" value="'.$itemdesc.'">'."\n";
echo '<input name="price" type="hidden" value="'.$price.'">'."\n";
?>
<table border="0" cellpadding="2" cellspacing="0">
<tr>
<td>
<div align="right">
<b>Full name:</b></div>
</td>
<td width="6"></td>
<td><input type="text" name="fullname" size="50"></td>
</tr>
<tr>
<td>
<div align="right">
<b>Company:</b></div>
</td>
<td width="6"></td>
<td><input type="text" name="company" size="50"></td>
</tr>
<tr>
<td></td>
<td width="6"></td>
<td><b>Shipping address:</b></td>
</tr>
<tr>
<td>
<div align="right">
<b>Address Line 1:</b></div>
</td>
<td width="6"></td>
<td><input type="text" name="address1" size="50"></td>
</tr>
<tr>
<td>
<div align="right">
<b>Address Line 2:</b></div>
</td>
<td width="6"></td>
<td><input type="text" name="address2" size="50"></td>
</tr>
<tr>
<td>
<div align="right">
<b>City:</b></div>
</td>
<td width="6"></td>
<td><input type="text" name="city" size="30"></td>
</tr>
<tr>
<td>
<div align="right">
<b>State/Province/Region:</b></div>
</td>
<td width="6"></td>
<td><input type="text" name="state" size="30"></td>
</tr>
<tr>
<td>
Thats a snip of the form.
If you were to simply move your /*get variables*/ chunk of code into the top of your makeconfirm function, you will get the desired results.
Also, you are using print makeconfirm(), but echoing the data within the function. You may want to remove the print function and just call your user-defined function.
make_confirm();all by its lonesome.
By the way, here's a link regarding variable scope [php.net].
$sql = 'UPDATE '. $class . 'SET itemstatus=0 WHERE item ='.$itemno;
exit($sql);
mysql_query($sql);
Example code snippet:
if (mysql_errno()) {
printf("Error is %s",mysql_error());
}
Here's what comes out:
UPDATE ornith SET itemstatus=0 WHERE item =110001
do I have to have the DB name there too? Here is the code for the SQL:
$dbh=mysql_connect ("localhost", "****xx_joetest", "****xx") or die ('Cannot connect to Database - error: ' . mysql_error () );
mysql_select_db("****xx_joetest1",$dbh);
$sql = 'UPDATE '. $class . ' SET itemstatus=0 WHERE item ='.$itemno;
exit($sql);
mysql_query($sql);
Do I need a space between the "item ='" - such as "item = '"?
Or do I need to be more specific in my SQL statement, such as specifying the DBname and table? (xxxjoetest1.$class)<i know thats wrong syntax.. just conveying the idea...>
when I run the query replacing the variable with fixed values in myPHPadmin the query works...
The query on the page returns no errors...
John
Let me remark that out now that I have the spacing correct. Stay Tuned!
John
Update: (no pun!) - Dang! See, it was just spacing and such. Once I got the SQL right I should have taken out the EXIT. Dang! Now it's working DANDY!
Thanks a million guys!
Next step - pass all these variables to the administrator via email for processing...
John
Sooner or later, you're going to want to know all about PHP configuration [php.net]!
Ok... that configuration link blew the back off my brain-pan.
Well it's no wonder since your hair folicles (which have gone missing) were actually attaching that to your head.
Umm, Ok, so I'll try the headers thing!
$headers = "From: " . $first_name . " " . $last_name . " <" . $email . ">\r\n";
mail($to, $subject, $message, $headers);
When I insert a row, how can I return the 'autoincrement ID' value?
$id = mysql_insert_id();