[SOLVED] mySQL infomation wont submit

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

bla5e
Forum Contributor
Posts: 234
Joined: Tue May 25, 2004 4:28 pm

[SOLVED] mySQL infomation wont submit

Post by bla5e »

Code: Select all

<?php 

if (!empty($_POST['submitted']) && $_POST["submitted"] == 1){ 
error_reporting(E_ALL); 
$name = $_POST["name"]; 
$link = $_POST["url"]; 
$infomation = $_POST["infomation"]; 

$dbh=mysql_connect ("localhost", "xnetwham_cc", "pw") or die ('I cannot connect to the database because: ' . mysql_error()); 
mysql_select_db ("xnetwham_cc"); 
$sql = "SELECT * FROM links"; 
mysql_query("INSERT INTO `links` (`id`, `name`, `url`, `infomation`) VALUES ('', '$name', '$link', '$infomation')"); 
$result = mysql_query($sql, $dbh) or die (mysql_error()); 
echo mysql_error(); 
echo "Link submitted!"; 
} 

else 
{ 
//display the form 
?>

it will say "links Submitted", but it wont add it to the database.. i dont get any errors or anyhting... and i checked the datebase's


anyclue whats wrong?



(its new code)
Last edited by bla5e on Sun Jul 18, 2004 7:32 pm, edited 3 times in total.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

you have an error in your query syntax:

Code: Select all

mysql_query("INSERT INTO `roster` (`id`, `name`, `name2`, `alias`, `email`, `pos`') VALUES ('', '$name', '$name2', '$alias', '$email', '$pos')");
there's an extra single quote immediately after `pos`
User avatar
Joe
Forum Regular
Posts: 939
Joined: Sun Feb 29, 2004 1:26 pm
Location: UK - Glasgow

Post by Joe »

Code: Select all

if (!empty($_POST&#1111;'submitted']) && $_POST&#1111;"submitted"] == 1)
&#123;
error_reporting(E_ALL);
$name1 = $_POST&#1111;"name"];
$name2= $_POST&#1111;"name2"];
$alias = $_POST&#1111;"alias"];
$email = $_POST&#1111;"email"];
$pos = $_POST&#1111;"pos"];

$dbh=mysql_connect ("localhost", "xnetwham_cc", "cc") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("xnetwham_cc");

$sql = "INSERT INTO `roster` (`id`, `name`, `name2`, `alias`, `email`, `pos`) VALUES ('', '$name', '$name2', '$alias', '$email', '$pos');

$result = mysql_query($sql) or die (mysql_error());

echo "Roster Member submitted!";
bla5e
Forum Contributor
Posts: 234
Joined: Tue May 25, 2004 4:28 pm

Post by bla5e »

thanks.. simple mistakes al the time :(
bla5e
Forum Contributor
Posts: 234
Joined: Tue May 25, 2004 4:28 pm

Post by bla5e »

new code -- same problem

Code: Select all

<?php 

if (!empty($_POST['submitted']) && $_POST["submitted"] == 1){ 
error_reporting(E_ALL); 
$name = $_POST["name"]; 
$link = $_POST["url"]; 
$infomation = $_POST["infomation"]; 

$dbh=mysql_connect ("localhost", "xnetwham_cc", "pw") or die ('I cannot connect to the database because: ' . mysql_error()); 
mysql_select_db ("xnetwham_cc"); 
$sql = "SELECT * FROM links"; 
mysql_query("INSERT INTO `links` (`id`, `name`, `url`, `infomation`) VALUES ('', '$name', '$link', '$infomation')"); 
$result = mysql_query($sql, $dbh) or die (mysql_error()); 
echo mysql_error(); 
echo "Link submitted!"; 
} 

else 
{ 
//display the form 
?>
User avatar
tim
DevNet Resident
Posts: 1165
Joined: Thu Feb 12, 2004 7:19 pm
Location: ohio

Post by tim »

why do u even query the $sql? It seems you dont even use it
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

try moving the mysql_error() to the insert query's line.. like you have your connect call..
bla5e
Forum Contributor
Posts: 234
Joined: Tue May 25, 2004 4:28 pm

Post by bla5e »

tim wrote:why do u even query the $sql? It seems you dont even use it
$result = mysql_query($sql, $dbh) or die (mysql_error());
bla5e
Forum Contributor
Posts: 234
Joined: Tue May 25, 2004 4:28 pm

Post by bla5e »

feyd wrote:try moving the mysql_error() to the insert query's line.. like you have your connect call..
still no errors
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

if you echo mysql_affected_rows() after the insert, what does it say?
bla5e
Forum Contributor
Posts: 234
Joined: Tue May 25, 2004 4:28 pm

Post by bla5e »

-1Link submitted!
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

[php_man]mysql_affected_rows[/php_man] wrote:If the last query failed, this function will return -1.
so, just to make sure, you have this now?

Code: Select all

//.....
mysql_query("INSERT INTO `links` (`id`, `name`, `url`, `infomation`) VALUES ('', '$name', '$link', '$infomation')") or die(mysql_error());
//..........
bla5e
Forum Contributor
Posts: 234
Joined: Tue May 25, 2004 4:28 pm

Post by bla5e »

Notice: Undefined variable: link in linksubmit.php on line 49
Unknown column 'infomation' in 'field list'
Line 49:
mysql_query("INSERT INTO `links` (`id`, `name`, `url`, `infomation`) VALUES ('', '$name', '$link', '$infomation')") or die(mysql_error());
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

are you sure it's infomation and not information? :)
Last edited by feyd on Sun Jul 18, 2004 4:41 pm, edited 1 time in total.
bla5e
Forum Contributor
Posts: 234
Joined: Tue May 25, 2004 4:28 pm

Post by bla5e »

lol nvm-- i had infomation spelled different then in the mysql db
Post Reply