synchro_irl Posted February 25, 2008 Share Posted February 25, 2008 hey guys i really really need some help i have tried everything, but it just aint working i a php file, that pulls all the data from a table in my database, and displays this data in textboxes as seen in the pic here: it dsplays teh data from the table fine, but i have an 'update' button, that is suppose to update the table with all the changes made to the table, by the user. i dont get any errors back, i have included some test code, where i set availability to 111111 for userid 5, to test the connection and it updates fine: mysql_query("UPDATE mytable SET availability = '1111111111' WHERE userid = '5'"); but i still cant get the update to work, i don't know why id really really appreciate some help on this one, no matter how much effort i put into it, i just cant get anywhere. here is the entire code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <!-- Design by Free CSS Templates http://www.freecsstemplates.org Released for free under a Creative Commons Attribution 2.5 License Name : Pluralism Description: A two-column, fixed-width template fit for 1024x768 screen resolutions. Version : 1.0 Released : 20071218 --> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <title>Search4Trade</title> <meta name="keywords" content="" /> <meta name="description" content="" /> <link href="../../../Documents%20and%20Settings/Owner/Desktop/search4trade.net1.4/search4trade.net/style.css" rel="stylesheet" type="text/css" media="screen" /> </head> <body> <div id="wrapper" style="width: 961px; height: 564px"> <div id="wrapper2"> <div id="header"> <div id="logo"> <h1><font size="6"> <a href="edit/search4trade.net/index.html">search4trade.net</a></font></h1> </div> <div id="menu"> <ul> <li></li> <li> <a href="Search1.html">Search </a></li> <li> <a href="Login1.php">Login</a></li> <li> <a href="phpBB2/index.php">Forum</a></li> <li> <a href="registration.html">Register</a></li> <li> <a href="adreviews111.html">Star Rating</a></li> <li> <a href="contact.php">Contact</a></li> </ul> </div> </div> <div id="page"> <div id="content" style="width: 861px; height: 227px"> <div class="post"> <blockquote> <blockquote> <blockquote> <h2 class="title"><a href="#">Welcome to Search4Trade</a></h2> <blockquote> <div class="entry"> <form action="<?php echo $_SERVER['PHP_SELF']?>" method="POST"> <blockquote> <table border="2" width="425" height="169" bgcolor="#FFFFFF"> <tr> <?php $con = mysql_connect("localhost","root","password"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("mydatabase", $con); $result = mysql_query("SELECT * FROM mytable"); echo "<table border='1'> <tr> <th>Type</th> <th>Location</th> <th>Availability</th> <th>StarRating</th> <th>name</th> <th>email</th> <th>username</th> </tr>"; while($row = mysql_fetch_array($result)) { echo "<tr>"; echo '<td><input type="text" value="' . $row['type'] . '"></td>'; echo '<td><input type="text" value="' . $row['location'] . '"></td>'; echo '<td><input type="text" value="' . $row['availability'] . '"></td>'; echo '<td><input type="text" value="' . $row['StarRating'] . '"></td>'; echo '<td><input type="text" value="' . $row['name'] . '"></td>'; echo '<td><input type="text" value="' . $row['email'] . '"></td>'; echo '<td><input type="text" value="' . $row['username'] . '"></td>'; echo "</tr>"; } mysql_close($con); ?> <?php if (isset($_POST['submit'])) { //Database Information $dbhost = "localhost"; $dbname = "mydatabase"; $dbuser = "root"; $dbpass = "clio172"; //Connect to database mysql_connect ( $dbhost, $dbuser, $dbpass)or die("Could not connect: ".mysql_error()); mysql_select_db($dbname) or die(mysql_error()); mysql_query("UPDATE mytable SET availability = '1111111111' WHERE userid = '5'"); $name = $_POST['name']; $email = $_POST['email']; $type = $_POST['type']; $location = $_POST['location']; $availability = $_POST['availability']; $username = $_POST['username']; $query = "INSERT INTO mytable (name, email,Type, location, availability, username) VALUES('$name', '$email','$type','$location','$availability','$username')"; mysql_query($query) or die(mysql_error()); mysql_close(); echo "You have successfully Registered"; } ?> </tr> <tr> <td colspan="2" align="right"> <p align="center" style="text-align: center"> <input type="submit" name="submit" value="Login" style="float: right"></td> </tr> </table> </blockquote> </form> </div> </blockquote> </blockquote> </blockquote> </blockquote> </div> </div> </div> </div> </div> <blockquote> <p align="center"> <span style="font-family: Angsana New;"> Copyright © Search4Trade.net 2008</span> </p> </blockquote> </body> </html> thanks very much for ur help Quote Link to comment Share on other sites More sharing options...
deansatch Posted February 25, 2008 Share Posted February 25, 2008 can you post the actual code you are using instead of the test code: mysql_query("UPDATE mytable SET availability = '1111111111' WHERE userid = '5'"); Quote Link to comment Share on other sites More sharing options...
synchro_irl Posted February 25, 2008 Author Share Posted February 25, 2008 can you post the actual code you are using instead of the test code: mysql_query("UPDATE mytable SET availability = '1111111111' WHERE userid = '5'"); o sorry here it is: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <!-- Design by Free CSS Templates http://www.freecsstemplates.org Released for free under a Creative Commons Attribution 2.5 License Name : Pluralism Description: A two-column, fixed-width template fit for 1024x768 screen resolutions. Version : 1.0 Released : 20071218 --> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <title>Search4Trade</title> <meta name="keywords" content="" /> <meta name="description" content="" /> <link href="../../../Documents%20and%20Settings/Owner/Desktop/search4trade.net1.4/search4trade.net/style.css" rel="stylesheet" type="text/css" media="screen" /> </head> <body> <div id="wrapper" style="width: 961px; height: 564px"> <div id="wrapper2"> <div id="header"> <div id="logo"> <h1><font size="6"> <a href="edit/search4trade.net/index.html">search4trade.net</a></font></h1> </div> <div id="menu"> <ul> <li></li> <li> <a href="Search1.html">Search </a></li> <li> <a href="Login1.php">Login</a></li> <li> <a href="phpBB2/index.php">Forum</a></li> <li> <a href="registration.html">Register</a></li> <li> <a href="adreviews111.html">Star Rating</a></li> <li> <a href="contact.php">Contact</a></li> </ul> </div> </div> <div id="page"> <div id="content" style="width: 861px; height: 227px"> <div class="post"> <blockquote> <blockquote> <blockquote> <h2 class="title"><a href="#">Welcome to Search4Trade</a></h2> <blockquote> <div class="entry"> <form action="<?php echo $_SERVER['PHP_SELF']?>" method="POST"> <blockquote> <table border="2" width="425" height="169" bgcolor="#FFFFFF"> <tr> <?php $con = mysql_connect("localhost","root","clio172"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("mydatabase", $con); $result = mysql_query("SELECT * FROM mytable"); echo "<table border='1'> <tr> <th>Type</th> <th>Location</th> <th>Availability</th> <th>StarRating</th> <th>name</th> <th>email</th> <th>username</th> </tr>"; while($row = mysql_fetch_array($result)) { echo "<tr>"; echo '<td><input type="text" value="' . $row['type'] . '"></td>'; echo '<td><input type="text" value="' . $row['location'] . '"></td>'; echo '<td><input type="text" value="' . $row['availability'] . '"></td>'; echo '<td><input type="text" value="' . $row['StarRating'] . '"></td>'; echo '<td><input type="text" value="' . $row['name'] . '"></td>'; echo '<td><input type="text" value="' . $row['email'] . '"></td>'; echo '<td><input type="text" value="' . $row['username'] . '"></td>'; echo "</tr>"; } mysql_close($con); ?> <?php if (isset($_POST['submit'])) { //Database Information $dbhost = "localhost"; $dbname = "mydatabase"; $dbuser = "root"; $dbpass = "clio172"; //Connect to database mysql_connect ( $dbhost, $dbuser, $dbpass)or die("Could not connect: ".mysql_error()); mysql_select_db($dbname) or die(mysql_error()); mysql_query("UPDATE mytable SET availability = '1111111111' WHERE userid = '5'"); $name = $_POST['name']; $email = $_POST['email']; $type = $_POST['type']; $location = $_POST['location']; $availability = $_POST['availability']; $username = $_POST['username']; $query = "INSERT INTO mytable (name, email,Type, location, availability, username) VALUES('$name', '$email','$type','$location','$availability','$username')"; mysql_query($query) or die(mysql_error()); mysql_close(); echo "You have successfully Registered"; } ?> </tr> <tr> <td colspan="2" align="right"> <p align="center" style="text-align: center"> <input type="submit" name="submit" value="Login" style="float: right"></td> </tr> </table> </blockquote> </form> </div> </blockquote> </blockquote> </blockquote> </blockquote> </div> </div> </div> </div> </div> <blockquote> <p align="center"> <span style="font-family: Angsana New;"> Copyright © Search4Trade.net 2008</span> </p> </blockquote> </body> </html> thanks Quote Link to comment Share on other sites More sharing options...
deansatch Posted February 25, 2008 Share Posted February 25, 2008 that's the same as before Quote Link to comment Share on other sites More sharing options...
synchro_irl Posted February 25, 2008 Author Share Posted February 25, 2008 that's the same as before thats all of the code, it doesnt call anything from outsie outside that php file or that code i posted Quote Link to comment Share on other sites More sharing options...
deansatch Posted February 25, 2008 Share Posted February 25, 2008 what is the actual code you are using that doesn't work. The bit you have instead of the '11111111' and '5' Also, you should have ; mysql_query("UPDATE mytable SET availability = '1111111111' WHERE userid = '5'")or die(mysql_error()); to check for errors in this part as well Quote Link to comment Share on other sites More sharing options...
synchro_irl Posted February 25, 2008 Author Share Posted February 25, 2008 what is the actual code you are using that doesn't work. The bit you have instead of the '11111111' and '5' Also, you should have ; mysql_query("UPDATE mytable SET availability = '1111111111' WHERE userid = '5'")or die(mysql_error()); to check for errors in this part as well \ o im sorry i forgot to mention that. $name = $_POST['name']; $email = $_POST['email']; $type = $_POST['type']; $location = $_POST['location']; $availability = $_POST['availability']; $username = $_POST['username']; $query = "INSERT INTO mytable (name, email,Type, location, availability, username) VALUES('$name', '$email','$type','$location','$availability','$username')"; mysql_query($query) or die(mysql_error()); mysql_close(); this is the code that is giving trouble, its lines 129-141 these lines are suppose to pull the data from teh textboxes and save the textbox entries to the database, while including all changes that the user might have made. but each time i click 'update' i just get a essage reading "update successfull" as coded by myself, but the table has not been updated when i check it, its still the same. thanks for ur help, it really means a lot. Quote Link to comment Share on other sites More sharing options...
deansatch Posted February 25, 2008 Share Posted February 25, 2008 ah! You missed off the name"" attribute in your input fields. So the $_POST part is not going to find anything. echo '<td><input type="text" name="type" value="' . $row['type'] . '"></td>'; echo '<td><input type="text" name="location" value="' . $row['location'] . '"></td>'; etc... Quote Link to comment Share on other sites More sharing options...
synchro_irl Posted February 25, 2008 Author Share Posted February 25, 2008 ah! You missed off the name"" attribute in your input fields. So the $_POST part is not going to find anything. echo '<td><input type="text" name="type" value="' . $row['type'] . '"></td>'; echo '<td><input type="text" name="location" value="' . $row['location'] . '"></td>'; etc... where does this go then, or what code does it replace? sorry for being so stupid! thanks again! Quote Link to comment Share on other sites More sharing options...
deansatch Posted February 25, 2008 Share Posted February 25, 2008 replace: while($row = mysql_fetch_array($result)) { echo "<tr>"; echo '<td><input type="text" value="' . $row['type'] . '"></td>'; echo '<td><input type="text" value="' . $row['location'] . '"></td>'; echo '<td><input type="text" value="' . $row['availability'] . '"></td>'; echo '<td><input type="text" value="' . $row['StarRating'] . '"></td>'; echo '<td><input type="text" value="' . $row['name'] . '"></td>'; echo '<td><input type="text" value="' . $row['email'] . '"></td>'; echo '<td><input type="text" value="' . $row['username'] . '"></td>'; echo "</tr>"; } with: while($row = mysql_fetch_array($result)) { echo "<tr>"; echo '<td><input type="text" name="type" value="' . $row['type'] . '"></td>'; echo '<td><input type="text" name="location" value="' . $row['location'] . '"></td>'; echo '<td><input type="text" name="availability" value="' . $row['availability'] . '"></td>'; echo '<td><input type="text" name="StarRating" value="' . $row['StarRating'] . '"></td>'; echo '<td><input type="text" name="name" value="' . $row['name'] . '"></td>'; echo '<td><input type="text" name="email" value="' . $row['email'] . '"></td>'; echo '<td><input type="text" name="username" value="' . $row['username'] . '"></td>'; echo "</tr>"; } Quote Link to comment Share on other sites More sharing options...
synchro_irl Posted February 25, 2008 Author Share Posted February 25, 2008 thanks for that, but it still not updating, any ideas? replace: while($row = mysql_fetch_array($result)) { echo "<tr>"; echo '<td><input type="text" value="' . $row['type'] . '"></td>'; echo '<td><input type="text" value="' . $row['location'] . '"></td>'; echo '<td><input type="text" value="' . $row['availability'] . '"></td>'; echo '<td><input type="text" value="' . $row['StarRating'] . '"></td>'; echo '<td><input type="text" value="' . $row['name'] . '"></td>'; echo '<td><input type="text" value="' . $row['email'] . '"></td>'; echo '<td><input type="text" value="' . $row['username'] . '"></td>'; echo "</tr>"; } with: while($row = mysql_fetch_array($result)) { echo "<tr>"; echo '<td><input type="text" name="type" value="' . $row['type'] . '"></td>'; echo '<td><input type="text" name="location" value="' . $row['location'] . '"></td>'; echo '<td><input type="text" name="availability" value="' . $row['availability'] . '"></td>'; echo '<td><input type="text" name="StarRating" value="' . $row['StarRating'] . '"></td>'; echo '<td><input type="text" name="name" value="' . $row['name'] . '"></td>'; echo '<td><input type="text" name="email" value="' . $row['email'] . '"></td>'; echo '<td><input type="text" name="username" value="' . $row['username'] . '"></td>'; echo "</tr>"; } Quote Link to comment Share on other sites More sharing options...
deansatch Posted February 25, 2008 Share Posted February 25, 2008 just reading through your script, it looks like it will first disply your info in a form. Then on clicking submit it will update users with id '5's availability to '11111111'. Then it will insert the details from the form into you db. This whole script doesn't make a lot of sense for a few reasons. Because you are using a while statement for your form echo, you are echoing the same fields several times with different info in each. You are adding a new user after updating your db but it seems as though that person is already a user and you are duplicating them. What exactly do you want this script to do from start to finish, and I'll try and help you come up with a solution? Quote Link to comment Share on other sites More sharing options...
synchro_irl Posted February 25, 2008 Author Share Posted February 25, 2008 just reading through your script, it looks like it will first disply your info in a form. Then on clicking submit it will update users with id '5's availability to '11111111'. Then it will insert the details from the form into you db. This whole script doesn't make a lot of sense for a few reasons. Because you are using a while statement for your form echo, you are echoing the same fields several times with different info in each. You are adding a new user after updating your db but it seems as though that person is already a user and you are duplicating them. What exactly do you want this script to do from start to finish, and I'll try and help you come up with a solution? hey i want it to display all teh data from the table the setting of availability to 1111 or watever was ust a test to proove there was a connection. all i want to do is display all entries, all the user to edit the entries, and allow them to save those changes to the table by clicking update thats all i want it to do thanks very much for ur help again Quote Link to comment Share on other sites More sharing options...
deansatch Posted February 25, 2008 Share Posted February 25, 2008 The way I would do it would be to use a few different pages. the main page that displays your list of users and their info. Using the id from the users table, make a link to edit.php?id=$id. e.g. [font=Verdana][/font]while($row = mysql_fetch_array($result)) { echo "<tr>"; echo '<td>' . $row['type'] . '></td>'; echo '<td>' . $row['location'] . '></td>'; echo '<td>' . $row['availability'] . '></td>'; echo '<td>' . $row['StarRating'] . '></td>'; echo '<td>' . $row['name'] . '></td>'; echo '<td>' . $row['email'] . '></td>'; echo '<td>' . $row['username'] . '></td>'; echo '<td><a href="edit.php?id=$id">Edit user details</a></td>'; echo "</tr>"; } On edit.php, echo your variables for user where id = $id in to a form. Have the form action set as update.php. e.g. $row = mysql_fetch_array($result); echo "<tr>"; echo '<td><input type="hidden" name="id" value="' . $id . '"></td>'; echo '<td><input type="text" name="type" value="' . $row['type'] . '"></td>'; echo '<td><input type="text" name="location" value="' . $row['location'] . '"></td>'; echo '<td><input type="text" name="availability" value="' . $row['availability'] . '"></td>'; echo '<td><input type="text" name="StarRating" value="' . $row['StarRating'] . '"></td>'; echo '<td><input type="text" name="name" value="' . $row['name'] . '"></td>'; echo '<td><input type="text" name="email" value="' . $row['email'] . '"></td>'; echo '<td><input type="text" name="username" value="' . $row['username'] . '"></td>'; echo "</tr>"; On update.php run your update script i.e. update mytable where id = $id etc... Quote Link to comment Share on other sites More sharing options...
synchro_irl Posted February 25, 2008 Author Share Posted February 25, 2008 im really not sure what to do, i sent u a message, did u get it? Quote Link to comment Share on other sites More sharing options...
deansatch Posted February 25, 2008 Share Posted February 25, 2008 here are the three files in a very basic way. They aren't tested either but you should get the general idea. firstpage.php <table border="1"> <tr> <th>Type</th> <th>Location</th> <th>Availability</th> <th>StarRating</th> <th>name</th> <th>email</th> <th>username</th> </tr> <?php //Database Information - needs filling in //#### You should put this in a config file seperately and include it in any files that need to connect to the db. And you shouldn't post the login details on a forum $dbhost = "localhost"; $dbname = "xxxxx"; $dbuser = "xxxx"; $dbpass = "xxxx"; //Connect to database $connection = mysql_connect($dbhost,$dbuser,$dbpass)or die(mysql_error()); mysql_select_db("$dbname", $connection)or die(mysql_error()); $result = mysql_query("SELECT * FROM mytable"); while($row = mysql_fetch_array($result)) { echo "<tr>"; echo '<td>' . $row['type'] . '></td>'; echo '<td>' . $row['location'] . '></td>'; echo '<td>' . $row['availability'] . '></td>'; echo '<td>' . $row['StarRating'] . '></td>'; echo '<td>' . $row['name'] . '></td>'; echo '<td>' . $row['email'] . '></td>'; echo '<td>' . $row['username'] . '></td>'; echo '<td><a href="edit.php?id='.$row['id'].'">Edit</a></td>'; echo "</tr>"; } mysql_close($con); ?> </table> edit.php <form action="update.php" method="post"> <table border='1'> <tr> <th>Type</th> <th>Location</th> <th>Availability</th> <th>StarRating</th> <th>name</th> <th>email</th> <th>username</th> </tr> <?php //Database Information - needs filling in //#### You should put this in a config file seperately and include it in any files that need to connect to the db. And you shouldn't post the login details on a forum $dbhost = "localhost"; $dbname = "xxxxx"; $dbuser = "xxxx"; $dbpass = "xxxx"; //Connect to database $connection = mysql_connect($dbhost,$dbuser,$dbpass)or die(mysql_error()); mysql_select_db("$dbname", $connection)or die(mysql_error()); $id=$_GET['id']; $result = mysql_query("SELECT * FROM mytable WHERE id = $id"); $row = mysql_fetch_array($result); { echo "<tr>"; echo '<td><input type="hidden" name="id" value="'.$id.'"></td>'; echo '<td><input type="text" name="type" value="' . $row['type'] . '"></td>'; echo '<td><input type="text" name="location" value="' . $row['location'] . '"></td>'; echo '<td><input type="text" name="availability" value="' . $row['availability'] . '"></td>'; echo '<td><input type="text" name="StarRating" value="' . $row['StarRating'] . '"></td>'; echo '<td><input type="text" name="name" value="' . $row['name'] . '"></td>'; echo '<td><input type="text" name="email" value="' . $row['email'] . '"></td>'; echo '<td><input type="text" name="username" value="' . $row['username'] . '"></td>'; echo "</tr>"; } mysql_close($con); ?> <tr> <td colspan="2" align="right"> <input type="submit" name="submit" value="Update"> </td> </tr> </table> </form> update.php <?php $id = $_POST['id']; $name = $_POST['name']; $email = $_POST['email']; $type = $_POST['type']; $location = $_POST['location']; $availability = $_POST['availability']; $username = $_POST['username']; //Database Information - needs filling in //#### You should put this in a config file seperately and include it in any files that need to connect to the db. And you shouldn't post the login details on a forum $dbhost = "localhost"; $dbname = "xxxxx"; $dbuser = "xxxx"; $dbpass = "xxxx"; //Connect to database $connection = mysql_connect($dbhost,$dbuser,$dbpass)or die(mysql_error()); mysql_select_db("$dbname", $connection)or die(mysql_error()); //Overwrite old details with new details $query = mysql_db_query($db, "UPDATE mytable SET name='$name', Type='$type', location='$location', availability='$availability', username='$username' WHERE id = $id", $connection); echo "Updated Successfully"; ?> You will need to add it to you pages as required and style your tables and forms etc... but it should do the job. Quote Link to comment Share on other sites More sharing options...
synchro_irl Posted February 27, 2008 Author Share Posted February 27, 2008 thanks for all the hlpe snatch got it worki, so delighted! thanks again! Quote Link to comment 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.