DasHaas Posted December 7, 2007 Share Posted December 7, 2007 Im working on a database hosted by ipowerweb and I am having problems interacting with the database. I can view the data in the tables, delete the data, but I cant edit the data or add new data from my php form. I have used this script on other servers and it has worked like a champ. I called the host's tech support line and after 20 minutes of waiting they are saying its my script that has the problem. Im not an expert php programmer but this script works fine on my site that is hosted by another company. I gave the login im using full access to the database, but I still cant edit or add data to the table. Any suggestions?? :'( Quote Link to comment https://forums.phpfreaks.com/topic/80659-solved-connection-problems-phpmysql/ Share on other sites More sharing options...
revraz Posted December 7, 2007 Share Posted December 7, 2007 Still sounds like you don't have full rights. Do you have access to phpmyadmin? If so, do you use the same id/pw that you use in your code and do you have rights there? Quote Link to comment https://forums.phpfreaks.com/topic/80659-solved-connection-problems-phpmysql/#findComment-409074 Share on other sites More sharing options...
cunoodle2 Posted December 7, 2007 Share Posted December 7, 2007 please post code examples and/or any error messages you are getting. Without that we cannot assist you any further. Quote Link to comment https://forums.phpfreaks.com/topic/80659-solved-connection-problems-phpmysql/#findComment-409076 Share on other sites More sharing options...
DasHaas Posted December 7, 2007 Author Share Posted December 7, 2007 i use the same id/pw that gets me into phpMyAdmin in my script. the following script populates the text fields with the table data but when i make a change and submit the for after a second or so I get the "page cannot be found" error. <html> <head> <link href="css/StyleSheet1.css" rel="stylesheet" type="text/css"> <body> <!-- standard page header begins --> <table width="100%" class="table1"> <tr> <td><div align="center" class="text2">EDIT NEWS ARTICLE</div></td> </tr> </table> <br> <!-- standard page header ends --> <?php // includes include('includes/PXS_Conf.php'); include('includes/PXS_Functions.php'); // form not yet submitted // display initial form with values pre-filled if (!$_POST['submit']) { // check for record ID if ((!isset($_GET['id']) || trim($_GET['id']) == '')) { die('Missing record ID!'); } // open database connection $connection = mysql_connect($host, $user, $pass) or die ('Unable to connect to MySql server!'); // select database mysql_select_db($db) or die ('Unable to select database!'); // generate and execute query $id = $_GET['id']; $query = "SELECT Title, Content FROM PXS_News WHERE id = '$id'"; $result = mysql_query($query) or die ("Error in query: $query. " . mysql_error()); // if a result is returned if (mysql_num_rows($result) > 0) { // turn it into an object $row = mysql_fetch_object($result); // print form with values pre-filled ?> <table cellpadding="5" cellspacing="5" class="table1"> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST"> <input type="hidden" name="id" value="<?php echo $id; ?>"> <tr> <td valign="top"><b class="text5">Title</b></td> <td> <input name="Title" type="text" class="table2" id="Title" value="<?php echo $row->Title; ?>" size="50" maxlength="250"> </td> </tr> <tr> <td valign="top"><b class="text5">Content</b></td> <td> <textarea name="Content" cols="47" rows="10" class="table2" id="Content"><?php echo $row->Content; ?></textarea> </td> </tr> <tr> <td colspan=2> <input type="Submit" name="submit" value="Update"> </td> </tr> </form> </table> <?php } // no result returned // print graceful error message else { echo 'That news article could not be located in the database'; } } // form submitted // start processing it else { // set up error list array $errorList = array(); $title = ucfirst($_POST['Title']); $content = ucfirst($_POST['Content']); $id = $_POST['id']; // check for record ID if ((!isset($_POST['id']) || trim($_POST['id']) == '')) { die ('Missing record ID!'); } // validate text input fields if (trim($_POST['Title']) == '') { $errorList[] = 'Please enter an article title'; } if (trim($_POST['Content']) == '') { $errorList[] = "Please enter article content"; } // check for errors // if none found... if (sizeof($errorList) == 0) { // generate and execute query $query = "UPDATE PXS_News SET Title = '$title', Content = '$Content' WHERE id = '$id'"; $result = mysql_query($query) or die ("Error in query: $query. " . mysql_error()); // close database connection mysql_close($connection); // print result echo '<center><a href=PXS_ListNews.php>Update successful click here to go back to the article list</a></center>'; } else { // errors occurred // print as list echo 'The following errors were encountered:'; echo '<br>'; echo '<ul>'; for ($x=0; $x<sizeof($errorList); $x++) { echo "<li>$errorList[$x]"; } echo '</ul>'; } } ?> <!-- standard page footer begins --> <br> <table width="100%" class="table1"> <tr> <td><div align="center" class="text1"><font size="2">Copyright © 2006 All Rights Reserved </font></div></td> </tr> </table> <!-- standard page footer ends --> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/80659-solved-connection-problems-phpmysql/#findComment-409083 Share on other sites More sharing options...
DasHaas Posted December 9, 2007 Author Share Posted December 9, 2007 is this the best/only way to connect to a mysql db? $connection = mysql_connect($host, $user, $pass) or die ('Unable to connect to MySql server!'); Quote Link to comment https://forums.phpfreaks.com/topic/80659-solved-connection-problems-phpmysql/#findComment-410051 Share on other sites More sharing options...
revraz Posted December 9, 2007 Share Posted December 9, 2007 From PHP, its the only way, unless you use mysql 5, then you can use mysqli instead. Quote Link to comment https://forums.phpfreaks.com/topic/80659-solved-connection-problems-phpmysql/#findComment-410071 Share on other sites More sharing options...
DasHaas Posted December 9, 2007 Author Share Posted December 9, 2007 thanks, im stumped. i gave the login full rights to the table but i can only delete and view data not add or edit. any suggestions? Quote Link to comment https://forums.phpfreaks.com/topic/80659-solved-connection-problems-phpmysql/#findComment-410073 Share on other sites More sharing options...
revraz Posted December 9, 2007 Share Posted December 9, 2007 page cannot be displayed wouldn't return if you didn't have rights, it would give you a mysql error instead. what is this page's name? Quote Link to comment https://forums.phpfreaks.com/topic/80659-solved-connection-problems-phpmysql/#findComment-410094 Share on other sites More sharing options...
DasHaas Posted December 9, 2007 Author Share Posted December 9, 2007 sorry the error is "Server cannot be found" I have used this script with other hosts and it has worked like a champ. the only difference with this host is that i had to use localhost instead of mysql.server.com Quote Link to comment https://forums.phpfreaks.com/topic/80659-solved-connection-problems-phpmysql/#findComment-410097 Share on other sites More sharing options...
revraz Posted December 9, 2007 Share Posted December 9, 2007 Can you post the exact error? Is it a mysql error or is it a HTML error? Quote Link to comment https://forums.phpfreaks.com/topic/80659-solved-connection-problems-phpmysql/#findComment-410107 Share on other sites More sharing options...
DasHaas Posted December 9, 2007 Author Share Posted December 9, 2007 here is what i get when i submit the form that edits the record in the table. Quote Link to comment https://forums.phpfreaks.com/topic/80659-solved-connection-problems-phpmysql/#findComment-410112 Share on other sites More sharing options...
revraz Posted December 9, 2007 Share Posted December 9, 2007 And the URL indicates the same name as the page you're on? Quote Link to comment https://forums.phpfreaks.com/topic/80659-solved-connection-problems-phpmysql/#findComment-410132 Share on other sites More sharing options...
revraz Posted December 9, 2007 Share Posted December 9, 2007 Try breaking the page into two files, one with the form and the other with the PHP. Then point the action to the php page instead of itself. Quote Link to comment https://forums.phpfreaks.com/topic/80659-solved-connection-problems-phpmysql/#findComment-410137 Share on other sites More sharing options...
DasHaas Posted December 9, 2007 Author Share Posted December 9, 2007 thanks, that worked. Why would I need to do that on this server, but other servers can process everything in one page? Quote Link to comment https://forums.phpfreaks.com/topic/80659-solved-connection-problems-phpmysql/#findComment-410424 Share on other sites More sharing options...
revraz Posted December 9, 2007 Share Posted December 9, 2007 Not really sure. I saw something similiar helping someone else out, so I thought it would be worth a try. Quote Link to comment https://forums.phpfreaks.com/topic/80659-solved-connection-problems-phpmysql/#findComment-410426 Share on other sites More sharing options...
DasHaas Posted December 9, 2007 Author Share Posted December 9, 2007 thanks a million for all your help, your a life saver!! Quote Link to comment https://forums.phpfreaks.com/topic/80659-solved-connection-problems-phpmysql/#findComment-410430 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.