how all,
hope every 1 here ok,
now have form admin can create users , can delete users let me display code first
this code
> > <?php error_reporting(e_all); > > session_start(); > if(!isset($_session['login']) || > $_session['login']!='1' ) { > header("location:loginpage.php"); > } ?> > > <!doctype html public "-//w3c//dtd > xhtml 1.0 transitional//en" > "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd"> > <html > xmlns="http://www.w3.org/1999/xhtml"> > <head> <meta http-equiv="content-type" > content="text/html; charset=utf-8" /> > <title>my control panel</title> <link > href="../css_style.css" > rel="stylesheet" type="text/css" /> > </head> > > > > <body> <div id="werpper"> <div > id="content"> > > <div id="header">my control - > panel</div> <div id="body_cntent"> > <div id="left_side"> <p>home , > instructions</p> <p><a > href="../control_panel.php">main > directory</a></p> <p><a > href="add_event.php">add new > event</a></p> <p><a > href="../editoccasion.php">control > occasion's</a></p> <p><a > href="add_photos_and_occasion.php">add > photos_occasion</a></p> <p><a > href="../signout.php">sign out</a></p> > </div> <div id="right_side"> > > <h2>add new user</h2> > > <form action="" method="post"> > > <table width="600" border="0" > cellpadding="5" cellspacing="0"> > <tr> > <td width="78">user name</td> > <td width="2"> </td> > <td width="149"><input type="text" name="uname" value="" /></td> > <td width="332" rowspan="5" align="left" valign="top"><p > class="red">for administration use > only.</p> > <p>you can add or delete users <a > href="edit_users.php">here</a><br /> > can't edit user if change user account > can delete user , create > again new > information.</p></td> </tr> <tr> > <td>password</td> > <td> </td> > <td><input type="text" name="pass" value="" /></td> > </tr> <tr> > <td> </td> > <td> </td> > <td><input type="submit" name="submit" value="add user" /></td> > </tr> <tr> > <td> </td> > <td> </td> > <td> </td> > </tr> <tr> > <td> </td> > <td> </td> > <td align="right"> </td> > </tr> </table> </form> > > </div> </div> > > <div id="footer"></div> </div> </div> > > <?php > if (isset($_post['submit'])) { > include_once "../config/config.php"; > $uname = $_post['uname']; $pass =$_post['pass']; > $check = "select * users id = {$uname}"; $result_check > = $db->query($check)or die($db->error); > > while ($row = $result_check -> fetch_object()) { > if(num_rows == 1){ > > echo "error"; > > }else{ > $add_user = "insert users (id, uname, pass) values ('', > '$uname', '$pass')"; > $result = $db -> query($add_user) or die ("$db->error"); > if ($result) { > echo "user added successfuly"; > }else{ > > echo "there error please try again later"; > > } } } } ?> > > </body> </html>
all need here know how solve problem of code
$check = "select * users id = {$uname}"; $result_check = $db->query($check)or die($db->error); while ($row = $result_check -> fetch_object()) { if(num_rows == 1){ echo "error"; }
how can avoid duplication users in db
i'm not sure database library you're using , methods are, made plain mysql if went route of making uname
(username) field unique index
--
// instantiate database connection $db = mysql_connect( .. ); // assuming id field auto incrementing, can left out of query $add_user = "insert users (uname, pass) "; $add_user .= "values ('" . mysql_real_escape_string($uname) . "', "; $add_user .= "'" . mysql_real_escape_string($pass) . "')"; if (mysql_query($add_user, $db)) { if (mysql_affected_rows($db) == 1) { // new user added, } } else { if (mysql_errno($db) == 1062) { // duplicate username, } else { // different database error occurred die('error: ' . mysql_error()); } }
Comments
Post a Comment