I am new to PHP. Could you please help me why the following code does not add the data to the database. Note: I can use the MySQL client program to add records no problem. When I try the code below it does nothing.
If you do what markl999 suggested you may find that the variables used in your $prod_statement do not have a value. I would think this is because you have register_globals off.
Thank you. I made the changes and a blnak screen is what I get. Would there be a simple code that show me whether I can even connect without even trying to add any record using a form?
<?php
$link = @mysql_connect("host", "user", "pass");
if (!$link) {
// unable to connect to database
echo 'Failed to connect';
}
else {
// you were able to connect to the database
echo 'Database connect succeeded';
}
?>
I thought that meant changeing the config file. Is there even a way to just simple test a connection to MySQL database using PHP without adding any records?
tags when posting code. Read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
nigma tested the code you provided and I get a blnk screen.
PHP:
<?php
$link = @mysql_connect("localhost", "mmaru", "marumysql");
if (!$link) {
// unable to connect to database
echo 'Failed to connect';
}
else {
// you were able to connect to the database
echo 'Database connect succeeded';
}
?>
I am using PHP 5 if it is going to make a difference.
It does not work - I do not know why. I have not used PHP with MySQL before this is just my first try to see whether I can even connect before I do anything. Am I missing something in configuring the two?
<?php
mysql_connect('localhost','mmaru','marumysql') or die(mysql_error());
$query = mysql_query('SELECT VERSION()') or die(mysql_error());
print_r(mysql_fetch_row($query));
tags when posting code. Read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
By the way - Apache and PHP work no problem. The following code works fine.
HTML:
<HTML>
<HEAD>
<TITLE>Using Numbers</TITLE>
</HEAD>
<BODY>
<?php
/* $Quantity must be passed to this page from a form or via the URL.
$Discount is optional.*/
$Cost=2000.00;
$Quantity = abs($Quantity);
$Discount = abs($Discount);
$Tax=0.06;
$Tax = $Tax++; // $Tax is now worth 1.06.
$TotalCost = (($Cost * $Quantity) - $Discount) * $Tax;
$Payments = round($TotalCost, 2) / 12;
// Print the results.
print ("You requested to pruchase $Quantity widget(s) at \$$Cost each.\n<P>");
print ("The total with tax, minus your \$$Discount discount, comes to $");
printf ("%01.2f", $TotalCost);
print (".\n<P>You may purchase the widget(s) in 12 monthly installments of $");
printf ("%01.2f", $Payments);
print (" each.\n<P>");
?>
</BODY>
</HTML>
<HTML>
<HEAD>
<TITLE>Using Numbers</TITLE>
</HEAD>
<BODY>
<?php
/* $Quantity must be passed to this page from a form or via the URL.
$Discount is optional.*/
$Cost=2000.00;
$Tax=0.06;
$TotalCost = $Cost * $Quantity;
$Tax = $Tax + 1; // $Tax is now worth 1.06.
$TotalCost = $TotalCost - $Discount;
$TotalCost = $TotalCost * $Tax;
$Payments = $TotalCost / 12;
// Print the results.
print ("You requested to pruchase $Quantity widget(s) at \$$Cost each.\n<P>");
print ("The total with tax, minus your \$$Discount discount, comes to $");
printf ("%01.2f", $TotalCost); \\ \$$TotalCost.\n<P>");
print (".\n<P>You may purchase the widget(s) in 12 monthly installments of $");
printf ("%01.2f", $Payments); \\\n$$Payments) each.\n<P>");
print (" each.\n<P>");
?>
</BODY>
</HTML>