Page 1 of 1

mySQL/PHP Problem

Posted: Sat Jun 05, 2004 11:55 am
by bla5e
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?

Posted: Sat Jun 05, 2004 11:57 am
by John Cartwright
Does this get outputteD?

Code: Select all

<?php
echo "Cheats submitted!"; 
?>

Posted: Sat Jun 05, 2004 12:21 pm
by bla5e
nope and i dont get any mySQL errors either

Posted: Sat Jun 05, 2004 12:27 pm
by markl999
Try using error_reporting(E_ALL); at the top, eg

Code: Select all

<?php
error_reporting(E_ALL);
...
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){

Posted: Sat Jun 05, 2004 1:17 pm
by evilmonkey
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. :x

Posted: Sat Jun 05, 2004 1:43 pm
by bla5e
markl999 wrote:Try using error_reporting(E_ALL); at the top, eg

Code: Select all

<?php
error_reporting(E_ALL);
...
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"

Posted: Sat Jun 05, 2004 1:47 pm
by bla5e
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(); ?>

Posted: Sat Jun 05, 2004 1:53 pm
by evilmonkey

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(); ?>

Posted: Sat Jun 05, 2004 2:05 pm
by bla5e
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

Posted: Sat Jun 05, 2004 2:10 pm
by markl999
Those errors just relate to you doing == YES and == NO instead of == 'YES' and == 'NO'

Posted: Sat Jun 05, 2004 2:13 pm
by bla5e
ya i got it thanks =]

Posted: Sat Jun 05, 2004 2:18 pm
by bla5e
evilmonkey fixed it for me!! good jobb!!

Posted: Sat Jun 05, 2004 2:23 pm
by evilmonkey
Thank you, thank you. *takes a bow*

:D Cheers!