backinblack Posted March 9, 2007 Share Posted March 9, 2007 I know there are alot of people that have asked about updates and I have read most of them. It seems to me I have the same thing as alot of people and they got there to work. Mine will not update it. It acts like it did but it don't. I have four columns in my database--driver_id, carnumber, name, april15pts(more dates will be added later)Car Numbers and names are already in there. I just want to update the april15pts column. Here is what I have. I have a form with the text areas carnumber, name, and april15pts which goes to this process page. <?php $carnumber = $_POST['carnumber']; $name = $_POST['name']; $april15pts = $_POST['april15pts']; $host = "xxxxxxx"; $user = "xxxxxxx"; $password = "xxxxxx"; $database = "xxxxxxx"; $connection = mysql_connect($host, $user, $password) or die ("Could not retrieve information"); $db = mysql_select_db("databasename",$connection) or die ("Could not make connection"); $query = "UPDATE points SET april15pts='$april15pts' WHERE carnumber='$carnumber' AND name='$name'"; $results=mysql_query($query) or die (mysql_error()); if ($results); echo 'Result have been posted into database!'; ?> I have read that you are not suppose to use AND --and just use a comma but when I do that I get an error. What the heck am I doing wrong? Quote Link to comment Share on other sites More sharing options...
skali Posted March 9, 2007 Share Posted March 9, 2007 Try printing your query and running it from mysql console or phpmyadmin and c what it does Quote Link to comment Share on other sites More sharing options...
backinblack Posted March 10, 2007 Author Share Posted March 10, 2007 Well I ran it in phpmyadmin and it does nothing. It just shows that no rows were affected which I already knew. For some reason I do not think it reconizes the $april15pts variable. I can put any thing else in there like 50 and it will update then. I am confused. Please help. Quote Link to comment Share on other sites More sharing options...
AndyB Posted March 10, 2007 Share Posted March 10, 2007 Are you sure that the NAMEs in your form inputs are identical to the names you assume for POSTed variables? Quote Link to comment Share on other sites More sharing options...
backinblack Posted March 10, 2007 Author Share Posted March 10, 2007 I have just two rows of three input fields now but it will be up to 25. <form action="april15pts.php" method="post"> <table width="30%"><tr><td width="5%"><b>Car #:</b> </td><td width="15%"><b>Name:</b></td> <td width="5%"><b>Points:</b></td></tr> <td><input type="text" name="carnumber[]"></td><td><input type="text" name="name[]"></td><td><input type="text" name="april15pts[]"></td></tr> <tr><td><input type="text" name="carnumber[]"></td><td><input type="text" name="name[]"></td><td><input type="text" name="april15pts[]"></td></tr> <tr><td><input type="submit" value="Send Results"></td></tr> </table> </form> Quote Link to comment Share on other sites More sharing options...
AndyB Posted March 10, 2007 Share Posted March 10, 2007 In your html form, april15pts is an array element. In your php script that attempts to add to the database, you assume that april15pts is a normal, non-array variable. Quote Link to comment Share on other sites More sharing options...
backinblack Posted March 10, 2007 Author Share Posted March 10, 2007 I have done it with out using them as an array but then it only updates the last one. The reason for that is all the input names are the same. Some how I have to get them different. I have read several turtorials and it just does not make sense. Quote Link to comment Share on other sites More sharing options...
per1os Posted March 10, 2007 Share Posted March 10, 2007 It is never a really good idea to use numbers in variable or column names to be honest. I would change the april15pts to aprilfiftpts or something like that, or do aprilpts15. Yes it works alot of times, but sometimes that is the cause of the errors is the incompatibility. I am just quoting this from memory, I could be wrong but yea. Try to change the column name in the DB to something different and see if it works. --FrosT Quote Link to comment Share on other sites More sharing options...
backinblack Posted March 10, 2007 Author Share Posted March 10, 2007 I have rename it before and it did not work. Some thing that should be fairly easy is drving me nuts. I have two rows of three input fields. Is there away to name each one differently for the update? Because I think this is part of my problem. 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.