3 Replies - 967 Views - Last Post: 25 July 2008 - 06:29 PM Rate Topic: -----

#1 Ändrew   User is offline

  • D.I.C Regular
  • member icon

Reputation: 25
  • View blog
  • Posts: 312
  • Joined: 21-April 08

Add User I cant find the problem!

Post icon  Posted 25 July 2008 - 05:23 PM

Hello,

As I have realesed a program that needs usernames and passwords and I have created a easy way then just putting the querys in SQL. But when I submit a Username, Password, Expirery date I just tells me query fails and I cant find the problem in my code so can you guys look at it for me?

<?php
if(isset($_POST['save']))
{
   $username = $_POST['username'];
   $password = $_POST['password'];
   $expire   = $_POST['expire'];

   if(!get_magic_quotes_gpc())
   {
      $username = addslashes($username);
      $password = addslashes($password);
	  $expire   = addslashes($expire);
   }
   include 'config.php';
   include 'opendb.php';

   $query = " INSERT INTO userlist (username, password, expire) ".
            " VALUES ('$username', '$password', '$expire)";
   mysql_query($query) or die('Error ,query failed');

   include 'closedb.php';

   echo "User '$username' added";
}
?>
<html>
<head>
<link rel="stylesheet" type="text/css" href="http://www.qescripter.uni.cc/style.css" >
</head>
<body>
<center>
<br>
<form method="post">
<table width="700" border="0" cellpadding="2" cellspacing="1" align="center">
<tr>
<td width="100">Username</td>
<td><input name="username" type="text"></td>
</tr>
<td width="100">Password</td>
<td><input name="password" type="text"></td>
</tr>
<td width="100">Expire</td>
<td><input name="expire" type="text"></td>
</tr>
<tr>
<td width="100">&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td colspan="2" align="center"><input name="save" type="submit" value="Make User"></td>
</tr>
</table>
</form>
</center>
</body>
</html>



I based it off my Add News...

Ändrew

http://andyscripter.uni.cc/

Is This A Good Question/Topic? 0
  • +

Replies To: Add User I cant find the problem!

#2 PsychoCoder   User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1663
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: Add User I cant find the problem!

Posted 25 July 2008 - 05:37 PM

Your problem is in your query, you have it like this

$query = " INSERT INTO userlist (username, password, expire) ".
            " VALUES ('$username', '$password', '$expire)";



You have single quotes around the variable names, which is throwing your database for a loop. Change your query to look like this

$query = " INSERT INTO userlist (username, password, expire) ".
            " VALUES ('" .mysql_real_escape_string($username). "','" .mysql_real_escape_string($password). "','" .mysql_real_escape_string($expire). "')";



That should resolve your issue :)
Was This Post Helpful? 0
  • +
  • -

#3 JBrace1990   User is offline

  • D.I.C Addict
  • member icon

Reputation: 112
  • View blog
  • Posts: 760
  • Joined: 09-March 08

Re: Add User I cant find the problem!

Posted 25 July 2008 - 06:05 PM

I think he just missed a single quote after $expire... >_>
Was This Post Helpful? 0
  • +
  • -

#4 Ändrew   User is offline

  • D.I.C Regular
  • member icon

Reputation: 25
  • View blog
  • Posts: 312
  • Joined: 21-April 08

Re: Add User I cant find the problem!

Posted 25 July 2008 - 06:29 PM

Oh jee your right im missing a quote. I think i need glasses B)
Thanks Guys.

Ändrew
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1