PDA

View Full Version : Information isn't being entered into database...


Iryk
12-14-2006, 02:12 AM
I have written a script that is suppose to enter information into a database. Can some one please tell me why the information isn't being entered?

<?php
$db_username = $_POST['db_username'];
$db_password = $_POST['db_password'];
$db_host = $_POST['db_host'];

$connect = mysql_connect("$db_host","$db_username","$db_password") or die("<center><span style='color: red; font: 8pt verdana'>Database information is wrong. Please go back and retype the information.</span></center>");

if ($your_password != $retype_password) {
echo "<center><span style='color: red; font: 8pt verdana'>Your passwords do not match. Please go back and retype the information.</span></center>";
} else {

$dat = date("D j M, Y");
$title = $_POST['site_title'];
$description = $_POST['site_description'];
$copyright = $_POST['site_copyright'];
$url = $_POST['site_url'];
$banner = $_POST['site_banner'];
$username = $_POST['your_username'];
$password = md5($_POST['your_password']);
$location = $_POST['your_location'];
$email = $_POST['your_email'];
$avatar = $_POST['your_avatar'];
$website = $_POST['your_website'];
$signature = $_POST['your_signature'];

$installed = '$installed';
$new_content = "<?
" . $installed . " = 'yes';
mysql_connect('" . $db_host . "','" . $db_username . "','" . $db_password . "');
?>";
$file = fopen('../db_connect.php', 'a');
fwrite($file,$new_content);
fclose($file);

include("../db_connect.php");
mysql_query("INSERT INTO user (user, pass, website, email, avatar, location, sig) VALUES ('$username','$password', '$website', '$email', '$avatar','$location','$signature')");
mysql_query("INSERT INTO staff VALUES ('$username','Admin','0')");
mysql_query("INSERT INTO site VALUES ('$title','$description','$dat','Blue','$copyright','$url','$banner')");

echo '<center><span style="color:green;font-size:8pt;font-family: verdana">The installation was successful.</span><br><a href="../index.php"><span style="font-size:8pt;font-family: verdana">Go to the homepage</span></a></center>';
}
?>

Fumigator
12-14-2006, 02:54 AM
Add checks to see if your queries failed and why. It's fun to do!

Instead of this (which tells you absolutely nothing about whether your queries worked):


mysql_query("INSERT INTO user (user, pass, website, email, avatar, location, sig) VALUES ('$username','$password', '$website', '$email', '$avatar','$location','$signature')");
mysql_query("INSERT INTO staff VALUES ('$username','Admin','0')");
mysql_query("INSERT INTO site VALUES ('$title','$description','$dat','Blue','$copyright','$url','$banner')");


Do something like this:


$result = mysql_query("INSERT INTO user (user, pass, website, email, avatar, location, sig) VALUES ('$username','$password', '$website', '$email', '$avatar','$location','$signature')");

//checking the query to see if it worked
if (!$result) {
die('QUERY FAILURE! I DIE NOW. error text is '.mysql_error());
}

$result = mysql_query("INSERT INTO staff VALUES ('$username','Admin','0')");

//checking the query to see if it worked
if (!$result) {
die('QUERY FAILURE! I DIE NOW. error text is '.mysql_error());
}

$result = mysql_query("INSERT INTO site VALUES ('$title','$description','$dat','Blue','$copyright','$url','$banner')");

//checking the query to see if it worked
if (!$result) {
die('QUERY FAILURE! I DIE NOW. error text is '.mysql_error());
}

Iryk
12-14-2006, 03:14 AM
Ok thanks... i did what u sed to do now i found out that no database was selected... how would i do that?

swatisonee
12-14-2006, 04:16 AM
$db_username = $_POST['db_username'];
$db_password = $_POST['db_password'];
$db_host = $_POST['db_host'];

Where is the db name ????

Iryk
12-14-2006, 04:26 AM
lol i just realized that... i got it working.. thanks for your help :)