NamePros
Welcome, Guest! Ready to make a name for yourself in the domain business? We welcome both the hobbyist and professional domainer to join the discussion as part of the NamePros community.

Click here to create your profile to start earning reputation for posting, and trader ratings for buying & selling in our free e-marketplace. Build your trader rating with each successful sale. Our system has tracked over 100,000 sales and counting!
FAQ & TOS Register Search Today's Posts Mark Forums Read

Go Back   NamePros.com > Website Development Discussion Forums > Programming
Reload this Page PHP code not working

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

Advanced Search


Closed Thread
 
LinkBack Thread Tools
Old 05-09-2005, 09:37 AM THREAD STARTER               #1 (permalink)
Account Closed
Join Date: May 2005
Posts: 62
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')");

????: NamePros.com http://www.namepros.com/programming/88892-php-code-not-working.html
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, 10:02 AM   #2 (permalink)
Senior Member
Join Date: May 2003
Posts: 2,187
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
????: NamePros.com http://www.namepros.com/showthread.php?t=88892
PHP Code:
$sql "MY MYSQL `query` HERE"
mysql_query($sql); 
adam_uk is offline  
Old 05-09-2005, 11:39 AM   #3 (permalink)
NamePros Member
Join Date: Nov 2003
Location: Ontario, Canada
Posts: 127
eagle12 will become famous soon enougheagle12 will become famous soon enough
 



We need to see more of the code to try and figure out the problem.
eagle12 is offline  
Old 05-09-2005, 01:21 PM   #4 (permalink)
Account Closed
 
axilant's Avatar
Join Date: May 2004
Location: /etc/passwd
Posts: 2,178
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
 

Member of the Month
July 2005

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");
????: NamePros.com http://www.namepros.com/showthread.php?t=88892

$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]')"); 
????: NamePros.com http://www.namepros.com/showthread.php?t=88892
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, 03:16 PM   #5 (permalink)
Soon to be RICHdoggie!
 
PoorDoggie's Avatar
Join Date: Jan 2005
Location: UK
Posts: 2,408
PoorDoggie is just really nicePoorDoggie is just really nicePoorDoggie is just really nicePoorDoggie is just really nicePoorDoggie 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";
????: NamePros.com http://www.namepros.com/showthread.php?t=88892

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, 03:46 PM   #6 (permalink)
RJ
NamePros Webmaster


 
RJ's Avatar
Join Date: Feb 2003
Posts: 12,930
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 Parkinson's Disease
The part you posted looks fine, unixbro. Would have to see the whole script to see what's not working right.
__________________
@DomainBuyer facebook
RJ is offline  
Old 05-09-2005, 06:07 PM   #7 (permalink)
NamePros Member
Join Date: Nov 2003
Location: Ontario, Canada
Posts: 127
eagle12 will become famous soon enougheagle12 will become famous soon enough
 



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, 06:47 PM THREAD STARTER               #8 (permalink)
Account Closed
Join Date: May 2005
Posts: 62
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>

????: NamePros.com http://www.namepros.com/showthread.php?t=88892
There's the whole code still not working
unixbro-patty is offline  
Old 05-11-2005, 06:49 PM   #9 (permalink)
Account Closed
 
axilant's Avatar
Join Date: May 2004
Location: /etc/passwd
Posts: 2,178
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
 

Member of the Month
July 2005

odd, wheres the form?

PHP Code:
<?php
$db_name 
"xxxxxxx";
$username "xxxxxx";
$password "xxxxxx";
$tbl_name "xxxxxx";
????: NamePros.com http://www.namepros.com/showthread.php?t=88892
$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>";
?>
????: NamePros.com http://www.namepros.com/showthread.php?t=88892
</body>
</html>
axilant is offline  
Old 05-11-2005, 07:40 PM THREAD STARTER               #10 (permalink)
Account Closed
Join Date: May 2005
Posts: 62
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, 08:38 PM   #11 (permalink)
Account Closed
 
axilant's Avatar
Join Date: May 2004
Location: /etc/passwd
Posts: 2,178
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
 

Member of the Month
July 2005

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
????: NamePros.com http://www.namepros.com/showthread.php?t=88892

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


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

Liquid Web Smart Servers  
All times are GMT -7. The time now is 06:34 PM.

Managed Web Hosting by Liquid Web
Domain name forum recommended by Domaining.com Powered by: vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.6.0 Ad Management plugin by RedTyger