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:
  #1  
Old January 4th, 2003, 04:19 AM
Pierre Pierre is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Victoria, BC, Canada
Posts: 3 Pierre User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
PHP inputting blank records into mysql

Hey all,

I'm totally new at this...
I have a test server on my home network, running Red Hat 8.0/Apache 2.0.43/PHP 4.3.0/MySQL 3.23.54

I've written this form in DreamweaverMX and the form works fine. However, when I look at the MySQL database, the records are blank. Is it an improperly set network or is there something wrong with my PHP installation? or is my code bad? Help please!

<form method="post" action="formmail.php">
<table width="400" border="0" cellspacing="1" cellpadding="4" align="center">
<tr>
<td>Screenname</td>
<td><input type="TEXT" name="screenname" size="32" maxlength="50"></td>
</tr>
<tr>
<td>First Name</td>
<td><input type="TEXT" name="firstname" size="32" maxlength="50"></td>
</tr>
<tr>
<td>Last Name</td>
<td><input type="TEXT" name="lastname" size="32" maxlength="50"></td>
</tr>
<tr>
<td colspan="2"><div align="center">
<input type="SUBMIT" name="submit" value="Send Message"></div></td>
</tr>
</table>
</form>

and formmail.php looks like:
<?php
$user = "user";
$password = "password";
$db = "database";
$link = mysql_connect("192.168.1.4", $user, $password);
if (!$link )
die("Couldn't connect to MySQL");
mysql_select_db($db, $link)
or die ("Couldn't open $db:" .mysql_error());
$query = "INSERT INTO names (screenname, firstname, lastname)
VALUES ('$screenname', '$firstname', '$lastname')";
mysql_query($query)
or die (mysql_error() );
mysql_close($link);
?>

Thanks in advance!

Pierre

Reply With Quote
  #2  
Old January 4th, 2003, 05:07 AM
bob0099 bob0099 is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: manchester,n.h.,usa
Posts: 172 bob0099 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
RE: PHP inputting blank records into mysql

your version of PHP comes with register globals off.

You need to use the superglobals. In this case you would use the $_POST[]
variable.

change :
$query = "INSERT INTO names (screenname, firstname, lastname)
VALUES ('$screenname', '$firstname', '$lastname')";

to :

$query = "INSERT INTO names (screenname, firstname, lastname)
VALUES ('$_POST[screenname]', '$_POST[firstname]', '$_POST[lastname]')";

and that should do it.

Reply With Quote
  #3  
Old January 4th, 2003, 05:39 AM
Pierre Pierre is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Victoria, BC, Canada
Posts: 3 Pierre User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
RE: PHP inputting blank records into mysql

Thanks Kaboo!

Worked like a charm!

Can I turn globals on instead of having to type $_POST[] everywhere?

Thanks for your prompt reply btw!

Pierre

Reply With Quote
  #4  
Old January 4th, 2003, 08:55 AM
hermawan's Avatar
hermawan hermawan is offline
Superman is not dead
Codewalkers Novice (500 - 999 posts)
 
Join Date: Apr 2007
Location: Jakarta, Indonesia
Posts: 552 hermawan User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 14 h 21 m 55 sec
Reputation Power: 2
Send a message via ICQ to hermawan Send a message via AIM to hermawan Send a message via Yahoo to hermawan Send a message via Google Talk to hermawan Send a message via Skype to hermawan
RE: PHP inputting blank records into mysql

Yes you can turn it on.
Edit the php.ini on your server on line where it says:
register_globals Off
set to On

Reply With Quote
Reply

Viewing: Codewalkers ForumsOther TechnologiesDatabase Help > PHP inputting blank records into mysql


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 1 hosted by Hostway