Web Hosting Talk







View Full Version : php/MySQL setup issue


richj
11-15-2002, 02:41 PM
Hi folks,

Looking for help...

I'm trying to set up a new site with my favorite web host, first one using php.

I can't seem to get my scripts to write into the database. I've tested the scripts thoroughly on my home server and in a subdirectory of my own website on another server hosted by the same company...worked perfectly. I've double-checked all the settings I can think of (queries, db name, table name, etc.) I know that the scripts are reading the database because they can pull out data, just can't write. Another weird quirk...a simple php form handling e-mail script also doesn't work...no database involvement. Here again, the script does work in other locations.

Thoughts?

Thanks,
Rich

jtrovato
11-15-2002, 03:43 PM
There needs to be more info.

Maybe send some code and the table structure....

MDJ2000
11-15-2002, 04:28 PM
You can't query a database without first connecting to it. Are you sure you're connecting properly? Other than that, we need some code and/or error messages to help you.

jtrovato
11-15-2002, 05:18 PM
He said he can select from the database but can not insert. Maybe you should echo the query out on the screen copy and paste into myphpadmin and see what errors you get. The two tables might be different and when you tested it at home it worked fine but when you uploaded the code it does.

John

richj
11-15-2002, 05:41 PM
Thanks for the offers of help...here's some code.

--First, the e-mail handler. No database connection and again, everything works on another server managed by the same host. Also, no error messages, even the built-in responses don't appear - just dead air...

------------------------------------------

<?php
if ($BeenSubmitted) {

if ("From: $MailFrom") {

if (mail($MailTo, $Subject, $Body, "From: $MailFrom")) {

print ("Your question has been successfully sent!\n");


} else {

print ("Your question was not successfully sent due to a system error!\n");

}

} else {

print ("Please enter your return e-mail address.\n");

}

}


?>

<TABLE WIDTH=500 border=0 cellpadding=0 cellspacing=0 align=center>

<FORM ACTION="contact.php" METHOD=POST>
<input type = HIDDEN name= BeenSubmitted value=TRUE>
<input type = HIDDEN name = MailTo value = rjohnston@webvoce.com >

<TR>

<TD VALIGN=top width=180 ><H3>Your E-mail Address:</H3></td>
<TD VALIGN=top ><INPUT TYPE="TEXT" NAME="MailFrom" size=35></td>
</TR>
<TR>

<TD VALIGN=top WIDTH=180><H3>Subject:</H3></td>
<TD VALIGN=top ><INPUT TYPE="TEXT" NAME="Subject" size=35></td>
</TR>

<TR>

<TD VALIGN=top width=180><H3>Your Question:</H3></TD>
<TD VALIGN=top ><TEXTAREA NAME="Body" rows=7 cols=27 wrap=Physical></TEXTAREA></td>
</TR>
<TR colspan=2>
<TD width=180>&nbsp;</td>
<TD class="center" VALIGN=middle ><INPUT TYPE="submit" VALUE="send" >&nbsp;&nbsp <INPUT TYPE="reset" VALUE="reset"></TD>
</TR>
</FORM>
</TABLE>

---------------------------------------------------------------------------------

Now one of the database interface forms. This one adds users

$Array["user"] = trim($Array["user"]);
$Array["password"] = trim($Array["password"]);
$Array["userlevel"] = trim($Array["userlevel"]);


$Host = $db_server;
$User = $db_user;
$Password = $db_password;
$DBName = $db_database;
$TableName = "phpSP_users";



if ($BeenSubmitted) {


$Link = mysql_pconnect ($Host, $User, $Password);
$Query = "INSERT into $TableName values ('0', '$Array[user]','$Array[password]', '$Array[userlevel]')";


if (mysql_db_query ($DBName, $Query, $Link)) {
print ("The query was successfully executed!<br>\n");
} else {
print ("The query could not be executed!<BR>\n");
}

mysql_close ($Link);
}

------------------------------------------------------------------------------------

Fairly simple, blunt code - db variables are defined in an include file. Again, everything works fine on another server managed by the same host. Selfishly, I want to believe it's not my code...any chance it's a problem with the server settings (php.ini, mySQL, etc.?). Also, no error messages, even the built-in responses don't appear - just dead air...


I'll try the echo technique suggested above also.

Thanks,
Rich

sasha
11-15-2002, 06:03 PM
is there a reason that you use persistent connection ? Try mysql_connect() instead, just for fun.

Somthing from php.net about mysql_db_query :


Note: This function has been deprecated since PHP 4.0.6. Do not use this function. Use mysql_select_db() and mysql_query() instead.


about if ("From: $MailFrom")

This will alway be different from FALSE same as you did: if ( 1 )


Not good idea to leave these spaces around "=" in any tag
<input type = HIDDEN name= BeenSubmitted value=TRUE>
<input type = HIDDEN name = MailTo value = rjohnston@webvoce.com >