Page 1 of 2
conection to database and displaying data
Posted: Sun May 28, 2006 9:41 am
by franknu
feyd | Please use Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
i have tons of problems conecting to database, i buit the database on adminpphp
i want to be able to display and add to the database this is the data but i been trying for weeks and nothing seems to work
Code: Select all
<?
$username="localhost";
$password="abc123";
$database="contacts";
$db = mysql_connect("localhost", $username,$password);
mysql_select_db("contacts",$db);
$result = mysql_query("SELECT * FROM First Name",$db);
$myvar = "Hello World";
echo ("$myvar");
echo "(Position: %s<br>\n", mysql_result($result,0,"Position"));
echo ("date,("m/d/y")");
?>
i get diffrent messages whenever i change this but mostly it say it a
" Parse error:" i think i am not conecting to the database because i gotten that message too sometimes
please can someone help me
feyd | Please use Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Posted: Sun May 28, 2006 9:46 am
by feyd
check the position of one of the opening parens.
Posted: Sun May 28, 2006 9:49 am
by Chris Corbyn
Code: Select all
echo "(Position: %s<br>\n", mysql_result($result,0,"Position"));
That's wrong. What's the comma? Looks like you wanted
printf()
Code: Select all
printf("Position: %s<br>\n", mysql_result($result,0,"Position"));
Posted: Sun May 28, 2006 10:44 am
by franknu
I am still gettin the same messageL:
This are the changes that i made
<html>
<head>
<title>Hello!</title>
</head>
<body>
<?php
$username="localhost";
$password="abc123";
$database="contacts";
$db = mysql_connect("localhost", $username,$password);
mysql_select_db("contacts",$db);
$result = mysql_query("SELECT * FROM First Name",$db);
$myvar = "Hello World";
echo ("$myvar");
printf("Position: %s<br>\n", mysql_result($result,0,"Position"));
printf ("date,("m/d/y")");
?>
</body>
</html>
message that is displaying
Parse error: parse error in /home/httpd/vhosts/mass-ad.com/httpdocs/test11.php on line 39
thank u guys( i want to be abloe to take care of this on this weekend
Posted: Sun May 28, 2006 10:50 am
by Chris Corbyn
What are you trying to do with that last printf() ? You have just paut the date() function inside it in a string which won't work
It should just be:
By the way, we have
Posted: Sun May 28, 2006 10:58 am
by franknu
ok, now when i add the "f" to print i get this
Hello World
Warning: Supplied argument is not a valid MySQL result resource in /home/httpd/vhosts/mass-ad.com/httpdocs/test11.php on line 28
Position
when i remove the f get this error message
Parse error: parse error in /home/httpd/vhosts/mass-ad.com/httpdocs/test11.php on line 28
this is the code
Code: Select all
<?php
$username="localhost";
$password="abc123";
$database="contacts";
$db = mysql_connect("localhost", $username,$password);
mysql_select_db("contacts",$db);
$result = mysql_query("SELECT * FROM First Name",$db);
$myvar = "Hello World";
printf("$myvar");
printf("Position: %s<br>\n", mysql_result($result,0,"Position"));
date('d/m/Y');
?>
</body>
</html>
Posted: Sun May 28, 2006 11:09 am
by Chris Corbyn
Your query has a space in it after the "FROM" clause. That's not valid.
Note: You should really put a call to mysql_error() when you run queries for debugging:
Code: Select all
$result = mysql_query("SELECT * FROM First Name",$db) or die(mysql_error());
Fix the query first though.
Posted: Sun May 28, 2006 11:45 am
by franknu
i am getting this message now; i have data inside the database, i dont have a table call contacts.First, i have a table call First Name what should do this is driving me crazy
Table 'contacts.First' doesn't exist
these are the codes
Code: Select all
<html>
<head>
<title>Hello!</title>
</head>
<body>
<?php
$username="localhost";
$password="abc123";
$database="contacts";
$db = mysql_connect("localhost", $username,$password);
mysql_select_db("contacts",$db);
$result = mysql_query("SELECT * FROM First Name",$db) or die(mysql_error());
$myvar = "Hello World";
printf("$myvar");
printf("Position: %s<br>\n", mysql_result($result,0,"Position"));
date('d/m/Y');
?>
</body>
</html>
Thank u
Posted: Sun May 28, 2006 11:51 am
by Chris Corbyn
Read my last post again because you haven't even done the major thing I mentioned. The errors are very descriptive.
What's your database table structure? What table are you trying to select from? What are you attempting to acheive?
EDIT | And can you start using the
Code: Select all
[ /php] tags please? I'm not going to keep editting your posts for you
Posted: Sun May 28, 2006 11:55 am
by Chris Corbyn
If your table really is called "First Name" use backticks to surround it. But why on earth would you have a whole table for First names? Would that not just be a column in another table?
Posted: Sun May 28, 2006 1:00 pm
by franknu
ok, i got almost everything u guys said i think i almost got it by the horn,
i did php and sql like 3 years last time so i lost it, guys, but i will get back in track,
this is the message i am getting now...
Hello World
Warning: Unable to jump to row 0 on MySQL result index 2 in /home/httpd/vhosts/mass-ad.com/httpdocs/test11.php on line 28
Position:
and this are the codes
<html>
<head>
<title>Hello!</title>
</head>
<body>
<?php
$username="localhost";
$password="abc123";
$database="contacts";
$db = mysql_connect("localhost", $username,$password);
mysql_select_db("contacts",$db);
$result = mysql_query("SELECT * FROM `First Name:`WHERE `Position:`",$db) or die(mysql_error());
$myvar= "Hello World";
printf("$myvar");
printf("Position: %s<br>\n", mysql_result($result,0,"Position"));
date('d/m/Y');
?>
</body>
</html>
Thank for all ur help
Posted: Sun May 28, 2006 1:08 pm
by Chris Corbyn
For the third time, use Code: Select all
tags.[/color]
No results were returned from the query... mysql_num_rows() can check that.
Posted: Sun May 28, 2006 2:49 pm
by franknu
Jcart | Please use Code: Select all
tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
well, this is?
Hello World
Warning: Unable to jump to row 0 on MySQL result index 2 in /home/httpd/vhosts/mass-ad.com/httpdocs/test11.php on line 28
Position
i have data inside the database so please tell me what else could be wrong,,
Code: Select all
<head>
<title>Hello!</title>
</head>
<body>
<?
$username="localhost";
$password="abc123";
$database="contacts";
$db = mysql_connect("localhost", $username,$password);
mysql_select_db("contacts",$db);
$result = mysql_query("SELECT * FROM `First Name:` WHERE `Position:`",$db) or die(mysql_error());
$myvar= "Hello World";
printf("$myvar");
printf("Position: %s<br>\n", mysql_result($result,0,"Position:"));
?>
</body>
</html>
all i want is to display the data that the colum name in postion is holding
thank u so much becuase progress had been made
Jcart | Please use Code: Select all
tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Posted: Sun May 28, 2006 2:54 pm
by John Cartwright
for the last time use our forum's php tags.. a lack of doing so usually results in people ignoring your thread because you cannot make the effort of helping us help you.

Your call.
Posted: Sun May 28, 2006 3:15 pm
by franknu
what are this <?php
scripts
?>
HTML tags
went tp the tags and it had something like this
when i added it just make it worst
maybe i a m not understanding, what u are saying