Database Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsOther TechnologiesDatabase Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here
  #1  
Old August 29th, 2003, 03:32 AM
berniez berniez is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Geelong, Victoria, Australia
Posts: 4 berniez User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
mysql record insert

Hi, I am a newbie and am having troubles with record insert. When I insert through a form the auto increment updates but no data is written to the db. Here is the code for the 2 forms. Can someone please help. Using latest PHP and MySql and Apache. Thanks
Form 1
<html>
<body>
<form action=submitform.php method=POST>
First Name: <input type=text name=first_name size=25 maxlength=25>
Last Name: <input type=text name=last_name size=25 maxlength=25>
<p>
<input type=submit>
</form>
</body>
</html>

Form 2
<?php
$location = "localhost";
$username = "admin";
$password = "131154";
$database = "ausvans";
$conn = mysql_connect("$location","$username","$password");
if (!$conn) die ("Could not connect to database");
mysql_select_db($database,$conn) or die ("Could not open database");

$insert = "insert into newsletter (first_name,last_name)
values ('$first_name','$last_name')";
mysql_query ($insert) or die ("Could not add data to table");

echo $_POST["first_name"];
print (" ");
echo $_POST["last_name"];
print ("<p>");
print ("Thanks for submitting your name.");
?>

Reply With Quote
  #2  
Old August 29th, 2003, 05:44 AM
coderboi coderboi is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 80 coderboi User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
RE: mysql record insert

If your message at the end is displaying ok, it probably means that you may have register_globals off in your php.ini - try putting the following lines in before you define the $insert variable:

php Code:
Original - php Code
  1.  
  2.  
  3. $first_name = $_POST['first_name'];
  4. $last_name = $_POST['last_name'];
  5.  


of course, you could just use the $_POST statements within the $insert declaration

Reply With Quote
  #3  
Old August 29th, 2003, 11:28 AM
berniez berniez is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Geelong, Victoria, Australia
Posts: 4 berniez User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
RE: mysql record insert

Thanks for the info. It worked placing the variables b4 the insert command, but I tried putting the $_POST into the actual insert statement no luck. What is the correct syntax to use on the previous example.

Reply With Quote
  #4  
Old August 29th, 2003, 01:20 PM
tkarkkainen's Avatar
tkarkkainen tkarkkainen is offline
Moderator
Click here for more information
 
Join Date: Apr 2007
Location: Finland
Posts: 2,320 tkarkkainen User rank is Lance Corporal (50 - 100 Reputation Level)tkarkkainen User rank is Lance Corporal (50 - 100 Reputation Level)tkarkkainen User rank is Lance Corporal (50 - 100 Reputation Level)  Folding Points: 10700 Folding Title: Novice Folder
Time spent in forums: 6 Days 8 h 46 m 16 sec
Reputation Power: 4
RE: mysql record insert

php Code:
Original - php Code
  1.  
  2. $insert="insert into newsletter (first_name,last_name)
  3. values ('".$_POST['first_name]."','".$_POST['last_name']."')";


Or just:

php Code:
Original - php Code
  1.  
  2. $insert="insert into newsletter (first_name,last_name)
  3. values ('$_POST[first_name]','$_POST[last_name]')";
  4.  

Reply With Quote
Reply

Viewing: Codewalkers ForumsOther TechnologiesDatabase Help > mysql record insert


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway