Jump to content

Recommended Posts

ok i get his errors it updates the table idk get it

 

 

Warning: mysql_query() [FUNCTION.MYSQL-QUERY]: Access denied for user 'ezgaming'@'localhost' (using password: NO) in /home/ezgaming/public_html/adminpanel.php on line 22

 

Warning: mysql_query() [FUNCTION.MYSQL-QUERY]: A link to the server could not be established in /home/ezgaming/public_html/adminpanel.php on line 22

 

heres my code

<?php
session_start();
$username = $_SESSION['username'];
?>
<?php 

if(isset($_POST['update'])){

require "scripts/connect.php";

// Set some values to go into the table fields for this person(record) 
$latestnews = $_POST ['latestnews']; 
$maincontent = $_POST ['maincontent']; 
$mainvideos = $_POST ['mainvideos']; 

}

// Build the sql command string 
$sqlCommand = "UPDATE content SET latestnews='$latestnews', maincontent='$maincontent', mainvideos='$mainvideos'";

// Execute the query here now 
$query = mysql_query($sqlCommand);


?>
<?php

require "scripts/connect.php";

$sqlCommand = ("SELECT * FROM content");
$query = mysql_query($sqlCommand);

while ($row = mysql_fetch_array($query)) { 
    // Gather all $row values into local variables for easier usage in output
    $latestnews = $row ['latestnews'];
    $maincontent= $row ['maincontent'];
    $mainvideos = $row ['mainvideos'];
}

?>
<?php
require "header.php";
?>
<?php if ($username){?>

<?php

echo "<br/><br/>"."Welcome <b>$username</b>, <a href='logout.php'>Logout</a href>"."<br /><br />";

?>


<?php

echo "<center><h2>Hey $username! What do you want to do?</h2></center>";

?>

<div id="ahome">

<form action='adminpanel.php' method='POST'>
<table>
<tr>
<td>Latest News</td>
<td><textarea name='latestnews' cols=50 rows=15><?php echo $latestnews; ?></textarea></td>
</tr>
<tr>
<td>Main Content</td>
<td><textarea name='maincontent' cols=50 rows=15><?php echo $maincontent; ?></textarea></td>
</tr>
<tr>
<td>Main Videos</td>
<td><textarea name='mainvideos' cols=50 rows=15><?php echo  $mainvideos; ?></textarea></td>
</tr>
<tr>
<td></td>
<td><input type='submit' name='update' value='Update'></td>
</tr>
</table>
</form>


</div>

<?php
}
else
echo "<font color='red'><center><h1>You must be logged in to view this page.</h1></center></font>";

?>
<?php
require "footer.php";
?>

Link to comment
https://forums.phpfreaks.com/topic/250519-help-plz/
Share on other sites

Your first require "scripts/connect.php"; statement is INSIDE a conditional if(){} statement, so no connection is made until the form is submitted. The logic for the first query is outside of and after that if(){} conditional statement and it executes every time the page is requested and the first time the page is requested there is no connection to the database.

 

ALL your logic to process the form data should be INSIDE that if(){} conditional statement and if everything you are doing on the page requires a database connection, put ONE require "scripts/connect.php"; statement at the start of the code (you currently have it in two places.)

Link to comment
https://forums.phpfreaks.com/topic/250519-help-plz/#findComment-1285307
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.