Forum Home
Press F1
 
Thread ID: 60191 2005-07-25 11:34:00 php / mysql query not working Morgenmuffel (187) Press F1
Post ID Timestamp Content User
375240 2005-07-25 11:34:00 Right here goes

I have two dBases
login_info - stores login details (in a table called loginuser)
rep_info - stores rep details (in a table called reps)
the connection details for login_info are in bla1 . php
the connection details for rep_info are in bla1 . php

I am adding users to a dBase i am adding their details and also a username and pasword, thir details got to rep_info and the pasword stuff goes to login_info, but I'm stuck
The script below doesn't work,



if (($valid) && ($emc == TRUE)) {
//<<<<<<<<<< Inserts User name and pswrd into Login Dbase
require_once('bla1 . php');
mysql_select_db($dbnamex, $connx);
echo '<br>';
//<<<<<< encrypt password >>>>>>>>>
$pswrd = crypt($pswrd);
$query = "insert into loginuser values (NULL,'" . $user_name . "', '" . $pswrd . "', '" . $level . "')";
$result = mysql_query($query);
if ($result){
echo 'The Rep Login information was added successfully';
}
$rep_ID = mysql_insert_id();

//<<<<<<<< Inserts address details into job database >>>>
require_once('bla2 . php');
mysql_select_db($dbname, $conn);
$query2 = "insert into reps values ('" . $rep_ID . "','" . $salutation . "', '" . $l_name . "', '" . $f_name . "', '" . $street . "', '" . $street2 . "', '" . $zip . "', '" . $city . "', '" . $phone . "', '" . $cell . "', '" . $email . "', '" . $region . "')";
echo $query2 . ' <br>';
$result2 = mysql_query($query2);
if ($result2){
echo '<br>The Reps contact details were added successfully';
}
exit;
}



it inserts the login_details fine
it doesn't insert the rep_details though

now i an pretty sure it is the connection string on the rep info that doesn't work, when i echo out the query (query2) and cut and paste it in to phpmyadmin it executes fine, both connection files use different terms and passwords so there is no clash there


bla1 . php
$server = "localhost"; // MySQL hostname
$username = "bill"; // MySQL username
$password = "past_bed_time"; // MySQL password
$dbnamex = "login_info"; // MySQL db name
$connx = mysql_pconnect($server, $username, $password) or die(mysql_error());


bla2 . php
$hostname = "localhost"; // MySQL hostname
$dbuser = "bob"; // MySQL username
$dbpass = "pass"; // MySQL password
$dbname="rep_info"; // MySQL db name
$conn = mysql_connect($hostname, $dbuser, $dbpass)
or die (mysql_error());



So if any one has the slightest clue as to what could be causing it please let me know, and i'll be back in the morning to try suggestions out

Thanks
Morgenmuffel (187)
375241 2005-07-25 13:47:00 Pconnect?

By the way checkout www.creightonbrown.co.nz (http://www.creightonbrown.co.nz) I have made an idea for a Session abstraction layer with ASP.

$connx = mysql_pconnect($server, $username, $password) or die(mysql_error
$conn = mysql_connect($hostname, $dbuser, $dbpass)



Right here goes

I have two dBases
login_info - stores login details (in a table called loginuser)
rep_info - stores rep details (in a table called reps)
the connection details for login_info are in bla1.php
the connection details for rep_info are in bla1.php

I am adding users to a dBase i am adding their details and also a username and pasword, thir details got to rep_info and the pasword stuff goes to login_info, but I'm stuck
The script below doesn't work,



if (($valid) && ($emc == TRUE)) {
//<<<<<< <<<< Inserts User name and pswrd into Login Dbase
require_once('bla1.php');
mysql_select_db($dbnamex, $connx);
echo ' <br>';
//<<<<<< encrypt password >>>>>>>>>
$pswrd = crypt($pswrd);
$query = "insert into loginuser values (NULL,'".$user_name."', '".$pswrd."', '".$level."')";
$result = mysql_query($query);
if ($result){
echo 'The Rep Login information was added successfully';
}
$rep_ID = mysql_insert_id();

//<<<<<< << Inserts address details into job database >>>>
require_once('bla2.php');
mysql_select_db($dbname, $conn);
$query2 = "insert into reps values ('".$rep_ID."','".$salutation."', '".$l_name."', '".$f_name."', '".$street."', '".$street2."', '".$zip."', '".$city."', '".$phone."', '".$cell."', '".$email."', '".$region."')";
echo $query2.' <br>';
$result2 = mysql_query($query2);
if ($result2){
echo '<br>The Reps contact details were added successfully';
}
exit;
}



it inserts the login_details fine
it doesn't insert the rep_details though

now i an pretty sure it is the connection string on the rep info that doesn't work, when i echo out the query (query2) and cut and paste it in to phpmyadmin it executes fine, both connection files use different terms and passwords so there is no clash there


bla1.php
$server = "localhost"; // MySQL hostname
$username = "bill"; // MySQL username
$password = "past_bed_time"; // MySQL password
$dbnamex = "login_info"; // MySQL db name
$connx = mysql_pconnect($server, $username, $password) or die(mysql_error());


bla2.php
$hostname = "localhost"; // MySQL hostname
$dbuser = "bob"; // MySQL username
$dbpass = "pass"; // MySQL password
$dbname="rep_info"; // MySQL db name
$conn = mysql_connect($hostname, $dbuser, $dbpass)
or die (mysql_error());



So if any one has the slightest clue as to what could be causing it please let me know, and i'll be back in the morning to try suggestions out

Thanks
CreightonBrown (5692)
375242 2005-07-25 13:50:00 Try Duplicating the connections, change only the final reference.

See if it makes any difference

Also consider or die($sql) for the sql and or die ($DBname) or similar as well.
CreightonBrown (5692)
375243 2005-07-25 13:54:00 You may also want to consider a naming convention for things.

e.g. Action Entity

Common Actions:
Add, Update, Delete, Get, Search, List

Entities are typically tables e.g. User, Customer, Product, Category or so forth.

Some people may also advocate labelling Things with type e.g. ObjVar for object, strVar for string, intVar for integer or otherwise.

EXAMPLEs
AddCustomer
DeleteOrder
SearchProduct

NOTE:
You cannot say when it will be one or many with All entities

As such at some point it will be incorrect

it seems more logical calling it product, may be more acceptable than products as plural may not always exist for some entities.
CreightonBrown (5692)
1