Database > General Database

More login problems

(1/1)

BenBread:
heres the deal, i got this script to add a user to the database (i have other scripts to login n stuff) but the problem is it deletes the original recold and writes over it, being a complete plonker i can't fix it please help!!!!!!!

<?php
include("connect2db.php");
$qselect = "Select * from members where id = '1'";
$qadd = "
  INSERT INTO members
   (id, password, username)
   VALUES ('1', 'test', 'test') ";
$qupdate = "
  UPDATE members
    SET password = '$password',
     username = '$username'
    WHERE id = '1'";

$result = mysql_query($qselect);

// check the single record exists
if (mysql_num_rows($result)) $result = mysql_query($qupdate); // add record
else $result = mysql_query($qadd); // if not add an initial record

if ($result) mysql_close();
else
{
 echo "ERROR - unable to save new username and password!<br>";
 $SQLError =  "SQL ERROR: ".mysql_errno().".  ".mysql_error()."<BR><BR>";
 echo "$SQLError";
 mysql_close();
}
include("addauser.php");
?>
Any idea's?

milesburton:
Your trying to update a table without a database.. You need to add 3 extra characters to your line...

peg110:

--- Quote from: "milesburton" ---Your trying to update a table without a database.. You need to add 3 extra characters to your line...
--- End quote ---


I'd assume include("connect2db.php"); has that info

evilcoder:

--- Code: ---$qselect = "Select * from members where id = '1'";
$qadd = "
INSERT INTO members
(id, password, username)
VALUES ('1', 'test', 'test') ";
$qupdate = "
UPDATE members
SET password = '$password',
username = '$username'
WHERE id = '1'";
--- End code ---


If your trying to add a member to a database, then why are you writing over the existing member with id of "1" ?

If you have set ID to auto_increment you don't have to define it in the values for "members".

Navigation

[0] Message Index

Go to full version