|
|
|
|
Thread title: SQL Not working |
|
|
|
|
|
Thread tools
Search this thread
Display Modes
|
|
10-21-2006, 09:34 PM
|
#1
|
Status: Dediport Hosting
Join date: Jul 2006
Location: Berkshire
Expertise: programming, business
Software: Dreamweaver
Posts: 1,316
|
SQL Not working
Hi,
I have the code below and it doesnt seem to be inserting anything into the db, Could anyone help and is tehre a way to make sure that it has entered correctly without selecting?
Steven
PHP Code:
<!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=iso-8859-1" /> <title>New Admin</title> <link type="text/css" rel="stylesheet" href="style.css" /> </head>
<body> <?php include_once('connect.php');
if (empty($_POST['submit'])) { } else { if (empty($_POST['name']) || empty($_POST['pass'])) { echo "<div class=\"text\">Please fill in all fields.</div>"; } else { $name = stripcslashes($_POST['name']); $pass = stripcslashes($_POST['pass']); $permission = '1'; $fpass = md5($pass); $ip = $_SERVER['REMOTE_ADDR']; $query = mysql_query("INSERT INTO users (`username` , `password` , `permissions` , `ip`) VALUES ('$name', '$fpass', '$permission', '$ip'"); if (isset($query)) { echo "<div class=\"text\">User successfully added.</div>"; } } } ?><div class="text"> Enter the details for the new admin below. <br /><br /> <form name="newuser" method="POST" action="newadmin.php"> Username: <input type="text" name="name" /><br /><br /> Password: <input type="password" name="pass" /><br /><br /> <input type="submit" name="submit" value="Add user" /> </form></div> </body> </html>
|
|
10-21-2006, 10:10 PM
|
#2
|
Status: design rockstar
Join date: Jan 2005
Location: guelph, ontario
Expertise:
Software:
Posts: 2,246
|
well you never actually tell it to write to the databse, you're just storing the query in the $query variable. you need to add mysql_query($query).
PHP Code:
<?php
if(isset($_POST['submit'])) {
if (empty($_POST['name']) || empty($_POST['pass'])) {
echo "<div class=\"text\">Please fill in all fields.</div>";
exit();
} else {
$name = stripcslashes($_POST['name']);
$pass = stripcslashes($_POST['pass']);
$permission = '1';
$fpass = md5($pass);
$ip = $_SERVER['REMOTE_ADDR'];
$query = mysql_query("INSERT INTO users (`username` , `password` , `permissions` , `ip`) VALUES ('$name', '$fpass', '$permission', '$ip'");
if (mysql_query($query)) {
echo "<div class=\"text\">User successfully added.</div>";
} else {
echo "div class=\"text"\>User was not added, please check your code<./div>";
}
}
}
?>
|
|
10-22-2006, 05:08 AM
|
#3
|
Status: Dediport Hosting
Join date: Jul 2006
Location: Berkshire
Expertise: programming, business
Software: Dreamweaver
Posts: 1,316
|
Its not making the user now...
|
|
10-22-2006, 01:01 PM
|
#4
|
Status: Member
Join date: May 2006
Location:
Expertise:
Software:
Posts: 119
|
*sigh* Change it to this:
PHP Code:
$query = mysql_query("INSERT INTO users (`username` , `password` , `permissions` , `ip`) VALUES ('$name', '$fpass', '$permission', '$ip'") or die(mysql_error());
|
|
10-22-2006, 01:49 PM
|
#5
|
Status: design rockstar
Join date: Jan 2005
Location: guelph, ontario
Expertise:
Software:
Posts: 2,246
|
$query should just equal the string, it doesn't need mysql_query in there.
PHP Code:
$query = "INSERT INTO users (username , password , permissions , ip) VALUES ('$name', '$fpass', '$permission', '$ip')";
|
|
10-22-2006, 02:57 PM
|
#6
|
Status: Request a custom title
Join date: Dec 2005
Location: Arizona
Expertise:
Software:
Posts: 5,200
|
Originally Posted by derek lapp
$query should just equal the string, it doesn't need mysql_query in there.
PHP Code:
$query = "INSERT INTO users (username , password , permissions , ip) VALUES ('$name', '$fpass', '$permission', '$ip')";
|
Yup, because otherwise you guys would be using mysql_query twice.
|
|
10-22-2006, 03:51 PM
|
#7
|
Status: Dediport Hosting
Join date: Jul 2006
Location: Berkshire
Expertise: programming, business
Software: Dreamweaver
Posts: 1,316
|
Yehm Sorry i didnt post i fixed about 5 minutes after the second post i made.
|
|
|
|
|
|
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
Thread Tools |
|
Display Modes |
Linear Mode
|
|
|