quite an advanced if statement..

  • Nem
  • Guru
  • Guru
  • No Avatar
  • Joined: Feb 13, 2004
  • Posts: 1243
  • Loc: UK
  • Status: Offline

Post July 11th, 2004, 3:02 am

hm, still doesnt seem to work.. nothing shows up.

My scenario:

I have a form asking for certain inputs to connect to database. Once it connects the sql code retrieves the information by a $_POST because the form is a $_POST.

Once it connects it automatically creates tables, and it also mentions it.

This i tested and works.

Straight after creating the tables in the database i need it to create the admin account. So a row in one of the tables it has created.

Would i still need to connect again or just insert the row?

I tried to just insert the row using:

PHP Code: [ Select ]
 
$ip = $_SERVER["REMOTE_ADDR"];
 
$user = $_POST["user"] ;
 
$pass = $_POST["pass"];
 
 
 
//insert the stuff
 
$sql = "INSERT INTO gs_admin (ip, lastvisit, user, pass)
 
       VALUES ('$ip',NOW(),'$user', '$pass')";
 
 
  1.  
  2. $ip = $_SERVER["REMOTE_ADDR"];
  3.  
  4. $user = $_POST["user"] ;
  5.  
  6. $pass = $_POST["pass"];
  7.  
  8.  
  9.  
  10. //insert the stuff
  11.  
  12. $sql = "INSERT INTO gs_admin (ip, lastvisit, user, pass)
  13.  
  14.        VALUES ('$ip',NOW(),'$user', '$pass')";
  15.  
  16.  


But the code above this starts of with "sql = " which i reckon stops it from using this.

Whats the best thing to do in this case?
GSDomains.com -Click here - Packages starting from £3.69 a month. 1.5GB Space & 10GB Bandwidth.
  • Anonymous
  • Bot
  • No Avatar
  • Joined: 25 Feb 2008
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post July 11th, 2004, 3:02 am

  • Nem
  • Guru
  • Guru
  • No Avatar
  • Joined: Feb 13, 2004
  • Posts: 1243
  • Loc: UK
  • Status: Offline

Post July 11th, 2004, 3:12 am

i have also now tried:

PHP Code: [ Select ]
 
//Now insert the admin stuff.  GETTING PROBLEMS BELOW THIS BIT
 
$ip = $_SERVER["REMOTE_ADDR"];
 
$user = $_POST["user"] ;
 
$pass = $_POST["pass"];
 
//insert
 
$query = "INSERT INTO ".$_POST["sqldbase"]."gs_admin ('ip', 'lastvisit', 'user', 'pass') VALUES VALUES ('$ip',NOW(),'$user', '$pass')";
 
    $query = mysql_query($sql) or die("Cannot query the database.<br>" . mysql_error());
 
    echo = "creating your admin account";
 
     
 
    } else {
 
    echo ("Could not connect"); }
 
 
  1.  
  2. //Now insert the admin stuff.  GETTING PROBLEMS BELOW THIS BIT
  3.  
  4. $ip = $_SERVER["REMOTE_ADDR"];
  5.  
  6. $user = $_POST["user"] ;
  7.  
  8. $pass = $_POST["pass"];
  9.  
  10. //insert
  11.  
  12. $query = "INSERT INTO ".$_POST["sqldbase"]."gs_admin ('ip', 'lastvisit', 'user', 'pass') VALUES VALUES ('$ip',NOW(),'$user', '$pass')";
  13.  
  14.     $query = mysql_query($sql) or die("Cannot query the database.<br>" . mysql_error());
  15.  
  16.     echo = "creating your admin account";
  17.  
  18.      
  19.  
  20.     } else {
  21.  
  22.     echo ("Could not connect"); }
  23.  
  24.  
GSDomains.com -Click here - Packages starting from £3.69 a month. 1.5GB Space & 10GB Bandwidth.
  • Veter
  • Novice
  • Novice
  • User avatar
  • Joined: Jul 08, 2004
  • Posts: 20
  • Status: Offline

Post July 11th, 2004, 4:27 am

What it tells?
  • SpooF
  • ٩๏̯͡๏۶
  • Bronze Member
  • User avatar
  • Joined: May 22, 2004
  • Posts: 3415
  • Loc: Richland, WA
  • Status: Offline

Post July 11th, 2004, 6:01 am

by the way

varible
PHP Code: [ Select ]
 
$conn = @mysql_connect("$host","$pass","$user");
 
 
  1.  
  2. $conn = @mysql_connect("$host","$pass","$user");
  3.  
  4.  


function
PHP Code: [ Select ]
 
function conn($host, $pass, $user) {
 
@mysql_connect("$host","$pass","$user");
 
}
  1.  
  2. function conn($host, $pass, $user) {
  3.  
  4. @mysql_connect("$host","$pass","$user");
  5.  
  6. }


when you call the function
PHP Code: [ Select ]
 
conn(localhost, pass, username);
 
 
  1.  
  2. conn(localhost, pass, username);
  3.  
  4.  
  • Scorpius
  • Proficient
  • Proficient
  • User avatar
  • Joined: Mar 20, 2004
  • Posts: 401
  • Loc: Scorpion Hole
  • Status: Offline

Post July 11th, 2004, 7:33 am

Nem wrote:
i have also now tried:

PHP Code: [ Select ]
//Now insert the admin stuff.  GETTING PROBLEMS BELOW THIS BIT
$ip = $_SERVER["REMOTE_ADDR"];
$user = $_POST["user"] ;
$pass = $_POST["pass"];
//insert
$query = "INSERT INTO ".$_POST["sqldbase"]."gs_admin ('ip', 'lastvisit', 'user', 'pass') VALUES VALUES ('$ip',NOW(),'$user', '$pass')";
    $query = mysql_query($sql) or die("Cannot query the database.<br>" . mysql_error());
    echo = "creating your admin account";
     
    } else {
    echo ("Could not connect"); }
 
  1. //Now insert the admin stuff.  GETTING PROBLEMS BELOW THIS BIT
  2. $ip = $_SERVER["REMOTE_ADDR"];
  3. $user = $_POST["user"] ;
  4. $pass = $_POST["pass"];
  5. //insert
  6. $query = "INSERT INTO ".$_POST["sqldbase"]."gs_admin ('ip', 'lastvisit', 'user', 'pass') VALUES VALUES ('$ip',NOW(),'$user', '$pass')";
  7.     $query = mysql_query($sql) or die("Cannot query the database.<br>" . mysql_error());
  8.     echo = "creating your admin account";
  9.      
  10.     } else {
  11.     echo ("Could not connect"); }
  12.  

Hmm I think you need to change this:
PHP Code: [ Select ]
$query = "INSERT INTO ".$_POST["sqldbase"]."gs_admin ('ip', 'lastvisit', 'user', 'pass') VALUES VALUES ('$ip',NOW(),'$user', '$pass')";

to:
PHP Code: [ Select ]
$query = "INSERT INTO gs_admin ('ip', 'lastvisit', 'user', 'pass') VALUES ('$ip',NOW(),'$user', '$pass')";

You shouldn't have to put the database name into the query and you don't need the word VALUES twice. You should also md5 the password before you send it to the database.
PHP Code: [ Select ]
$pass = md5($_POST['pass']);

Hope this will fix it for you.

Post Information

  • Total Posts in this topic: 20 posts
  • Users browsing this forum: No registered users and 164 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
cron
 

© 2011 Unmelted, LLC. Ozzu® is a registered trademark of Unmelted, LLC.