Today's Posts Follow Us On Twitter! TFL Members on Twitter  
Forum search: Advanced Search  
Navigation
Marketplace
  Members Login:
Lost password?
  Forum Statistics:
Forum Members: 24,254
Total Threads: 80,792
Total Posts: 566,472
There are 2060 users currently browsing (tf).
 
  Our Partners:
 
  TalkFreelance     Design and Development     Programming     PHP and MySQL :

php and mySQL

Thread title: php and mySQL
     
    Thread tools Search this thread Display Modes  
Prev Previous Post   Next Post Next
04-02-2007, 04:33 PM
#1
ali.black is offline ali.black
Status: I'm new around here
Join date: Feb 2007
Location:
Expertise:
Software:
 
Posts: 13
iTrader: 0 / 0%
 

ali.black is on a distinguished road

  Old  php and mySQL

hello, i found this tutorial on the net and i thought id give it a go because i have just started learning this stuff. the problem is when i input the info it seems to be ok but when i go to index.php new rows have been created but the info i inputted isnt displayed. could you please have a look at the code to see if there is a problem because i dont know what to look for. cheers.

dbinfo.inc.php(to connect to the database):

PHP Code:
<?
$username
="name";
$password="pw";
$database="db";
?>
add.html(to input the data)

HTML Code:
<form action="insert.php" method="post">
First Name: <input type="text" name="first"><br>
Last Name: <input type="text" name="last"><br>
Phone: <input type="text" name="phone"><br>
Mobile: <input type="text" name="mobile"><br>
Fax: <input type="text" name="fax"><br>
E-mail: <input type="text" name="email"><br>
Web: <input type="text" name="web"><br>
<input type="Submit">
</form>
insert.php(to insert the info into the database):

PHP Code:
<?
include("dbinfo.inc.php");
mysql_connect(localhost,$username,$password);
@
mysql_select_db($database) or die( "Unable to select database"); 

$query "INSERT INTO contacts VALUES ('','$first','$last','$phone','$mobile','$fax','$email','$web')";
mysql_query($query);

mysql_close();
?>
index.php (to display it):

PHP Code:
<?
include("dbinfo.inc.php");
mysql_connect(localhost,$username,$password);
@
mysql_select_db($database) or die( "Unable to select database");
$query="SELECT * FROM contacts";
$result=mysql_query($query);

$num=mysql_numrows($result); 

mysql_close();

echo 
"<b><center>Database Output</center></b><br><br>";

?>
<table border="0" cellspacing="2" cellpadding="2">
<tr> 
<th><font face="Arial, Helvetica, sans-serif">Name</font></th>
<th><font face="Arial, Helvetica, sans-serif">Phone</font></th>
<th><font face="Arial, Helvetica, sans-serif">Mobile</font></th>
<th><font face="Arial, Helvetica, sans-serif">Fax</font></th>
<th><font face="Arial, Helvetica, sans-serif">E-mail</font></th>
<th><font face="Arial, Helvetica, sans-serif">Website</font></th>
</tr>

<?
$i
=0;
while (
$i $num) {
$first=mysql_result($result,$i,"first");
$last=mysql_result($result,$i,"last");
$phone=mysql_result($result,$i,"phone");
$mobile=mysql_result($result,$i,"mobile");
$fax=mysql_result($result,$i,"fax");
$email=mysql_result($result,$i,"email");
$web=mysql_result($result,$i,"web"); 
?>

<tr> 
<td><font face="Arial, Helvetica, sans-serif"><? echo "$first $last"?></font></td>
<td><font face="Arial, Helvetica, sans-serif"><? echo "$phone"?></font></td>
<td><font face="Arial, Helvetica, sans-serif"><? echo "$mobile"?></font></td>
<td><font face="Arial, Helvetica, sans-serif"><? echo "$fax"?></font></td>
<td><font face="Arial, Helvetica, sans-serif"><a href="mailto:<? echo "$email"?>">E-mail</a></font></td>
<td><font face="Arial, Helvetica, sans-serif"><a href="<? echo "$web"?>">Website</a></font></td>
</tr>
<?
++$i;

echo 
"</table>";


?>

     


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

  Posting Rules  
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump:
 
  Contains New Posts Forum Contains New Posts   Contains No New Posts Forum Contains No New Posts   A Closed Forum Forum is Closed