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!

PHP noob getting errors

Status
Not open for further replies.

wbodger

Programmer
Apr 23, 2007
769
US
OK, I have a simple page that I need to make work. I can do it simple enough in ASP, but they have a Linux box, and I have to use PHP. Only problem is I do not know PHP at all, so troubleshooting the errors is difficult at best. Anyway, the code is simply taking the response from a single question survey and writing it to a db:

Code:
<?php

mysqlconnect("mysqlv12","gppsurvey","GPPartners") or die ('Error:'.mysqlerror());
mysql_select_db("gppsurvey");

$query = "Insert into survey(survey,response) values('".$survey."','".$response."')";
mysql_query($query) or die ('Error updating database');

response.redirect("thankyou.html")

?>

and the error is:
Code:
Fatal error: Call to undefined function mysqlconnect() in /data/10/0/161/147/813310/user/834562/htdocs/newsletter/surveyprocess.php on line 3

I'm sure my error is syntactical in nature, but I really don't know. Once I get this figured out I will go back to learn PHP, but for now I just need to make this work. So, what have I done wrong? And thank you in advance for any help that you can give me!

Willie
 
Hi

Willie said:
So, what have I done wrong?
One of this :
[ul]
[li]You not defined the [tt]mysqlconnect()[/tt] function before calling it.[/li]
[li]You wish to use the [tt]mysql_connect()[/tt] function but misspelled its name.[/li]
[/ul]
I bet you next problem will be response.redirect(). You will have to use [tt]header()[/tt] instead.

Beside that, I hope your $survey and $response variables' values were escaped before using them in an SQL statement. If not, consider using [tt]mysql_real_escape_string()[/tt] on them.

Feherke.
 
Thank you, that seems to have cleared up my syntax problems! Now I just need to figure out how the hosting provider wants me to connect to the db...
 
You need:
username
password
database name
the server it runs on.
Your code looks ok, it connects, then it selects then it executes a query.
As you are from a MS background you might want to look at the ODBC interface rather than the native calls. It'll ber a bit slower but might get you up and running quicker.
The response.redirect call you iaaue should be a header call such as
Code:
header("Location: [URL unfurl="true"]http://www.site.com/thankyou.html");[/URL]
I might be wrong on this but I think you have to give the full URL with header.
A gotcha with redirects which catches a lot of people is you can't output anything at all (white space, nothing) from a script if you then go on to use the header call. This makes sense as the header is an HTTP header and must come before the textual body of the page. If you get a run-time error saying something like can't issue headers after content sent you've output something.
Any probs look at or give a shout here
 
Woo hoo, I got it working! Well, you guys got it working, I just replaced values. Thanks for the help, I really appreciate it.

Willie
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top