View previous topic :: View next topic |
Author |
Message |
E-Oreo. Guest
|
Posted: Tue Jun 04, 2002 5:52 pm Post subject: Writing to an mysql database |
|
|
I am using this php script to write the resualts of this form to an mysql database.
This is 1.html, the form
Code: | <HTML>
<HEAD>
<TITLE> Form Handling with PHP </TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF">
<center>
<FORM METHOD="POST" ACTION="1.php">
<input type="hidden" name="id" value="NULL">
<TABLE>
<TR height="20"><TD colspan="2"><FONT SIZE="+0" face="verdana">
Below is a Sample Form for our PHP tutorial</TD></TR>
<TR height="50">
<td></td></TR>
<TR><TD align="left"><FONT SIZE="+0" face="verdana">
<b>Your Name <br>Your E-Mail Address</b></td>
<td><INPUT TYPE="text" NAME="$name" value=""><br><INPUT
TYPE="text" NAME="$email"><p></TD>
</TR>
<tr><td colspan="2"><center>
<SELECT NAME="$opinion">
<option value="is great">I like your site</option>
<option value="is OK">Your Site is OK</option>
<option value="is horrible">Your Site is
horrible</option>
</SELECT><p><INPUT TYPE="submit" value="Tell
us!"></td></tr>
</TABLE></FORM></body></html> |
And this is 1.php
Code: | <?
$DBhost = "localhost";
$DBuser = "root";
$DBpass = "(password)";
$DBName = "blink";
$table = "report";
mysql_connect($DBhost,$DBuser,$DBpass) or die("Unable to connect to database");
@mysql_select_db("$DBName") or die("Unable to select
database $DBName");
$sqlquery = "INSERT INTO $table
VALUES('$id','$name','$email','$opinion')";
$results = mysql_query($sqlquery);
mysql_close();
print "<HTML><TITLE> PHP and MySQL </TITLE><BODY
BGCOLOR=\"#FFFFFF\"><center><table border=\"0\"
width=\"500\"><tr><td>";
print "<p><font face=\"verdana\" size=\"+0\"> <center>You
Just Entered This Information Into the
Database<p><blockquote>";
print "Name : $name<p>E-Mail : $email<p>Opinion :
$opinion</blockquote></td></tr></table>
</center></BODY></HTML>";
?> |
When i type stuff into the form and then click on submit i get:
Notice: Undefined variable: id in C:\XITAMI\ftproot\test\1.php on line 14
Notice: Undefined variable: name in C:\XITAMI\ftproot\test\1.php on line 14
Notice: Undefined variable: email in C:\XITAMI\ftproot\test\1.php on line 14
Notice: Undefined variable: opinion in C:\XITAMI\ftproot\test\1.php on line 14
You Just Entered This Information Into the Database
Notice: Undefined variable: name in C:\XITAMI\ftproot\test\1.php on line 26
Notice: Undefined variable: email in C:\XITAMI\ftproot\test\1.php on line 26
Notice: Undefined variable: opinion in C:\XITAMI\ftproot\test\1.php on line 27
Name :
E-Mail :
Opinion :
What am i doing wrong? is there an error is this code?
Thankz |
|
Back to top |
|
|
TheLinker -
Joined: 05 Apr 2002 Posts: 165 Location: Oslo, Norway
|
Posted: Tue Jun 04, 2002 7:17 pm Post subject: Re: Writing to an mysql database |
|
|
Check in your PHP.ini if register_globals = On. |
|
Back to top |
|
|
E-Oreo -
Joined: 18 Apr 2002 Posts: 17
|
Posted: Tue Jun 04, 2002 7:32 pm Post subject: thankz |
|
|
thankz i'll try that, will i need to restart any of my servers? (mysql, web server?) |
|
Back to top |
|
|
TheLinker -
Joined: 05 Apr 2002 Posts: 165 Location: Oslo, Norway
|
Posted: Wed Jun 05, 2002 6:26 am Post subject: Re: thankz |
|
|
E-Oreo wrote: | thankz i'll try that, will i need to restart any of my servers? (mysql, web server?) |
No, you don't need to do that... |
|
Back to top |
|
|
E-Oreo -
Joined: 18 Apr 2002 Posts: 17
|
Posted: Wed Jun 05, 2002 10:13 pm Post subject: no |
|
|
it didn't work, i still got the exact same error, any other suggestions? |
|
Back to top |
|
|
Guest Guest
|
Posted: Thu Jun 06, 2002 10:42 pm Post subject: get - method |
|
|
Hi!
I've got the same problem, seem as if php does not get variables from the url! Have you already found a solution? |
|
Back to top |
|
|
TheLinker -
Joined: 05 Apr 2002 Posts: 165 Location: Oslo, Norway
|
Posted: Fri Jun 07, 2002 6:31 am Post subject: Re: no |
|
|
E-Oreo wrote: | it didn't work, i still got the exact same error, any other suggestions? |
There is an error in your HTML code ... don't use the character $ in your variables name... if you remove the $ character and use register_globals = on, it should work ... if you want to run using register_globals = off, you need to change something in your php code...
... Instead of
VALUES('$id','$name','$email','$opinion')";
... it should read ...
VALUES('$_POST["id"]','$_POST["name"]','$_POST["email"]','$_POST["opinion"]')"; |
|
Back to top |
|
|
putnam Guest
|
Posted: Sat Jun 08, 2002 12:52 pm Post subject: |
|
|
i had this problem--- make sure you have register_Globals on--- but also make sure you have Php.ini in C:\windows or C:\winnt or C:\winnt40 (Whichever one is your %systemroot%).
-putnam |
|
Back to top |
|
|
E-Oreo. Guest
|
Posted: Sun Jun 09, 2002 7:07 pm Post subject: :( |
|
|
I feel really stupid. :oops:
Thankz, that made it work perfectly |
|
Back to top |
|
|
|