[advanced search]
 

Go Back   NamePros.com > Discussion > Web Design & Development > Programming

Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics.


Closed Thread
 
LinkBack Thread Tools
Old 05-09-2005, 08:37 AM   #1 (permalink)
Account Closed
 
Join Date: May 2005
Posts: 62
117.25 NP$ (Donate)

unixbro-patty is a name known to allunixbro-patty is a name known to allunixbro-patty is a name known to allunixbro-patty is a name known to allunixbro-patty is a name known to allunixbro-patty is a name known to all


PHP code not working

Code:
$connection = mysql_connect("localhost", "$user", "$password") or die("Couldn't connect to database");

$db = mysql_select_db($database, $connection) or die("Couldn't choose database.");

$sql = mysql_query("INSERT INTO $table_name (first_name, last_name, birthdate, address, city, state, zip, phone) VALUES ('$first_name', '$last_name', '$birthdate', '$address', '$city', '$state', '$zip', '$phone')");

can someone tell me why the above code isn't putting anything inat a database except the int and date defaults?

unixbro-patty is offline  
Old 05-09-2005, 09:02 AM   #2 (permalink)
Senior Member
 
Join Date: May 2003
Posts: 2,211
6,170.25 NP$ (Donate)

adam_uk is a jewel in the roughadam_uk is a jewel in the roughadam_uk is a jewel in the rough

Breast Cancer
delete the $sql = bit

what your doing is putting that the query function to a variable but not calling the variable afterwards.

what you could do is
PHP Code:
$sql = "MY MYSQL `query` HERE"
mysql_query($sql);
adam_uk is offline  
Old 05-09-2005, 10:39 AM   #3 (permalink)
NamePros Member
 
Join Date: Nov 2003
Location: Ontario, Canada
Posts: 91
80.80 NP$ (Donate)

eagle12 is on a distinguished road


We need to see more of the code to try and figure out the problem.
eagle12 is offline  
Old 05-09-2005, 12:21 PM   #4 (permalink)
Account Closed
 
axilant's Avatar
 
Join Date: May 2004
Location: /etc/passwd
Posts: 2,194
0.00 NP$ (Donate)

axilant is a splendid one to beholdaxilant is a splendid one to beholdaxilant is a splendid one to beholdaxilant is a splendid one to beholdaxilant is a splendid one to beholdaxilant is a splendid one to behold


not sure but if you are getting this info from a form posting with method of POST or GET:

PHP Code:
$connection = mysql_connect("localhost", "$user", "$password") or die("Couldn't connect to database");

$db = mysql_select_db($database, $connection) or die("Couldn't choose database.");

$sql = mysql_query("INSERT INTO $table_name (first_name, last_name, birthdate, address, city, state, zip, phone) VALUES ('$_POST[first_name]', '$_POST[last_name]', '$_POST[birthdate]', '$_POST[address]', '$_POST[city]', '$_POST[state]', '$_POST[zip]', '$_POST[phone]')");
This will also be a little more secure.
if your using the GET method change _POST to _GET.

Cody Selzer
axilant is offline  
Old 05-09-2005, 02:16 PM   #5 (permalink)
Soon to be RICHdoggie!
 
PoorDoggie's Avatar
 
Join Date: Jan 2005
Location: UK
Posts: 2,390
316.50 NP$ (Donate)

PoorDoggie is just really nicePoorDoggie is just really nicePoorDoggie is just really nicePoorDoggie is just really nice


you could add this code:
PHP Code:
if( !$sql ){
echo
"Could not add to database";
}
this will run the mysql query AND report on any errors. lol

Dunno if this will work though.
PoorDoggie is offline  
Old 05-09-2005, 02:46 PM   #6 (permalink)
RJ
NamePros Founder

Administrator

 
Join Date: Feb 2003
Location: Bay Area, CA
Posts: 13,173
104,451.68 NP$ (Donate)

RJ Has achieved greatnessRJ Has achieved greatnessRJ Has achieved greatnessRJ Has achieved greatnessRJ Has achieved greatnessRJ Has achieved greatnessRJ Has achieved greatnessRJ Has achieved greatnessRJ Has achieved greatnessRJ Has achieved greatnessRJ Has achieved greatness

Find Marrow Donors! Cystic Fibrosis
The part you posted looks fine, unixbro. Would have to see the whole script to see what's not working right.
RJ is offline  
Old 05-09-2005, 05:07 PM   #7 (permalink)
NamePros Member
 
Join Date: Nov 2003
Location: Ontario, Canada
Posts: 91
80.80 NP$ (Donate)

eagle12 is on a distinguished road


It sounds like you don't have anything being stored in the variables you trying to insert into the DB. As RJ said, and I said earlier, we need to see more code.
eagle12 is offline  
Old 05-11-2005, 05:47 PM   #8 (permalink)
Account Closed
 
Join Date: May 2005
Posts: 62
117.25 NP$ (Donate)

unixbro-patty is a name known to allunixbro-patty is a name known to allunixbro-patty is a name known to allunixbro-patty is a name known to allunixbro-patty is a name known to allunixbro-patty is a name known to all


Code:
<?php
$db_name = "xxxxxxx";
$username = "xxxxxx";
$password = "xxxxxx";
$tbl_name = "xxxxxx";
$connection = mysql_connect("localhost", "$username", "$password") or die("Couldn't connect to database");
$db = mysql_select_db($db_name, $connection) or die("Couldn't choose database.");
$sql = mysql_query("INSERT INTO $tbl_name (first_name, last_name, birthdate, address, city, state, zip, phone) VALUES ('$first_name', '$last_name', '$birthdate', '$address', '$city', '$state', '$zip', '$phone')");
mysql_query($sql);
$result = mysql_query($sql, $connection);
if (!$result) {
   die('Could not query:' . mysql_error());
}
else { 
   die('Data entered correctly.');
}

?>
<html>
<title>Database connect</title>
<body>
<? 
echo "$msg"; 
echo "<p>First Name: $first_name <br>";
echo "<p>Last Name: $last_name <br>";
echo "<p>Birthdate: $birthdate <br>";
echo "<p>Address: $address <br>";
echo "<p>City: $city <br>";
echo "<p>State: $state <br>";
echo "<p>Zip: $zip <br>";
echo "<p>Phone: $phone <br>";
?>
</body>
</html>

There's the whole code still not working
unixbro-patty is offline  
Old 05-11-2005, 05:49 PM   #9 (permalink)
Account Closed
 
axilant's Avatar
 
Join Date: May 2004
Location: /etc/passwd
Posts: 2,194
0.00 NP$ (Donate)

axilant is a splendid one to beholdaxilant is a splendid one to beholdaxilant is a splendid one to beholdaxilant is a splendid one to beholdaxilant is a splendid one to beholdaxilant is a splendid one to behold


odd, wheres the form?

PHP Code:
<?php
$db_name
= "xxxxxxx";
$username = "xxxxxx";
$password = "xxxxxx";
$tbl_name = "xxxxxx";
$connection = mysql_connect("localhost", "$username", "$password") or die("Couldn't connect to database");
$db = mysql_select_db($db_name, $connection) or die("Couldn't choose database.");
$sql = @mysql_query("INSERT INTO $tbl_name (first_name, last_name, birthdate, address, city, state, zip, phone) VALUES ('$first_name', '$last_name', '$birthdate', '$address', '$city', '$state', '$zip', '$phone')") OR DIE(mysql_error());



?>
<html>
<title>Database connect</title>
<body>
<?
echo "$msg";
echo
"<p>First Name: $first_name <br>";
echo
"<p>Last Name: $last_name <br>";
echo
"<p>Birthdate: $birthdate <br>";
echo
"<p>Address: $address <br>";
echo
"<p>City: $city <br>";
echo
"<p>State: $state <br>";
echo
"<p>Zip: $zip <br>";
echo
"<p>Phone: $phone <br>";
?>
</body>
</html>
axilant is offline  
Old 05-11-2005, 06:40 PM   #10 (permalink)
Account Closed
 
Join Date: May 2005
Posts: 62
117.25 NP$ (Donate)

unixbro-patty is a name known to allunixbro-patty is a name known to allunixbro-patty is a name known to allunixbro-patty is a name known to allunixbro-patty is a name known to allunixbro-patty is a name known to all


axilant ... thanks man it works now. and you helped me learn I appreciate it
unixbro-patty is offline  
Old 05-11-2005, 07:38 PM   #11 (permalink)
Account Closed
 
axilant's Avatar
 
Join Date: May 2004
Location: /etc/passwd
Posts: 2,194
0.00 NP$ (Donate)

axilant is a splendid one to beholdaxilant is a splendid one to beholdaxilant is a splendid one to beholdaxilant is a splendid one to beholdaxilant is a splendid one to beholdaxilant is a splendid one to behold


Quote:
Originally Posted by unixbro
axilant ... thanks man it works now. and you helped me learn I appreciate it
im pleased to hear you compliment me like that

and no problem hit me on any instant messager if you need help (check profile)
axilant is offline  
Closed Thread


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Tutorial: Getting started with PHP (The Basics) deadserious Webmaster Tutorials 60 11-17-2007 11:35 AM
Googlism - What does google think of you? deadserious The Break Room 55 12-15-2005 09:09 AM
Basic HTML Tutorial webgear Webmaster Tutorials 8 04-02-2005 02:20 PM

Site Sponsors
Advertise your business at NamePros

All times are GMT -7. The time now is 12:45 PM.


Powered by: vBulletin® Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0
Template-Modifications by TMS
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85