bftwofreak Posted November 3, 2009 Share Posted November 3, 2009 $sql = 'UPDATE schedule SET subject="' . $_POST['subject'] . '", date=' . $_POST['date'] . ', location="' . $_POST['location'] . '", description="' . $_POST['description'] . ' WHERE id=' . $_GET['id']; if (mysql_query($sql)) { $body .= 'The scheduled event was updated succesfully!'; } else { $body .= 'There was an error!'; include('edit.php'); $body .= mysql_error(); } In the following code, my form updates my database for a scheduled event. The issue is that my page feeds back that there's an error, but mysql_error() does not report an error and neither does the php error reporting. Any explanations, tips, changes I can make? Quote Link to comment https://forums.phpfreaks.com/topic/180064-solved-mysql_query-returns-error-without-reporting/ Share on other sites More sharing options...
Alex Posted November 3, 2009 Share Posted November 3, 2009 For debugging you should place error_reporting(E_ALL); at the top of your scripts. Glancing at the query it appears that you're missing the closing " for description=" $sql = 'UPDATE schedule SET subject="' . $_POST['subject'] . '", date=' . $_POST['date'] . ', location="' . $_POST['location'] . '", description="' . $_POST['description'] . '" WHERE id=' . $_GET['id']; Quote Link to comment https://forums.phpfreaks.com/topic/180064-solved-mysql_query-returns-error-without-reporting/#findComment-949929 Share on other sites More sharing options...
bftwofreak Posted November 3, 2009 Author Share Posted November 3, 2009 Error reporting is listed in my header page. My index page include()'s my header page and this page. (As well as others with the header page at the top). Edited the query: <?php unset($_SESSION['form'],$_POST['form']); $sql = 'UPDATE schedule SET subject="' . $_POST['subject'] . '", date=' . $_POST['date'] . ', location="' . $_POST['location'] . '", description="' . $_POST['description'] . '" WHERE id=' . $_GET['id']; if (mysql_query($sql)) { $body .= 'The scheduled event was updated succesfully!'; } else { $body .= 'There was an error!'; include('edit.php'); $body .= mysql_error(); } ?> No dice... still returns 'There was an error!', but no reason given. The mysql_query() and the Error reporting show absolutely nothing... Anything else? Quote Link to comment https://forums.phpfreaks.com/topic/180064-solved-mysql_query-returns-error-without-reporting/#findComment-949934 Share on other sites More sharing options...
PFMaBiSmAd Posted November 3, 2009 Share Posted November 3, 2009 What is the code in edit.php? It is likely doing something that is causing mysql_error() to not have a value. Quote Link to comment https://forums.phpfreaks.com/topic/180064-solved-mysql_query-returns-error-without-reporting/#findComment-949937 Share on other sites More sharing options...
bftwofreak Posted November 3, 2009 Author Share Posted November 3, 2009 edit.php: <?php $sql = 'SELECT * FROM schedule WHERE id=' . $_REQUEST['id']; $results = mysql_query($sql); $_SESSION['form'] = rand(0,10000); while ($row = mysql_fetch_array($results)) { $body .= '<form action="?pg=Admin&sub=Schedule&s=e&id=' . $_GET['id'] . '" method="Post" enctype="multipart/form-data"> <input type="hidden" name="form" value="' . $_SESSION['form'] . '"> <table width="100%" border="1px"><tr><td colspan="2" style="text-align:center;">Subject: <input type="text" name="subject" size="30" value="' . $row['subject'] . '"></td></tr> <tr><td style="text-align:left" width="50%">When: <input type="text" name="date" size="30" value="' . date('F j, Y g:i A',$row['date']) . '"></td> <td style="text-align:right" width="50%">Where: <input type="text" name="location" size="30" value="' . $row['location'] . '"></td></tr> <td colspan="2" style="text-align:center"><textarea name="description" rows="5" cols="50">' . $row['description'] . '</textarea></td></tr> <tr><td colspan="2" style="text-align:center;"><input type="submit" value="Post"></td></table></form>'; } ?> I don't really see where or how, but if you find something then please point it out. Quote Link to comment https://forums.phpfreaks.com/topic/180064-solved-mysql_query-returns-error-without-reporting/#findComment-949939 Share on other sites More sharing options...
PFMaBiSmAd Posted November 3, 2009 Share Posted November 3, 2009 mysql_error (PHP 4, PHP 5) mysql_error — Returns the text of the error message from previous MySQL operation You are executing a query in the edit.php code. mysql_error() no longer has the value from the UPDATE query that is failing, it has the value from the SELECT query in edit.php. Quote Link to comment https://forums.phpfreaks.com/topic/180064-solved-mysql_query-returns-error-without-reporting/#findComment-949940 Share on other sites More sharing options...
bftwofreak Posted November 3, 2009 Author Share Posted November 3, 2009 Found the error! Thanks guys! Quote Link to comment https://forums.phpfreaks.com/topic/180064-solved-mysql_query-returns-error-without-reporting/#findComment-949944 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.