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());
?>
Passing variables between pages
Moderator: General Moderators
-
Straterra
- Forum Regular
- Posts: 527
- Joined: Mon Nov 24, 2003 8:46 am
- Location: Indianapolis, Indiana
- Contact:
Re: Passing variables between pages
Just put it all in PHP syntax...skaber wrote: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-----Code: Select all
<?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-----Code: Select all
<?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()); ?>
-
Straterra
- Forum Regular
- Posts: 527
- Joined: Mon Nov 24, 2003 8:46 am
- Location: Indianapolis, Indiana
- Contact:
admin.php
This above code was such badly written, that I have NO CLUE what you are wanting to do with the while statement..Now, onto the test.php
test.php
And why are you adding the exact same things twice??
I would STRONGLY recommend you rewrite the entire script.
Code: Select all
<?php
require_once('Connections/PretimeDB.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>
<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
Code: Select all
<?php
require_once('Connections/PretimeDB.php');
if ( isset($_GET['name']) == true and isset($_GET['password']) == true ) {
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 would STRONGLY recommend you rewrite the entire script.
-
Illusionist
- Forum Regular
- Posts: 903
- Joined: Mon Jan 12, 2004 9:32 pm
he is not adding the same thing twice. He has it the same thing typed out twice, but he isn't adding it twice...
could just be:
Code: Select all
<?php
require_once('Connections/PretimeDB.php');
if ( isset($_GET['name']) == true and isset($_GET['password']) == true ) {
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());
?>Code: Select all
<?php
require_once('Connections/PretimeDB.php');
if ( isset($_GET['name']) == true and isset($_GET['password']) == true ) {
mysql_select_db($database_PretimeDB, $PretimeDB);
$query = "INSERT INTO logins (username,password) VALUES ('$name','$password')";
$result = mysql_query($query) or die("Query failed : " . mysql_error());
?>still no good
yea, you were right, i had typed in twice the same command. i modifed the admin.php to set <form action="test.php"> and i changed the test.php page has fallow:
<?php
require_once('Connections/PretimeDB.php');
if ( isset($_GET['name']) == true and isset($_GET['password']) == true ) {
mysql_select_db($database_PretimeDB, $PretimeDB);
$query = "INSERT INTO logins (username,password) VALUES ('$name','$password')";
$result = mysql_query($query) or die("Query failed : " . mysql_error());
echo "$name $password";
}
?>
i added the echo "$name $password" to see if the command would be executed. Seems like all what is between the brackets isnt getting executed.
any idea ?
<?php
require_once('Connections/PretimeDB.php');
if ( isset($_GET['name']) == true and isset($_GET['password']) == true ) {
mysql_select_db($database_PretimeDB, $PretimeDB);
$query = "INSERT INTO logins (username,password) VALUES ('$name','$password')";
$result = mysql_query($query) or die("Query failed : " . mysql_error());
echo "$name $password";
}
?>
i added the echo "$name $password" to see if the command would be executed. Seems like all what is between the brackets isnt getting executed.
any idea ?