Page 1 of 1

Problems with MySQL and remote INSERT

Posted: Fri Aug 01, 2003 5:51 pm
by sghetti
I have a registration script that I have working wonderfully on my server(whch is also my regular pc). Problem is, whenever I try to run the script from a different pc, such as one from my workplace, the script returns the message I set up in the case that the INSERT did not execute. Now, I set all privelages for this db and the username and password are correct. Again, the script runs fine on my computer, just not from a remote one.

Even more interesting is the fact that I have several other scripts, none of them INSERT though, that all work without a hitch. Please help me! This is driving me crazy!!! Here is the script:

Code: Select all

<?php
include("config.php");
$connect = mysql_connect("$user_hostname", "$user_username", "$user_password");
mysql_select_db("$user_database", $connect);
$sql = "SELECT * FROM users WHERE userName = "$userName"";
$result = @mysql_query($sql) or die("Could not select from database");
$num = mysql_num_rows($result);
if($submit && empty($firstName) && empty($lastName) && empty($email) && empty($userName) && empty($passWord)) 
&#123;
echo "<center>You need to enter all the fields</center>";
&#125; 
else if($num == "1") 
&#123;
echo "<center>The username is already registered, please try another.</center>";
&#125; 
else if($submit && !empty($firstName) && !empty($lastName) && !empty($email) && !empty($userName) && !empty($passWord) && $num == "0") 
&#123;
$insert = "INSERT INTO users VALUES ('', '$firstName', '$lastName', '$email', '$userName', '$passWord')";
$insert_res = @mysql_query($insert) or die("<center>Could not register account.</center>");
mkdir ("users/$userName");
echo "<center>Thank you $userName.<br/>Your account is active.<br/><a href="signin.php">Log In</a>!</center>";
&#125;
mysql_close($connect);
?>
The include file (config.php) is just assigning variables to my connection, username and password. There's nothing wrong in it. Thx in advance.

Posted: Mon Aug 04, 2003 8:09 pm
by Jade
The only thing i possibly see that could be wrong, is that your not telling the insert WHERE to put the data into it.

For example you have 3 fields (name, pass, email) then your insert would look something like this:

Code: Select all

<?php

$result = mysql_query("INSERT INTO members (name, pass, email) VALUES ('$name','$pass','$email'")
or die ('cannot create new member');
?>

You have:

Code: Select all

<?php
$insert = "INSERT INTO users VALUES ('', '$firstName', '$lastName', '$email', '$userName', '$passWord')"; 
$insert_res = @mysql_query($insert) or die("<center>Could not register account.</center>"); 
?>

Code: Select all

<?php
$result = mysql_query("INSERT INTO members (name, pass, email) VALUES ('$name','$pass','$email'")
or die ('cannot create new member');
?>