namhu Posted March 4, 2007 Share Posted March 4, 2007 Hello guys, i hope im in the right place... Im trying to link a html form to a database with php for the first time and i need some help. I created the database and the i created a html form that as an action to the next php page: /* <?PHP $username="****"; $password="****"; $database="fixusweb_Contacts"; $first=$_POST["first"]; $last=$_POST["last"]; $phone=$_POST["phone"]; $mobile=$_POST["mobile"]; $email=$_POST["email"]; $fax=$_POST["fax"]; $web=$_POST["web"]; 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_num_rows($result); mysql_close(); echo "<b><center>Database Output</center></b><br><br>"; $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"); echo "<b>$first $last</b><br>Phone: $phone<br>Mobile: $mobile<br>Fax: $fax<br>E-mail: $email<br>Web: $web<br><hr><br>"; $i++; } ?> */ the problem is that there is no output whatsoever...and the db stays the same....so i think this script its not doing nothing! Can someone help me with this problem please? PS: soz my english.. Thanks Link to comment https://forums.phpfreaks.com/topic/41102-first-time-creating-a-database/ Share on other sites More sharing options...
wildteen88 Posted March 4, 2007 Share Posted March 4, 2007 Rather than using mysql_result it better to do this: $num = mysql_num_rows($result); mysql_close(); echo "<center>Database Output <i>($num result(s) returned)</i></center><br />\n\n"; while ($row = mysql_fetch_assoc($result)) { $first = $row['first']; $last = $row['last']; $phone = $row['phone']; $mobile = $row['mobile']; $fax = $row['fax']; $email = $row['email']; $web = $row['web']; echo "Name: $first $last<br /> Phone: $phone<br /> Mobile: $mobile<br /> Fax: $fax<br /> E-mail: $email<br /> Web: $web<br />"; } mysql_fetch_assoc returns an array of each row in the result set. Much faster, cleaner an easier to understand. Link to comment https://forums.phpfreaks.com/topic/41102-first-time-creating-a-database/#findComment-199089 Share on other sites More sharing options...
namhu Posted March 4, 2007 Author Share Posted March 4, 2007 thanks for the help mate! But still...i have always 0 results when i submit something! Maybe the problem isnt the php code i dont know.. Link to comment https://forums.phpfreaks.com/topic/41102-first-time-creating-a-database/#findComment-199104 Share on other sites More sharing options...
fenway Posted March 4, 2007 Share Posted March 4, 2007 You mean no records are being returned even without a where clause? Link to comment https://forums.phpfreaks.com/topic/41102-first-time-creating-a-database/#findComment-199175 Share on other sites More sharing options...
namhu Posted March 4, 2007 Author Share Posted March 4, 2007 thats right...no records are being returned!!! Link to comment https://forums.phpfreaks.com/topic/41102-first-time-creating-a-database/#findComment-199480 Share on other sites More sharing options...
fenway Posted March 5, 2007 Share Posted March 5, 2007 Then I'm led to believe that there are no records... Link to comment https://forums.phpfreaks.com/topic/41102-first-time-creating-a-database/#findComment-199898 Share on other sites More sharing options...
wildteen88 Posted March 5, 2007 Share Posted March 5, 2007 No where in your code (that you have provided) you have an SQL query that inserts user submitted data in to your database and you don't have a WHERE clause in your query. Just a basic select all from table query. Link to comment https://forums.phpfreaks.com/topic/41102-first-time-creating-a-database/#findComment-200160 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.