PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
bla5e
Forum Contributor
Posts: 234 Joined: Tue May 25, 2004 4:28 pm
Post
by bla5e » Sat Jun 05, 2004 11:55 am
SUBMIT FORM :
Code: Select all
<?php
if (!empty($_POST['submitted']) && $_POST["submitted"] == 1){
error_reporting(E_ALL);
$date = $_POST["date"];
$name = $_POST["name"];
$info = $_POST["info"];
$cdproof = $_POST["cdproof"];
$vacproof = $_POST["vacproof"];
$dbh=mysql_connect ("localhost", "root", "") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("cheats");
$sql = "INSERT INTO cheats VALUES ('$date', '$name', '$info', '$cdproof', '$vacproof')";
$result = mysql_query($sql, $dbh);
echo mysql_error();
echo "Cheats submitted!";
}
else
{
//display the form
?>
<form action=cheatsubmit.php method=post>
<< BODY OF FORM REMOVED >>
<input type="hidden" name="submitted" value="1">
<input type="image" name=submitted src="submit.png" value="1">
<?php } echo mysql_error(); ?>
PROBLEMS: Wont submit data to mySQL db
-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_
WEBSITE WITH THE LISTED MATERIAL(s)
-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_
Code: Select all
<?php
error_reporting(E_ALL);
$dbh=mysql_connect ("localhost", "root", "") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("cheats");
$sql = "SELECT * FROM cheats";
echo mysql_error();
$result = mysql_query($sql, $dbh);
echo mysql_error();
echo "<table width="100%" border="1" cellpadding="0" cellspacing="0">";
echo "<tr>";
echo "<td width="8%"><span class="style4">Release Date</span> </td>";
echo "<td width="23%"><span class="style4">Name</span></td>";
echo "<td width="47%"><span class="style4">Description</span></td>";
echo "<td width="6%"><span class="style4">C-D Proof</span></td>";
echo "<td width="7%"><span class="style4">VAC Proof</span></td>";
echo "</tr>";
while ($data = mysql_fetch_assoc($result)) {
echo "<tr>";
echo "<td width="8%"><span class="style1">";
echo $data["date"];
echo "</span></td>";
echo "<td width="23%"><span class="style1">";
echo $data["name"];
echo "</span> </td>";
echo "<td width="47%"><span class="style1">";
echo $data["info"];
echo "</span> </td>";
if ($data["cdproof"] == YES) {
echo "<td width="6%" bgcolor="#00FF00" bordercolor="#00FF00" bordercolordark="#000000" bordercolorlight="#00FF00"><span class="style5">YES</span></span></td>";
}
if ($data["cdproof"] == NO) {
echo "<td bgcolor="#FF0000" bordercolordark="#FF0000" bordercolor="#FF0000" bordercolorlight="#FF0000"><span class="style5">NO</span></span></td>";
}
echo "<td width="7%" bordercolor="#00FF00" bordercolorlight="#00FF00" bordercolordark="#000000" bgcolor="#00FF00" class="style5">";
echo $data["vacproof"];
echo "</span></td>";
echo "</tr>";
echo mysql_error();
}
echo "</table>";
?>
ERRORS FOR ---^ PAGE:
Notice: Use of undefined constant YES - assumed 'YES' in cheatnetwork.php on line 52
YES
Notice: Use of undefined constant NO - assumed 'NO' in cheatnetwork.php on line 55
YES
Notice: Use of undefined constant YES - assumed 'YES' in cheatnetwork.php on line 52
Notice: Use of undefined constant NO - assumed 'NO' in cheatnetwork.php on line 55
how i fix that?
Last edited by
bla5e on Sat Jun 05, 2004 2:06 pm, edited 1 time in total.
bla5e
Forum Contributor
Posts: 234 Joined: Tue May 25, 2004 4:28 pm
Post
by bla5e » Sat Jun 05, 2004 12:21 pm
nope and i dont get any mySQL errors either
markl999
DevNet Resident
Posts: 1972 Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)
Post
by markl999 » Sat Jun 05, 2004 12:27 pm
Try using error_reporting(E_ALL); at the top, eg
You will get some errors/warnings as the lines at the top ($date = $_POST["date"]; etc..) should be inside the if(){ .. } bit. And you might also want to do this instead:
Code: Select all
if (!empty($_POST['submitted']) && $_POST["submitted"] == 1){
evilmonkey
Forum Regular
Posts: 823 Joined: Sun Oct 06, 2002 1:24 pm
Location: Toronto, Canada
Post
by evilmonkey » Sat Jun 05, 2004 1:17 pm
to your $result command, add or die (mysql_error());. Might shed some light on the problem. The most common errors come from MySQL not PHP, and those are so hard to debug. I know from expirience.
bla5e
Forum Contributor
Posts: 234 Joined: Tue May 25, 2004 4:28 pm
Post
by bla5e » Sat Jun 05, 2004 1:43 pm
markl999 wrote: Try using error_reporting(E_ALL); at the top, eg
You will get some errors/warnings as the lines at the top ($date = $_POST["date"]; etc..)
ya i did..
Notice: Undefined index: date in cheatsubmit.php on line 25
Notice: Undefined index: name in ccheatsubmit.php on line 26
Notice: Undefined index: info in cheatsubmit.php on line 27
Notice: Undefined index: cdproof in cheatsubmit.php on line 28
Notice: Undefined index: vacproof in cheatsubmit.php on line 29
but they are undefined until the submit button, aka filled in.. so i dont really think thats the problem, and after i hit the "submit" button, the errors go away but i still dont get the echo of "cheats submitted"
bla5e
Forum Contributor
Posts: 234 Joined: Tue May 25, 2004 4:28 pm
Post
by bla5e » Sat Jun 05, 2004 1:47 pm
Heres updated source:
Code: Select all
<?php
error_reporting(E_ALL);
$date = $_POST["date"];
$name = $_POST["name"];
$info = $_POST["info"];
$cdproof = $_POST["cdproof"];
$vacproof = $_POST["vacproof"];
if (!empty($_POST['submitted']) && $_POST["submitted"] == 1){
$dbh=mysql_connect ("localhost", "<< REMOVED >>", " << REMOVED >>") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("cheats");
$sql = "INSERT INTO cheats VALUES ('$date', '$name', '$info', '$cdproof', '$vacproof')";
$result = mysql_query($sql, $dbh);
echo mysql_error();
echo "Cheats submitted!";
}
?>
<form action=cheatsubmit.php method=post>
<< BODY OF THE FORM REMOVED >>
<input type="image" src="submit.png" value="1" name=submitted>
<?php echo mysql_error(); ?>
evilmonkey
Forum Regular
Posts: 823 Joined: Sun Oct 06, 2002 1:24 pm
Location: Toronto, Canada
Post
by evilmonkey » Sat Jun 05, 2004 1:53 pm
Code: Select all
<?php
if (!empty($_POST['submitted']) && $_POST["submitted"] == 1){
error_reporting(E_ALL);
$date = $_POST["date"];
$name = $_POST["name"];
$info = $_POST["info"];
$cdproof = $_POST["cdproof"];
$vacproof = $_POST["vacproof"];
$dbh=mysql_connect ("localhost", "<< REMOVED >>", " << REMOVED >>") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("cheats");
$sql = "INSERT INTO cheats VALUES ('$date', '$name', '$info', '$cdproof', '$vacproof')";
$result = mysql_query($sql, $dbh);
echo mysql_error();
echo "Cheats submitted!";
}
else
{
//display the form
?>
<form action=cheatsubmit.php method=post>
<< BODY OF THE FORM REMOVED >>
<input type="image" src="submit.png" value="1" name=submitted>
<?php } echo mysql_error(); ?>
bla5e
Forum Contributor
Posts: 234 Joined: Tue May 25, 2004 4:28 pm
Post
by bla5e » Sat Jun 05, 2004 2:05 pm
SUBMIT FORM :
Code: Select all
<?php
if (!empty($_POST['submitted']) && $_POST["submitted"] == 1){
error_reporting(E_ALL);
$date = $_POST["date"];
$name = $_POST["name"];
$info = $_POST["info"];
$cdproof = $_POST["cdproof"];
$vacproof = $_POST["vacproof"];
$dbh=mysql_connect ("localhost", "root", "") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("cheats");
$sql = "INSERT INTO cheats VALUES ('$date', '$name', '$info', '$cdproof', '$vacproof')";
$result = mysql_query($sql, $dbh);
echo mysql_error();
echo "Cheats submitted!";
}
else
{
//display the form
?>
<form action=cheatsubmit.php method=post>
<< BODY OF FORM REMOVED >>
<input type="hidden" name="submitted" value="1">
<input type="image" name=submitted src="submit.png" value="1">
<?php } echo mysql_error(); ?>
PROBLEMS: Wont submit data to mySQL db
Last edited by
bla5e on Sat Jun 05, 2004 2:13 pm, edited 1 time in total.
markl999
DevNet Resident
Posts: 1972 Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)
Post
by markl999 » Sat Jun 05, 2004 2:10 pm
Those errors just relate to you doing == YES and == NO instead of == 'YES' and == 'NO'
bla5e
Forum Contributor
Posts: 234 Joined: Tue May 25, 2004 4:28 pm
Post
by bla5e » Sat Jun 05, 2004 2:13 pm
ya i got it thanks =]
bla5e
Forum Contributor
Posts: 234 Joined: Tue May 25, 2004 4:28 pm
Post
by bla5e » Sat Jun 05, 2004 2:18 pm
evilmonkey fixed it for me!! good jobb!!
evilmonkey
Forum Regular
Posts: 823 Joined: Sun Oct 06, 2002 1:24 pm
Location: Toronto, Canada
Post
by evilmonkey » Sat Jun 05, 2004 2:23 pm
Thank you, thank you. *takes a bow*
Cheers!