Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

harddrive vs server

Status
Not open for further replies.

janet24

Technical User
Jul 22, 2003
161
US
I have 2 samples of code. The first one works on the server and my harddrive. The second one only works on my harddrive. What would be the reason for that?

SAMPLE 1

<?php
$userid=$_POST['userid'];
$first=$_POST['first'];
$last=$_POST['last'];
$organ=$_POST['organ'];
$email=$_POST['email'];
$comments=$_POST['comments'];
@ $db=new mysqli('localhost','c4solutions','ftwash','ites');
if (mysqli_connect_errno())
{
echo 'Error: Could not connect to database.';
exit;
}
$query = "insert into itesuser(userid,first,last,organ,email,comments) values ('$userid' , '$first' , '$last' , '$organ' , '$email' , '$comments')";
$result = $db->query($query);
if ($result)
echo $db->affected_rows.' information inserted into database.';
$db->close();
?>

SAMPLE 2

<?php
$userid=$_POST['userid'];
$first=$_POST['first'];
$last=$_POST['last'];
$organ=$_POST['organ'];
$email=$_POST['email'];
$comments=$_POST['comments'];
echo "php is connecting";
exit;
}
@ $db=new mysqli('localhost', 'c4solutions', 'ftwash','ites');
if (mysqli_connect_errno())
{
echo 'Error: Could not connect to database.';
exit;
}
$query = "insert into itesuser values ('".$userid."','".$first."','".$last."','".$organ."','".$email."','".$comments."')";
$result = $db->query($query);
if ($result)
echo $db->affected_rows.' information inserted into database.';
$db->close();
?>
 
I assume when you say "on my harddrive", you really mean "on my workstation". You make it sound as though the firmware in your hard drive has a PHP interpreter.

First, get rid o fall the "@" in your code. They are error-supression operators which could be preventing the script from outputting good error messages.

Second, what does "doesn't work" mean?


Want the best answers? Ask the best questions! TANSTAAFL!
 
First you have a lone closing curly brace after the first exit; command that seems to have no opening partner. You'll get an error there.

Second That fact that you have an exit; after assigning a few variables command doesn't help. It will terminate the script there. and do nothing more.

In addition, I urge you to follow Sleipnir's advice and remove the "@" so you can get any error messages back and be able to debug.




----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Ok, this code works off my harddrive (apache & MySQL) but not on the server. The database is the same except I'm getting this error message off phpmyadmin...

Cannot load mysql extension. Please check your PHP configuration. - Documentation

@ $db=new mysqli

Do you mean I can take @ off the above statement or do I have to use something else to connect to the database?

I'm just trying to do something simple to test the server and SQL which was recently set up and I've been having problems.

<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');
echo "blah";
$userid=$_POST['userid'];
$first=$_POST['first'];
$last=$_POST['last'];
$organ=$_POST['organ'];
$email=$_POST['email'];
$comments=$_POST['comments'];

if (!$userid || !$first || !$last ||!$organ || !$email|| !$comments)
{echo 'You have not entered all the fields, try again';
exit;
}

@ $db=new mysqli('localhost','c4solutions','ftwash','ites');

if (mysqli_connect_errno())
{
echo 'Error: Could not connect to database.';
exit;
}

$query = "insert into itesuser(userid,first,last,organ,email,comments)
values ('$userid' , '$first' , '$last' , '$organ' , '$email' , '$comments')";
$result = $db->query($query);
if ($result)
echo $db->affected_rows.' information inserted into database.';
$db->close();
?>
 
Do you mean I can take @ off the above statement or do I have to use something else to connect to the database?
Remove all @s before function calls. Those symbols stop the display of errors and you're debugging: you want to see the errors.

and I've been having problems.
What are the nature of the problems?


Want the best answers? Ask the best questions! TANSTAAFL!
 
I get no response, no error, nothing being written to the database. The tech guy said php was not configured so I'll let you know if that doesn't work. and I will take @'s out.
 
Cannot load mysql extension. Please check your PHP configuration. - Documentation

This tells me PHP is not properly configured to load the mysql extension. Probably can't find it or something, You should talk to the Server Admin and see if he can fix it. As it has nothing top do with your code.

----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top