Benaravo Posted January 14, 2007 Share Posted January 14, 2007 Hey,I'm having a few problems with a script I made... Basically, it is going to be an add user script, which uses SQL.The problem I'm having at the moment is that when I complete the form, it does not complete the script by adding the user, it merely returns to the form input section :-\I've looked through the script quite a lot, and couldn't see anything... But thought I'd post it here to see if you guys can see anything...[code]<body><?php$self = $_SERVER['PHP_SELF'];$user = $_POST['user'];$pwd = $_POST['pass'];$name = $_POST['name'];$admin = $_POST['admin'];?><form action="<?php echo( $self ); ?>" method="get"> <label>User Name <input type="text" name="user" /> <br /> </label> <Label>Password <input type="password" name="pass" /> </Label> <Label><br /> Name <input type="text" name="name" /> <br /> </Label> <label>Account Status <input type="text" name="admin" /> </label> <p><input type="submit" Value="Add User" /> </br> </p></form><?phpif( $admin and $user and $pwd and $name ){$conn= @mysql_connect( "My","SQL","Details" )or die( "Err:Conn" );$rs = @mysql_select_db( "ben_forum", $conn )or die( "Err:Db" );$sql="insert into users (username, password, name, admin)values ( $user, \"$pwd \", \"$name\", \"$name\", \"$admin\" )";$rs = mysql_query( $sql, $conn );if($rs){ echo( "Record added: Username: {$user}, With Password: {$pwd}, For: {$name}, And Is The Status Of: {$admin}." ); }}?></body>[/code] Link to comment https://forums.phpfreaks.com/topic/34155-problems-adding-users-php-newbie/ Share on other sites More sharing options...
Orio Posted January 14, 2007 Share Posted January 14, 2007 [code]<body><?php$self = $_SERVER['PHP_SELF'];if(isset($_POST['submit'])){ $user = $_POST['user']; $pwd = $_POST['pass']; $name = $_POST['name']; $admin = $_POST['admin'];}?><form action="<?php echo( $self ); ?>" method="get"> <label>User Name <input type="text" name="user" /> <br /> </label> <Label>Password <input type="password" name="pass" /> </Label> <Label><br /> Name <input type="text" name="name" /> <br /> </Label> <label>Account Status <input type="text" name="admin" /> </label> <p><input type="submit" Value="Add User" name="submit" /> </br> </p></form><?phpif(isset($_POST['submit'])){$conn= @mysql_connect( "My","SQL","Details" )or die( "Err:Conn" );$rs = @mysql_select_db( "ben_forum", $conn )or die( "Err:Db" );$sql="insert into users (username, password, name, admin)values ( $user, \"$pwd \", \"$name\", \"$name\", \"$admin\" )";$rs = mysql_query( $sql, $conn );if($rs){ echo( "Record added: Username: {$user}, With Password: {$pwd}, For: {$name}, And Is The Status Of: {$admin}." ); }}?></body>[/code]I changed three things- I added a condition in the beginning of the code, I added the submit button a name and I changed the condition in the second part.Should work. Get used to the isset($_POST['submit']) - it's a good way to deal with self pointing forms.Orio. Link to comment https://forums.phpfreaks.com/topic/34155-problems-adding-users-php-newbie/#findComment-160663 Share on other sites More sharing options...
Benaravo Posted January 14, 2007 Author Share Posted January 14, 2007 Unfortienetly, this hasn't sorted the problem :( I think it might be some kind of missing ';' or } It's driving me mad! It may even be some thing to do with the database connection strings ???Sorry about being quite so new to PHP; only wish I knew more!THanks,Ben.[quote author=Orio link=topic=122374.msg504712#msg504712 date=1168803411][code]<body><?php$self = $_SERVER['PHP_SELF'];if(isset($_POST['submit'])){ $user = $_POST['user']; $pwd = $_POST['pass']; $name = $_POST['name']; $admin = $_POST['admin'];}?><form action="<?php echo( $self ); ?>" method="get"> <label>User Name <input type="text" name="user" /> <br /> </label> <Label>Password <input type="password" name="pass" /> </Label> <Label><br /> Name <input type="text" name="name" /> <br /> </Label> <label>Account Status <input type="text" name="admin" /> </label> <p><input type="submit" Value="Add User" name="submit" /> </br> </p></form><?phpif(isset($_POST['submit'])){$conn= @mysql_connect( "My","SQL","Details" )or die( "Err:Conn" );$rs = @mysql_select_db( "ben_forum", $conn )or die( "Err:Db" );$sql="insert into users (username, password, name, admin)values ( $user, \"$pwd \", \"$name\", \"$name\", \"$admin\" )";$rs = mysql_query( $sql, $conn );if($rs){ echo( "Record added: Username: {$user}, With Password: {$pwd}, For: {$name}, And Is The Status Of: {$admin}." ); }}?></body>[/code]I changed three things- I added a condition in the beginning of the code, I added the submit button a name and I changed the condition in the second part.Should work. Get used to the isset($_POST['submit']) - it's a good way to deal with self pointing forms.Orio.[/quote] Link to comment https://forums.phpfreaks.com/topic/34155-problems-adding-users-php-newbie/#findComment-160760 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.