ecabrera Posted November 5, 2011 Share Posted November 5, 2011 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"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/250519-help-plz/ Share on other sites More sharing options...
seany123 Posted November 5, 2011 Share Posted November 5, 2011 its failing to connect to the database, make sure the path to connect.php is correct, if its not that then post the code for connect.php Quote Link to comment https://forums.phpfreaks.com/topic/250519-help-plz/#findComment-1285304 Share on other sites More sharing options...
ecabrera Posted November 5, 2011 Author Share Posted November 5, 2011 wait but if its failing to connect to the bd how come it updates everything inside the db Quote Link to comment https://forums.phpfreaks.com/topic/250519-help-plz/#findComment-1285305 Share on other sites More sharing options...
PFMaBiSmAd Posted November 5, 2011 Share Posted November 5, 2011 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.) Quote Link to comment https://forums.phpfreaks.com/topic/250519-help-plz/#findComment-1285307 Share on other sites More sharing options...
ecabrera Posted November 5, 2011 Author Share Posted November 5, 2011 thanks got it to work now Quote Link to comment https://forums.phpfreaks.com/topic/250519-help-plz/#findComment-1285316 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.