Go Back   PCMech Forums > Help & Discussion > Web Design / Development

Need Some Help? Type Your Keywords Here:

Reply
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
Old 05-09-2004, 04:24 AM   #1
Member (6 bit)
 
Join Date: May 2003
Location: Leeds, West Yorkshire, UK
Posts: 56
Angry Cant INSERT into MySQL table using PHP

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...








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 ( "

Server unreachable

");
MYSQL_SELECT_DB($database) or die ( "

Database non existent

");
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();

?>

The new product has been added to the database


CONTINUE...







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

Thanks

Adrian
adrianlewis is offline   Reply With Quote
Old 05-09-2004, 04:26 AM   #2
Member (6 bit)
 
Join Date: May 2003
Location: Leeds, West Yorkshire, UK
Posts: 56
Will try and enter it right this time. sorry...

PHP Code:
<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>
adrianlewis is offline   Reply With Quote
Old 05-09-2004, 05:58 AM   #3
Staff
Premium Member
 
mairving's Avatar
 
Join Date: Jul 1999
Location: Arlington, TN
Posts: 5,538
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.
mairving is offline   Reply With Quote
Old 05-09-2004, 06:33 AM   #4
Member (6 bit)
 
Join Date: May 2003
Location: Leeds, West Yorkshire, UK
Posts: 56
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
adrianlewis is offline   Reply With Quote
Reply

Bookmarks

Still Need Help? Type Your Keywords Here:


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -5. The time now is 12:54 AM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
SEO by vBSEO 3.6.0 PL2