• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

[PHP] News Manager ( first script )

Kavvson

Gdy boli cie glowa wez
Joined
Jun 25, 2008
Messages
1,177
Reaction score
72
Location
Poland
So i managed to make my "first" this kind of script.. based on archez ( he gave me this do == system )

But there is a update error while i want to insert values in the database error:

echo 'There was an error during the updating process!';

PHP:
<?PHP
    $array = array(
    '1' => 'Topic',
    '2' => 'Author',
    '3' => 'Image_Id',
    '4' => 'Hide_News');
    
    
        if($_REQUEST['do'] == 'index')
    { ?>
<div class="column" id="right"></div>
<div id="tab2" class="tab_content">
  <div class="portlet">
        <div class="portlet-header fixed"><img src="images/icons/user.gif" width="16" height="16" alt="" />Item details</div>
        <div class="portlet-content nopadding">
        <form action="#" method="post">  <table cellspacing="0" cellpadding="0" width="100%" summary="" id="box-table-a">
         <table cellspacing="0" cellpadding="0" width="100%" summary="" id="box-table-a">
            <thead>
              <tr>
              <th width="102" scope="col">#</th>
              <th width="136" scope="col">Title</th>
    
                <th width="136" scope="col">Author</th>
                <th width="136" scope="col">image_id</th>
                            <th width="102" scope="col">hide_news</th>
              <th width="102" scope="col">text</th>
              </tr>
            </thead>
            
            <tbody>
<?PHP
$i=1;
$data = $mysqli->query("SELECT * FROM `z_news_big`");
    while($item = $data->fetch_array()){
    echo "<tr><td>".$i."</td>";
        echo "<td>".$item['topic']."</td>";

        echo "<td>".$item['author']."</td>";
        echo "<td>".$item['image_id']."</td>";
        echo "<td>".$item['hide_news']."</td>";
        echo "<td><textarea class='tinymce'>".$item['text']."</textarea></td></tr>";
        $i++;
        

        }
        unset ($data);  

?>

</tbody>
</table>
 </form>
</div>
</div>
</div>
<?PHP
    echo '<form action="?page=news&do=update" method="post">';
$i=1;
$data = $mysqli->query("SELECT * FROM `z_news_big`");
        echo '<table>';
    while($a = $data->fetch_array()){

        echo '<tr><td width="20%">'.$array[1].' :<input type="text" name="'.$a['topic'].'" value="'.$a['topic'].'"></td>';
        echo '<td>'.$array[2].' : <input type="text" name="'.$a['author'].'" value="'.$a['author'].'"></td>';
        echo '<td>'.$array[3].' : <input type="text" name="'.$a['image_id'].'" value="'.$a['image_id'].'"></td>';
        echo '<td>'.$array[4].' : <input type="text" name="'.$a['hide_news'].'" value="'.$a['hide_news'].'"></td>';
        //echo ''.$a['text'].' : <textarea name="'.$a['text'].'>'.$item['text'].'</textarea>';
}
        echo '<tr><td><input type="submit" value="Update" /></td><td><input type="reset" value="Clear" /></td></tr>';
        unset ($data);  
        echo '</tr></table>';
        echo '</form>';
}

    if($_REQUEST['do'] == 'update')
    {
        if(!$_POST)
        {
            echo 'error';
        }
        else
        {
    $array1 = array(
    '1' => 'topic',
    '2' => 'author',
    '3' => 'image_id',
    '4' => 'hide_news');
            $query .= 'UPDATE `z_news_big` SET ';
            
            foreach($array1 as $c => $d)
            {
                $query .= '`'.strip_tags($d).'` = "'.strip_tags($_POST[$d]).'", ';
            }
            
            
            $execute = $mysqli->query($query);
            
            if($execute)
            {
                echo 'Done!';
            }
            else
            {
                echo 'There was an error during the updating process!';
            }
        }
    }
?>
 
Parse error: syntax error, unexpected T_VARIABLE in C:\xampp\htdocs\Adminpanel1\pages\news.php on line 96

PHP:
if($_REQUEST['do'] == 'update')
	{
		if(!$_POST)
		{
			echo 'error';
		}
		else
		{
	$array1 = array(
	'1' => 'topic',
	'2' => 'author',
	'3' => 'image_id',
	'4' => 'hide_news');
			$query .= 'UPDATE `z_news_big` SET ';
			
			foreach($array1 as $c => $d)
			{
				$query .= '`'.strip_tags($d).'` = "'.strip_tags($_POST[$d]).'", ';
			}
			$mysqli->query($query) or die $mysqli->error();
			
			$execute = $mysqli->query($query);
			
			if($execute)
			{
				echo 'Done!';
			}
			else
			{
				echo 'There was an error during the updating process!';
			}
			
		}
		
	}
 
Code:
$array1 = array(
    1 => 'topic',
    2 => 'author',
    3 => 'image_id',
    4 => 'hide_news'
);

//...

foreach($array1 as $c => $d)
	if($c != count($array1))
		$query .= '`'.strip_tags($d).'` = \''.strip_tags($_POST[$d]).'\', ';
	else
		$query .= '`'.strip_tags($d).'` = \''.strip_tags($_POST[$d]).'\';';
 
Still error

should be

PHP:
	if($c != count($array1))
		$query .= '`'.strip_tags($d).'` = \''.strip_tags($_POST[$d]).'\', ';
	else
		$query .= '`'.strip_tags($d).'` = \''.strip_tags($_POST[$d]).'\'';
 
PHP:
<?PHP

	$array = array(
	'1' => 'Topic',
	'2' => 'Author',
	'3' => 'Image_Id',
	'4' => 'Hide_News');
	
	
		if($_REQUEST['do'] == 'index')
	{ ?>
<div class="column" id="right"></div>
<div id="tab2" class="tab_content">
  <div class="portlet">
        <div class="portlet-header fixed"><img src="images/icons/user.gif" width="16" height="16" alt="" />Item details</div>
		<div class="portlet-content nopadding">
        <form action="#" method="post">  <table cellspacing="0" cellpadding="0" width="100%" summary="" id="box-table-a">
		 <table cellspacing="0" cellpadding="0" width="100%" summary="" id="box-table-a">
            <thead>
              <tr>
			  <th width="102" scope="col">#</th>
			  <th width="136" scope="col">Title</th>
	
				<th width="136" scope="col">Author</th>
			    <th width="136" scope="col">image_id</th>
							<th width="102" scope="col">hide_news</th>
              <th width="102" scope="col">text</th>
              </tr>
            </thead>
			
            <tbody>
<?PHP
$i=1;
$data = $mysqli->query("SELECT * FROM `z_news_big`");
	while($item = $data->fetch_array()){
	echo "<tr><td>".$i."</td>";
		echo "<td>".$item['topic']."</td>";

		echo "<td>".$item['author']."</td>";
		echo "<td>".$item['image_id']."</td>";
		echo "<td>".$item['hide_news']."</td>";
		echo "<td><textarea class='tinymce'>".$item['text']."</textarea></td></tr>";
		$i++;
		

		}
		unset ($data);  

?>

</tbody>
</table>
 </form>
</div>
</div>
</div>
<?PHP

	echo '<form action="?page=news&do=update" method="post">';
$i=1;
$data = $mysqli->query("SELECT * FROM `z_news_big`");
		echo '<table>';
	while($a = $data->fetch_array()){

		echo '<tr><td width="20%">'.$array[1].' :<input type="text" name="'.$a['topic'].'" value="'.$a['topic'].'"></td>';
		echo '<td>'.$array[2].' : <input type="text" name="'.$a['author'].'" value="'.$a['author'].'"></td>';
		echo '<td>'.$array[3].' : <input type="text" name="'.$a['image_id'].'" value="'.$a['image_id'].'"></td>';
		echo '<td>'.$array[4].' : <input type="text" name="'.$a['hide_news'].'" value="'.$a['hide_news'].'"></td>';
		//echo ''.$a['text'].' : <textarea name="'.$a['text'].'>'.$item['text'].'</textarea>';
}
		echo '<tr><td><input type="submit" value="Update" /></td><td><input type="reset" value="Clear" /></td></tr>';
		unset ($data);  
		echo '</tr></table>';
		echo '</form>';
}

	if($_REQUEST['do'] == 'update')
	{
		if(!$_POST)
		{
			echo 'error';
		}
		else
		{
$array1 = array(
    1 => 'topic',
    2 => 'author',
    3 => 'image_id',
    4 => 'hide_news'
);

			$query = 'UPDATE `z_news_big` SET ';
			
			foreach($array1 as $c => $d){
		
			
	if($c != count($array1))
		$query = '`'.strip_tags($d).'` = \''.strip_tags($_POST[$d]).'\', ';
	else
		$query = '`'.strip_tags($d).'` = \''.strip_tags($_POST[$d]).'\'';
		}
		$execute($query);
		
			if($execute)
			{
				echo 'Done!';
			}
			else
			{
				echo 'There was an error during the updating process!';
			}
			
		}
		
	}
	
?>

Fatal error: Function name must be a string in C:\xampp\htdocs\Adminpanel1\pages\news.php on line 102

102 : $execute($query);
 
Still an error There was an error during the updating process!


Can someone recode the UPDATE part?
 
Last edited:
I made a new script to add a news

PHP:
if($_REQUEST['do'] == 'add')
    {
$array = array(
    1 => 'Topic',
    2 => 'Author',
    3 => 'Image_Id',
    4 => 'Hide_News');
    
    
if ($_POST['Post'])
{
$hide_news =$_POST['hide_news'];
$date =$_POST['date'];
$author =$_POST['author'];
$author_id =$_POST['author_id'];
$image_id =$_POST['image_id'];
$topic =$_POST['topic'];
$text =$_POST['text'];

$p="INSERT INTO z_news_big(hide_news,date,author,author_id,image_id,topic,text) values('$hide_news','$date','$author','$author_id','$image_id','$topic','$text')";
    $execute = $mysqli->query($p);
print "Your news was posted successfully.<br />";
}
else

{
print "<form action='$PHPSELF' method='POST'>";
print "Topic - <input type='text' name='topic'><br />";
print "text - <textarea rows='5' cols='25' name='text'></textarea><br />";
print "hide_news - <input type='text' name='hide_news'><br />";
print "date -  <input type='text' name='date'><br />";

print "author -  <input type='text' name='author'><br />";
print "author_id -  <input type='text' name='author_id'><br />";
print "image_id -  <input type='text' name='image_id'><br />";


print "<input type='submit' name='Post' value='Post News!'><br />";
}
}

Can someone verify it? Since i think each refresh add's blank fields.

Also how would it be possible to display all news

PHP:
<?PHP
$i=1;
$data = $mysqli->query("SELECT * FROM `z_news_big`");
    while($item = $data->fetch_array()){
    echo "<tr><td>".$i."</td>";
        echo "<td>".$item['topic']."</td>";

        echo "<td>".$item['author']."</td>";
        echo "<td>".$item['image_id']."</td>";
        echo "<td>".$item['hide_news']."</td>";
        echo "<td><textarea class='tinymce'>".$item['text']."</textarea></td></tr>";
        $i++;
        

        }
        unset ($data);  

?>

With an edit option. Like ?page=news&do=index&edit=1
 
Its really bad now :P I can't do anything i need help. I made few modules but only 1 works the index :D

PHP:
<?php
if($_REQUEST['do'] == 'add')
    {
$array = array(
    1 => 'Topic',
    2 => 'Author',
    3 => 'Image_Id',
    4 => 'Hide_News');
    
    
if ($_POST['Post'])
{
$hide_news =$_POST['hide_news'];
$date =$_POST['date'];
$author =$_POST['author'];
$author_id =$_POST['author_id'];
$image_id =$_POST['image_id'];
$topic =$_POST['topic'];
$text =$_POST['text'];

$p="INSERT INTO z_news_big(hide_news,date,author,author_id,image_id,topic,text) values('$hide_news','$date','$author','$author_id','$image_id','$topic','$text')";
    $execute = $mysqli->query($p);
print "Your news was posted successfully.<br />";
}
else

{
print "<form action='$PHPSELF' method='POST'>";
print "Topic - <input type='text' name='topic'><br />";
print "text - <textarea rows='5' cols='25' name='text'></textarea><br />";
print "hide_news - <input type='text' name='hide_news'><br />";
print "date -  <input type='text' name='date'><br />";

print "author -  <input type='text' name='author'><br />";
print "author_id -  <input type='text' name='author_id'><br />";
print "image_id -  <input type='text' name='image_id'><br />";


print "<input type='submit' name='Post' value='Post News!'><br />";
}
}


if($_REQUEST['do'] == 'delete')
{
    
        $result = $mysqli->query("DELETE FROM `z_news_big` WHERE `z_news_big`.`hide_news` = '$hide_news' AND `z_news_big`.`date` = '$date' AND `z_news_big`.`author_id` = '$author_id' AND `z_news_big`.`image_id` = '$image_id' AND `z_news_big`.`topic` = '$topic' AND `z_news_big`.`text` = '$text' LIMIT 1");

                     echo "<b>News Deleted!<br>You'll be redirected to Home Page after (1) Seconds";
                     //header("location: index.php");
                     echo "<meta http-equiv=Refresh content=1;url=?page=news&do=index>";
}

    $array = array(
    '1' => 'Topic',
    '2' => 'Author',
    '3' => 'Image_Id',
    '4' => 'Hide_News');
    
    
        if($_REQUEST['do'] == 'index')
    { ?>
<div class="column" id="right"></div>
<div id="tab2" class="tab_content">
  <div class="portlet">
        <div class="portlet-header fixed"><img src="images/icons/user.gif" width="16" height="16" alt="" />Item details</div>
        <div class="portlet-content nopadding">
        <form action="#" method="post">  <table cellspacing="0" cellpadding="0" width="100%" summary="" id="box-table-a">
         <table cellspacing="0" cellpadding="0" width="100%" summary="" id="box-table-a">
            <thead>
              <tr>
              <th width="102" scope="col">#</th>
              <th width="136" scope="col">Title</th>
    
                <th width="136" scope="col">Author</th>
                <th width="136" scope="col">image_id</th>
                <th width="102" scope="col">hide_news</th>
              <th width="102" scope="col">text</th>
              <th width="102" scope="col">Action</th>
              </tr>
            </thead>
            
            <tbody>
<?PHP
$i=1;
$data = $mysqli->query("SELECT * FROM `z_news_big`");
    while($item = $data->fetch_array()){
    echo "<tr><td>".$i."</td>";
        echo "<td>".$item['topic']."</td>";

        echo "<td>".$item['author']."</td>";
        echo "<td>".$item['image_id']."</td>";
        echo "<td>".$item['hide_news']."</td>";
        echo "<td><textarea class='tinymce'>".$item['text']."</textarea></td>";
        echo "<td>Delete : <a href='?page=news&do=delete'>Delete</a></td>";
        echo"</tr>";
        $i++;
        

        }
        unset ($data);  

?>

</tbody>
</table>
 </form>
</div>
</div>
</div>

<?PHP

    echo '<form action="?page=news&do=update" method="post">';
$i=1;
$data = $mysqli->query("SELECT * FROM `z_news_big`");
        echo '<table>';
    while($a = $data->fetch_array()){

        echo '<tr><td width="20%">'.$array[1].' :<input type="text" name="'.$a['topic'].'" value="'.$a['topic'].'"></td>';
        echo '<td>'.$array[2].' : <input type="text" name="'.$a['author'].'" value="'.$a['author'].'"></td>';
        echo '<td>'.$array[3].' : <input type="text" name="'.$a['image_id'].'" value="'.$a['image_id'].'"></td>';
        echo '<td>'.$array[4].' : <input type="text" name="'.$a['hide_news'].'" value="'.$a['hide_news'].'"></td>';
        echo '<td>'.$a['text'].' : '.$item['text'].'</td>';
}
        echo '<tr><td><input type="submit" value="Update" /></td><td><input type="reset" value="Clear" /></td></tr>';
        unset ($data);  
        echo '</tr></table>';
        echo '</form>';
}

    if($_REQUEST['do'] == 'update')
    {
        if(!$_POST)
        {
            
        }
        else
        {
        $array1 = array(
    1 => 'topic',
    2 => 'author',
    3 => 'image_id',
    4 => 'hide_news'
);
            $query .= 'UPDATE `players` SET ';
            
            foreach($array as $c => $d)
            {
                $query .= '`'.strip_tags($d).'` = "'.strip_tags($_POST[$d]).'", ';
            }
            
            $query .= $field.' WHERE `topic` = ""';
            
            $execute = $mysqli->query($query);
            
            if($execute)
            {
                echo 'Done!';
            }
            else
            {
                echo 'There was an error during the updating process!';
            }
        }
    }
    

    
?>

The delete and update part doesn't work
 
Back
Top