Jump to content

Catchable fatal error: Object of class mysqli could not be converted to string


Go to solution Solved by lauren_etherington,

Recommended Posts

  • Solution

Okay so I have an update for anyone else who has this problem.

I actually have the query working now and pulling the info based on the ID thanks to changing an i to an s.

 

So when the user clicks Edit on the list of news articles it runs this code:

function editnews($i)

{
	ini_set('display_errors',1);
	error_reporting(E_ALL);

	$conn = mysqli_connect("mysqli connection string");
	
	if (mysqli_connect_errno()) {
		printf("Connect failed: %s\n", mysqli_connect_error());
		exit();
	}
	
	$enquery =  "SELECT * FROM news WHERE newsid='$i'";
	$enresult = mysqli_query($conn, $enquery) or trigger_error($enquery . ' - has encountered an error at:<br />');

	if ($enresult) {

	while ($enrow = mysqli_fetch_array($enresult)) {

	echo "
				<form enctype='multipart/form-data' action='functions/newsedit.php' method='post'>
				<table>

					<tr>
					<td>News Ref:</td>
					<td>" . $i . "<input type='hidden' name='newsid' value='" . $i . "' /><input type='hidden' name='oldim' value='" . $enrow['newsimage'] . "' /></td>
				</tr>


					<tr>
						<td>Title:</td>
						<td><input type='text' name='title' value='" . $enrow['newstitle'] . "' size='100' /></td>
					</tr>

						<tr>
						<td>Author:</td>
						<td><input type='text' name='author' value='" . $enrow['newsauthor'] . "' size='100' /></td>
					</tr>

					<tr>
						<td>Status:</td>
						<td><select name='stat'><option value='enabled' ";
						if ($enrow['newsstatus'] == "enabled")
						{
							echo "selected='selected' ";
						}
						echo ">Enabled</option><option value='disabled' ";
						if ($enrow['newsstatus'] == "disabled")
						{
							echo "selected='selected' ";
						}
						echo "}>Disabled</option></select>
					</td>
					</tr>

					<tr>
						<td>Snippettext:</td>
						<td><textarea name='snip' rows='6' cols='80'>" . $enrow['newssnippet'] . "</textarea></td>
					</tr>

					<tr>
						<td>News story:</td>
						<td><textarea name='stry' rows='20' cols='80'>" . $enrow['newsarticle'] . "</textarea></td>
					</tr>


					<tr>
						<td>Current image:</td>
						<td>" . $enrow['newsimage'] . " - <a href='news/" . $enrow['newsimage'] . "' target='_blank'>View Image</a></td>
					</tr>

					<tr>
						<td>Change Image:</td>
						<td><input type='file' name='file'></td>
					</tr>

					<tr>
						<td colspan='2'><input type='submit' name='submit' value='Edit' /></td>
					</tr>
				</table>
				</form>
			";
				}

		}
			else {
			echo "Oh noes, an error!";
		}
}

?>

This directs to the HTML page where the form will be displayed with this code (This code is disaplyed at the very top of the document - above the doc type:

<?php
include_once("functions/newseditform.php");
$s = $_GET['i'];
?>

While this little bit of code sits somewhere in the body.

<?php
 editnews($s)
 ?>

-- Thanks for all the help guys!!! :happy-04:

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.