Loans | Loans | Credit Card | Free Ringtones | Loans
Cant INSERT into MySQL table using PHP [Archive] - PCMech Forums

PDA

View Full Version : Cant INSERT into MySQL table using PHP


adrianlewis
05-09-2004, 05:24 AM
Hi All,

having major problems with the following code. The code wont insert the info into the database however I know it connecting to the database because it displays how many rows are in the database and I can enter data using PHPMyAdmin...

<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body bgcolor="#FFFFFF" text="#000000">
<?php
print ("'$ProdID', '$Type', '$Cat', '$Name', '$ProdDesc', '$Temp', '$Size', '$Price', '$Stock'");
/* Start of PHP3 Script */
/* Data of SQL-server */
$server= "xxxxxx"; /* Address of 1&1 database server */
$user= "xxxxxx"; /* FTP-username */
$password= "xxxxxx"; /* FTP-Password */
$database= "xxxxxx"; /* name of database */
$table= "ORCProducts"; /* Name of table, you can select that */

/* Accessing SQL-Server and querying table */
$Link = MYSQL_CONNECT($server, $user, $password) or die ( "<H3>Server unreachable</H3>");
MYSQL_SELECT_DB($database) or die ( "<H3>Database non existent</H3>");
MYSQL_QUERY( "INSERT INTO $table VALUES('$ProdID', '$Type', '$Cat', '$Name', '$ProdDesc', '$Temp', '$Size', '$Price', '$Stock')");

/* Display number of entries */
$number=MYSQL_NUMROWS(MYSQL_QUERY( "SELECT * FROM $table"));
if ($number==0):
echo "database empty";
elseif ($number > 0):
echo "$number rows in database";
endif;
/* Close SQL-Connection */
MYSQL_CLOSE();

?>
<p><font size="1" face="Verdana, Arial, Helvetica, sans-serif">The new product has been added to the database</font></p>
<p><font face="Verdana, Arial, Helvetica, sans-serif" size="1"><a href="AllProductsAdmin.php">CONTINUE...</a></font></p>

</body>
</html>


Any ideas what might be wrong because im stumped at the mo?

Thanks

Adrian

adrianlewis
05-09-2004, 05:26 AM
Will try and enter it right this time. sorry...


<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body bgcolor="#FFFFFF" text="#000000">
<?php
print ("'$ProdID', '$Type', '$Cat', '$Name', '$ProdDesc', '$Temp', '$Size', '$Price', '$Stock'");
/* Start of PHP3 Script */
/* Data of SQL-server */
$server= "db76.oneandone.co.uk"; /* Address of 1&1 database server */
$user= "xxxxxx"; /* FTP-username */
$password= "xxxxxx"; /* FTP-Password */
$database= "xxxxxx"; /* name of database */
$table= "ORCProducts"; /* Name of table, you can select that */

/* Accessing SQL-Server and querying table */
$Link = MYSQL_CONNECT($server, $user, $password) or die ( "<H3>Server unreachable</H3>");
MYSQL_SELECT_DB($database) or die ( "<H3>Database non existent</H3>");
MYSQL_QUERY( "INSERT INTO $table VALUES('$ProdID', '$Type', '$Cat', '$Name', '$ProdDesc', '$Temp', '$Size', '$Price', '$Stock')");

/* Display number of entries */
$number=MYSQL_NUMROWS(MYSQL_QUERY( "SELECT * FROM $table"));
if ($number==0):
echo "database empty";
elseif ($number > 0):
echo "$number rows in database";
endif;
/* Close SQL-Connection */
MYSQL_CLOSE();

?>
<p><font size="1" face="Verdana, Arial, Helvetica, sans-serif">The new product has been added to the database</font></p>
<p><font face="Verdana, Arial, Helvetica, sans-serif" size="1"><a href="AllProductsAdmin.php">CONTINUE...</a></font></p>

</body>
</html>

mairving
05-09-2004, 06:58 AM
Unless you are accessing the MySQL server from a different domain than the one that it is on, $server should be localhost. If you are accessing it from another domain, make sure that your host has added the domain that you are coming from to the users table in MySQL.

adrianlewis
05-09-2004, 07:33 AM
Thanks,

Worked out what the problem was. turned out to be just 2 more fields that needed data and becasue they were missed off the INSERT it wouldnt accept any.

Adrian