php won't insert into ... - Webmaster Forums - Webmaster forum for HTML, PHP, ASP, CSS and more
Webmaster Forums - Webmaster forum for HTML, PHP, ASP, CSS and more
Go Back   Webmaster Forums - Webmaster forum for HTML, PHP, ASP, CSS and more > Webmaster Tech > Programming > PHP Development

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 02-01-2009, 08:32 PM   #1 (permalink)
Regular User
 
Join Date: Nov 2008
Posts: 20
Default php won't insert into ...

Hello:

I am trying to get my insert into mysql to work and it just plain does not work. I have copied the insert part into a text file and manually executed the code via source and it works but for some reason it won't via php. Is there someting I am missing or not getting? I have the loop at the begining to test if the variables are getting thru and they are.

<?php
// Loop to pass the variables from previous script
//
foreach (array_keys($_POST) as $key)
{
$$key = $_POST[$key];
//print "$key is ${$key}<br />";
print "$key ==> ${$key}<br />";
}
//
//
mysql_connect("localhost", "root", "xxxxxxxxx") or die('Could not connect: ');
mysql_select_db("test") or die('Could not connect again: ');
//
$sql = ("INSERT INTO tblnadda (tblNADA_User01,tblNADA_User02) VALUES ('namef','namem')") or die('Could not add records ');

$result = mysql_query("SELECT * FROM tblnadda");

$num_rows = mysql_num_rows($result);

echo "$num_rows Rows\n";
//
?>
pepe_lepew1962 is offline   Reply With Quote
Sponsored Links
Old 02-04-2009, 12:43 PM   #2 (permalink)
Junior Member
 
Join Date: Feb 2009
Posts: 1
Default Re: php won't insert into ...

shouldn't this:
PHP Code:
$sql = ("INSERT INTO tblnadda (tblNADA_User01,tblNADA_User02) VALUES ('namef','namem')") or die('Could not add records '); 
be

PHP Code:
$sql mysql_query("INSERT INTO tblnadda (tblNADA_User01,tblNADA_User02) VALUES ('namef','namem')") or die('Could not add records '); 
?
KaeVectori is offline   Reply With Quote
Old 02-18-2009, 07:55 AM   #3 (permalink)
Junior Member
 
Join Date: Feb 2009
Posts: 12
Default Re: php won't insert into ...

You should read this article on W3School about SQL - the Insert Into statement.
SQL INSERT INTO Statement

PHP Code:
$sql "INSERT INTO tblnadda (tblNADA_User01,tblNADA_User02) VALUES ('namef','namem') 
Ariyes1 is offline   Reply With Quote
Old 02-22-2009, 10:40 AM   #4 (permalink)
Junior Member
 
Join Date: Oct 2008
Posts: 60
Default Re: php won't insert into ...

Quote:
Originally Posted by KaeVectori
shouldn't this:
PHP Code:
$sql = ("INSERT INTO tblnadda (tblNADA_User01,tblNADA_User02) VALUES ('namef','namem')") or die('Could not add records '); 
be

PHP Code:
$sql mysql_query("INSERT INTO tblnadda (tblNADA_User01,tblNADA_User02) VALUES ('namef','namem')") or die('Could not add records '); 
?
That is exactly correct. This should fix your problem.

AD
clinkpc is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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



» Sponsors

» Links

» Affiliates
Web Hosting
Online Backup Reviews
Marketing Find
Merchant Select
SiteMap Builder
Host Compare

» Links

» Sports Network
Paintball Forum
Football Forum
Hockey Forum
Golf Forum
Boxing Forum
Lacrosse Forum
Baseball Forum
SnowBoarding Forum
Soccer Forum
MMA Forum


All times are GMT -4. The time now is 07:35 PM.


Powered by vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.2
Webmaster Forums
Web Hosting | Chicago Web Hosting | Web Hosting