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
Post
by bla5e » Sun Jul 18, 2004 11:42 am
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.
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Sun Jul 18, 2004 11:44 am
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`
Joe
Forum Regular
Posts: 939 Joined: Sun Feb 29, 2004 1:26 pm
Location: UK - Glasgow
Post
by Joe » Sun Jul 18, 2004 11:46 am
Code: Select all
if (!empty($_POSTї'submitted']) && $_POSTї"submitted"] == 1)
{
error_reporting(E_ALL);
$name1 = $_POSTї"name"];
$name2= $_POSTї"name2"];
$alias = $_POSTї"alias"];
$email = $_POSTї"email"];
$pos = $_POSTї"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 » Sun Jul 18, 2004 12:39 pm
thanks.. simple mistakes al the time
bla5e
Forum Contributor
Posts: 234 Joined: Tue May 25, 2004 4:28 pm
Post
by bla5e » Sun Jul 18, 2004 2:58 pm
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
?>
tim
DevNet Resident
Posts: 1165 Joined: Thu Feb 12, 2004 7:19 pm
Location: ohio
Post
by tim » Sun Jul 18, 2004 3:06 pm
why do u even query the $sql? It seems you dont even use it
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Sun Jul 18, 2004 3:13 pm
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 » Sun Jul 18, 2004 4:03 pm
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 » Sun Jul 18, 2004 4:10 pm
feyd wrote: try moving the mysql_error() to the insert query's line.. like you have your connect call..
still no errors
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Sun Jul 18, 2004 4:21 pm
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 » Sun Jul 18, 2004 4:25 pm
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Sun Jul 18, 2004 4:28 pm
[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 » Sun Jul 18, 2004 4:34 pm
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());
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Sun Jul 18, 2004 4:37 pm
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 » Sun Jul 18, 2004 4:37 pm
lol nvm-- i had infomation spelled different then in the mysql db