Today's Posts Follow Us On Twitter! TFL Members on Twitter  
Forum search: Advanced Search  
Navigation
Marketplace
  Members Login:
Lost password?
  Forum Statistics:
Forum Members: 24,254
Total Threads: 80,792
Total Posts: 566,472
There are 2220 users currently browsing (tf).
 
  Our Partners:
 
  TalkFreelance     Design and Development     Programming     PHP and MySQL :

SQL Not working

Thread title: SQL Not working
Closed Thread    
    Thread tools Search this thread Display Modes  
10-21-2006, 09:34 PM
#1
localhost is offline localhost
localhost's Avatar
Status: Dediport Hosting
Join date: Jul 2006
Location: Berkshire
Expertise: programming, business
Software: Dreamweaver
 
Posts: 1,316
iTrader: 17 / 100%
 

localhost is on a distinguished road

  Old  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
derek lapp is offline derek lapp
Status: design rockstar
Join date: Jan 2005
Location: guelph, ontario
Expertise:
Software:
 
Posts: 2,246
iTrader: 0 / 0%
 

derek lapp is on a distinguished road

  Old

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 addedplease check your code<./div>";
            }
    }
}
?>

10-22-2006, 05:08 AM
#3
localhost is offline localhost
localhost's Avatar
Status: Dediport Hosting
Join date: Jul 2006
Location: Berkshire
Expertise: programming, business
Software: Dreamweaver
 
Posts: 1,316
iTrader: 17 / 100%
 

localhost is on a distinguished road

  Old

Its not making the user now...

10-22-2006, 01:01 PM
#4
Chaos King is offline Chaos King
Status: Member
Join date: May 2006
Location:
Expertise:
Software:
 
Posts: 119
iTrader: 4 / 100%
 

Chaos King is on a distinguished road

Send a message via AIM to Chaos King Send a message via MSN to Chaos King

  Old

*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
derek lapp is offline derek lapp
Status: design rockstar
Join date: Jan 2005
Location: guelph, ontario
Expertise:
Software:
 
Posts: 2,246
iTrader: 0 / 0%
 

derek lapp is on a distinguished road

  Old

$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
Andrew R is offline Andrew R
Status: Request a custom title
Join date: Dec 2005
Location: Arizona
Expertise:
Software:
 
Posts: 5,200
iTrader: 17 / 95%
 

Andrew R is on a distinguished road

  Old

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
localhost is offline localhost
localhost's Avatar
Status: Dediport Hosting
Join date: Jul 2006
Location: Berkshire
Expertise: programming, business
Software: Dreamweaver
 
Posts: 1,316
iTrader: 17 / 100%
 

localhost is on a distinguished road

  Old

Yehm Sorry i didnt post i fixed about 5 minutes after the second post i made.

Closed Thread    


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 

  Posting Rules  
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump:
 
  Contains New Posts Forum Contains New Posts   Contains No New Posts Forum Contains No New Posts   A Closed Forum Forum is Closed