Passing variables between pages
Posted: Fri Feb 06, 2004 4:53 am
hello !
I created an admin.php page wich is used by any admin to addusers to a mysql database. The admin.php itself seems to be nice but i have no clue how to get the fields added into the database. The first part of the page shows the LOGIN table and the second part is a form to add users.
What i do here is i refer the form action to test.php that adds a new row to the database.
My problem is i dunno how to get the "name" and "password" fields passed throught test.php so $name and $password will be defined on test.php
Is this the right way to do it or could i do something shorter without test.php ?
Thanks,
Francis
-----admin.php-----
<?php require_once('Connections/PretimeDB.php'); ?>
<?php
mysql_select_db($database_PretimeDB, $PretimeDB);
$query_pretime = "SELECT * FROM logins";
$pretime = mysql_query($query_pretime, $PretimeDB) or die(mysql_error());
$row_pretime = mysql_fetch_assoc($pretime);
$totalRows_pretime = mysql_num_rows($pretime);
?>
<body>
<?php do { ?>
<tr>
<td><div align="center"><font face="Verdana, Arial, Helvetica, sans-serif"><?php echo $row_pretime['username']; ?></font></div></td>
<td><div align="center"><font face="Verdana, Arial, Helvetica, sans-serif"><?php echo $row_pretime['password']; ?></font></div></td>
</tr>
<?php } while ($row_pretime = mysql_fetch_assoc($pretime)); ?>
</table>
<p> </p>
<form name="form1" method="post" action="test.php">
<table width="75%" border="0" align="center">
<tr>
<td colspan="2"><div align="center"><img src="img_03.gif" width="400" height="20"></div></td>
</tr>
<tr>
<td><div align="center"><font color="#0000A0" face="Verdana, Arial, Helvetica, sans-serif">USERNAME</font></div></td>
<td><div align="center"><font color="#0000A0" face="Verdana, Arial, Helvetica, sans-serif">PASSWORD</font></div></td>
</tr>
<tr>
<td><div align="center">
<input name="name" type="text" id="name">
</div></td>
<td><div align="center">
<input name="password" type="text" id="password">
</div></td>
</tr>
</table>
<div align="center">
<input type="submit" name="submit" value="submit">
<br>
</div>
</form>
<p> </p>
</body>
</html>
<?php
mysql_free_result($pretime);
?>
-----test.php-----
<?php require_once('Connections/PretimeDB.php'); ?>
<?php
if ( isset( $_GET['name'] ) )
if ( isset( $_GET['password'] ) )
?>
<?php
mysql_select_db($database_PretimeDB, $PretimeDB);
$query = "INSERT INTO logins (username,password) VALUES ('$name','$password')";
$result = mysql_query("INSERT INTO logins (username,password) VALUES ('$name','$password')") or die("Query failed : " . mysql_error());
?>
I created an admin.php page wich is used by any admin to addusers to a mysql database. The admin.php itself seems to be nice but i have no clue how to get the fields added into the database. The first part of the page shows the LOGIN table and the second part is a form to add users.
What i do here is i refer the form action to test.php that adds a new row to the database.
My problem is i dunno how to get the "name" and "password" fields passed throught test.php so $name and $password will be defined on test.php
Is this the right way to do it or could i do something shorter without test.php ?
Thanks,
Francis
-----admin.php-----
<?php require_once('Connections/PretimeDB.php'); ?>
<?php
mysql_select_db($database_PretimeDB, $PretimeDB);
$query_pretime = "SELECT * FROM logins";
$pretime = mysql_query($query_pretime, $PretimeDB) or die(mysql_error());
$row_pretime = mysql_fetch_assoc($pretime);
$totalRows_pretime = mysql_num_rows($pretime);
?>
<body>
<?php do { ?>
<tr>
<td><div align="center"><font face="Verdana, Arial, Helvetica, sans-serif"><?php echo $row_pretime['username']; ?></font></div></td>
<td><div align="center"><font face="Verdana, Arial, Helvetica, sans-serif"><?php echo $row_pretime['password']; ?></font></div></td>
</tr>
<?php } while ($row_pretime = mysql_fetch_assoc($pretime)); ?>
</table>
<p> </p>
<form name="form1" method="post" action="test.php">
<table width="75%" border="0" align="center">
<tr>
<td colspan="2"><div align="center"><img src="img_03.gif" width="400" height="20"></div></td>
</tr>
<tr>
<td><div align="center"><font color="#0000A0" face="Verdana, Arial, Helvetica, sans-serif">USERNAME</font></div></td>
<td><div align="center"><font color="#0000A0" face="Verdana, Arial, Helvetica, sans-serif">PASSWORD</font></div></td>
</tr>
<tr>
<td><div align="center">
<input name="name" type="text" id="name">
</div></td>
<td><div align="center">
<input name="password" type="text" id="password">
</div></td>
</tr>
</table>
<div align="center">
<input type="submit" name="submit" value="submit">
<br>
</div>
</form>
<p> </p>
</body>
</html>
<?php
mysql_free_result($pretime);
?>
-----test.php-----
<?php require_once('Connections/PretimeDB.php'); ?>
<?php
if ( isset( $_GET['name'] ) )
if ( isset( $_GET['password'] ) )
?>
<?php
mysql_select_db($database_PretimeDB, $PretimeDB);
$query = "INSERT INTO logins (username,password) VALUES ('$name','$password')";
$result = mysql_query("INSERT INTO logins (username,password) VALUES ('$name','$password')") or die("Query failed : " . mysql_error());
?>