PDA

View Full Version : Insert a record


Dingbat
10-21-2006, 09:29 AM
If all else fails consult the experts.

Hi Guy's,

I really would appreciate any help that any of you experts can can give.

I have tried to cobble togther 2 scripts to acheive the following objectives.

1. Insert data into a table.
2. Create a thank you page.
3. Send an email to inform the administrator that a new record had been inserted.

When I try to run the script I get a warning error to say "Warning: mysql_select_db(): supplied argument is not a valid MySQL-Link resource in ........ at line 33 and also at line 34".

I feel sure that the problem is something simple but having tried all ways to sort out the problem I fail.

The script is listed below:

<?php
$Company = $_POST['Company'];
$UserName = $_POST['Username'];
$Email = $_POST['Email'];
$Password = $_POST['Password'];
$Telephone = $_POST['Telephone'];

$insertSQL = sprintf("INSERT INTO password2 (Company, Username, Email, Password, Telephone) VALUES (%s, %s, %s, %s, %s)",
$Company,
$Username,
$Email,
$Password,
$Telephone);

mysql_select_db($database_Fencehome, $Fencehome);
$Result1 = mysql_query($insertSQL, $Fencehome) or die(mysql_error());
?>

<p align="center"><font color="#000000"><img src="file:///G|/images/owl.gif" width="56" height="73"><font color="#FF0000" size="+4">Thank you from Fencewize</font></font></p>
<table width="600" border="1" align="center">
<tr>
<td>Dear, <b><?php echo $UserName; ?></b>,<br><br> Thank you for your application for a trade account at Fencewize Ltd.<br> We will contact you using the following to confirm your username and password!<br><br>
Your e-mail address is: <b><?php echo $Email; ?></b><br><br>
Your telephone number:<b><?php echo $Telephone; ?></b><br><br>
<?php
//start building the mail string
$msg = "Name: $_POST[Name]\n";
$msg .= "Telephone: $_POST[phone]\n";
$msg .= "E-Mail: $_POST[From]\n";

//set up the mail
$recipient = "beta";
$subject = "Form Submission Results";
$mailheaders = "From: My Web Site <beta> \n";
$mailheaders .= "Reply-To: $_POST[email]\n\n";

//send the mail
mail($recipient, $subject, $msg, $mailheaders);
?></td>
</tr>
</table>

Thanks in anticipation.

The Dingbat

Brandoe85
10-21-2006, 09:34 AM
Hi,

I don't see you calling mysql_connect() anywhere before you select the db. Also, where are $database_Fencehome and $Fencehome defined?

Good luck;

nextri
10-22-2006, 12:38 PM
yeah ,you have to connect before you select a db. also useful to use or die(mysql_error); after your query so you get a message if the query fails.