Can't display from MySQL!<

liunx

Guest
Hi, I'm making a database of all the staff for my website. I can get the ID# to dislay properly, but I can't get anything else to display. I have set upo my database with a table called staff, and with rows: ID, email, username, and password. Here is the code of how the data is added (through a form)



<?PHP


//MySQL Variables. Edit where necessary
$host = "_____";
$login_name = "_____";
$password = "_____";

//Connecting to MYSQL
MySQL_connect("$host","$login_name","$password");



//select db

MySQL_select_db("admin_db") or die("Could not select database");


$sql = "INSERT staff SET username='$username', password='$pass', email='$email'";


//Send query

if ( mysql_query($sql)) {
echo ("Data added Sucessfully");
}ELSE {
echo ("Error adding data");
}

//close connection

MySQL_close()

?>


I believe everything okay in this script, because I didn't get any errors. Heres the script for the display page:



<?PHP

//MySQL Variables
$host = "_____";
$login_name = "_____";
$password = "_____";

//Connecting to MYSQL
MySQL_connect("$host","$login_name","$password") or die("could not connect to database");

//select db
MySQL_select_db("admin_db") or die("Could not select database");

//output table with staff info
$query = mysql_query("SELECT * FROM staff");
echo"<table cellpadding='2' cellspacing='2' border='1' style='border: collapse'>";
echo"<tr>";
echo"<td>";
echo"ID #";
echo"</td>";
echo"<TD>";
echo"Username";
echo"</td>";
echo"<td>";
echo"E-mail";
echo"</td>";
echo"</tr>";
echo"<tr>";
WHILE($row=mysql_fetch_array($query) ){
echo"<td>{$row['ID']}</td>";
echo"<td>{$row['username']}</td>";
echo"<td>{$row['email']}</td></tr><tr>";
}
echo"</td></tr></table>";

//close connection
MySQL_close();


?>



The output I get is the table, but only the ID column is displaying, nothing else. Any help would be appreciated.

Thanksdid you look at the source of the result page?
do you have a link for us?

maybe try this...
(put the <tr></tr> inside the loop)

//output table with staff info
$query = mysql_query('SELECT * FROM staff') or exit(mysql_error());
echo '<table cellpadding="2" cellspacing="2" border="1" style="border: collapse;">
<tr>
<td>ID #</td>
<td>Username</td>
<td>E-mail</td>
</tr>';
WHILE ($row=mysql_fetch_array($query)) {
echo "<tr>
<td>{$row['ID']}</td>
<td>{$row['username']}</td>
<td>{$row['email']}</td></tr>
<tr>";
}
echo '</table>';Unfortunatley, that didn't work. I have uploaded the scripts so you can see them.


Add data page: <!-- m --><a class="postlink" href="http://hylarch4.t35.com/form.html">http://hylarch4.t35.com/form.html</a><!-- m -->
Display Page: <!-- m --><a class="postlink" href="http://hylarch4.t35.com/display.phpfor">http://hylarch4.t35.com/display.phpfor</a><!-- m --> one your insert is wrong, you can't use SET in an insert, that is for updates.

$sql = "INSERT into staff (username, password, email) VALUES ('$username','$pass','$email') ";look again

i add test/test to the form page and it appear on the result page...Originally posted by scoutt
for one your insert is wrong, you can't use SET in an insert, that is for updates.

$sql = "INSERT into staff (username, password, email) VALUES ('$username','$pass','$email') ";

yes you can!!really !!!!
<!-- m --><a class="postlink" href="http://www.mysql.com/doc/en/INSERT.html">http://www.mysql.com/doc/en/INSERT.html</a><!-- m -->

still have to use

INSERT into which he is not.What I believe the problem is, is that you have to enter the same data for the text to be displayed. Any ideas?i try with mozilla
username test1
password test2
email test3

and with explorer
username test4
password test5
email test6

and both are in the list!I took out some code in the make tables, and re-did some stuff, I forget what I did, but I now know that it works. Thanks for the help guys/gals!why in the world would you have a form to enter a password just so it can go through the url for everybody to seeJust experimenting, I'll change that when my final version goes up next week.
 
Back
Top