Jump to content

[SOLVED] mysql_query() returns error without reporting


bftwofreak

Recommended Posts

$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?

Link to comment
Share on other sites

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'];

Link to comment
Share on other sites

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?

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.