TheCatapult Posted March 15, 2012 Share Posted March 15, 2012 Hi friends, I want to know what script can change the value of ID in database. Please help me. I want to accomplish this because in my Web site there is an icon which indicates which DJ is currently on air. I am hoping for helpful answers. All the best,The Catapult Link to comment Share on other sites More sharing options...
niche Posted March 16, 2012 Share Posted March 16, 2012 If it's auto increment, it can't be changed unless you delete then re-add it and auto increment. If it's not auto increment changing won't be a problem. Link to comment Share on other sites More sharing options...
birbal Posted March 16, 2012 Share Posted March 16, 2012 to change value of a row you can use "update". if it is auto increment colum and it changed to any existed ID new id will be the next id of the highest id if it does not exist it will be just updated Link to comment Share on other sites More sharing options...
TheCatapult Posted March 16, 2012 Author Share Posted March 16, 2012 Thank you for the above answers. Yes, it is auto increment. What I want to happen is to display the row 1 in my Web site. I also want to have a protected page in my Web site wherein I can change the value written in row 1. birbal, Update did not work. Please help me. <form action="insert.php" method="post"><select> <option value="volvo">Volvo</option> <option value="saab">Saab</option> <option value="mercedes">Mercedes</option> <option value="audi">Audi</option></select> <br><input type="Submit"></form> Here's my current code for adding new row in my data base. Unfortunately, it does only write a space and not what is written in the option value. What's my mistake here? Please help me. Thank you! Link to comment Share on other sites More sharing options...
birbal Posted March 16, 2012 Share Posted March 16, 2012 please show us the php code of it Link to comment Share on other sites More sharing options...
TheCatapult Posted March 16, 2012 Author Share Posted March 16, 2012 Thank you birbal! Here is my Update code. <?$ud_id=$_POST['ud_id'];$ud_first=$_POST['ud_jockey'];$username="";$password=";$database="";mysql_connect("",$username,$password);$query="UPDATE diskjockey SET first='$ud_first'";mysql_query($query);echo "Record Updated";mysql_close();?> Please help me. I just want to have a page wherein I can select the image code of the current DJ on air. Link to comment Share on other sites More sharing options...
niche Posted March 16, 2012 Share Posted March 16, 2012 (edited) That won't work if first is auto increment. EDIT: Add another column that you can UPDATE. Edited March 16, 2012 by niche Link to comment Share on other sites More sharing options...
justsomeguy Posted March 16, 2012 Share Posted March 16, 2012 $query="UPDATE diskjockey SET first='$ud_first'"; That will work if $ud_first contains the ID that you want to update with, and you want to store that in a column called first in the table diskjockey. That particular query is going to update all rows in that table with the same value in that column. If that's the table and column you use to figure out who is playing, then that will work to update it. Link to comment Share on other sites More sharing options...
niche Posted March 16, 2012 Share Posted March 16, 2012 (edited) please confirm that you can't update an auto increment column. post #4 suggests it might be ai. Edited March 16, 2012 by niche Link to comment Share on other sites More sharing options...
justsomeguy Posted March 16, 2012 Share Posted March 16, 2012 I'm pretty sure you can update any column, but I don't know why you would want to update an auto increment. It sounded to me like he had one table that held all of the DJs, and another table that listed which was currently on air, and he wanted to update the one with the ID from the other. I could be wrong. Link to comment Share on other sites More sharing options...
niche Posted March 16, 2012 Share Posted March 16, 2012 I just tried to update an auto increment field and got this error: Duplicate entry '1' for key 'PRIMARY' phpmyadmin wouldn't let me manually change it either for the same reason. Link to comment Share on other sites More sharing options...
TheCatapult Posted March 16, 2012 Author Share Posted March 16, 2012 Thank you for the above helpful answers!I put a section in my Web site which indicates which DJ is currently on air. DJ changes time by time so I need a script wherein I can change the icon of the current DJ into an icon of the next DJ. Please help me. Link to comment Share on other sites More sharing options...
birbal Posted March 16, 2012 Share Posted March 16, 2012 I just tried to update an auto increment field and got this error: Duplicate entry '1' for key 'PRIMARY' phpmyadmin wouldn't let me manually change it either for the same reason. if it is auto increment colum and it changed to any existed ID new id will be the next id of the highest idif it is primary key or unique constrained it will not do so and will throw a error Link to comment Share on other sites More sharing options...
TheCatapult Posted March 16, 2012 Author Share Posted March 16, 2012 So the only way is to make a new table wherein the primary key is not auto increment? Link to comment Share on other sites More sharing options...
niche Posted March 16, 2012 Share Posted March 16, 2012 Yes, if you think that's the problem, but you don't need a new table. I'd just add a column that isn't ai and remember what justsomeguy said. Link to comment Share on other sites More sharing options...
justsomeguy Posted March 16, 2012 Share Posted March 16, 2012 I put a section in my Web site which indicates which DJ is currently on air. DJ changes time by time so I need a script wherein I can change the icon of the current DJ into an icon of the next DJ.What exactly is the database structure like? How does it know which DJ is on air, does it look that up in the database? If so, what does that database table look like? 1 Link to comment Share on other sites More sharing options...
TheCatapult Posted March 16, 2012 Author Share Posted March 16, 2012 Thank you niche! Okay I made a new table namely diskjockey1. I made a row id which is INT and as the primary key and jockey which is VARCHAR. So how to change the value of jockey? What's the script for this? Link to comment Share on other sites More sharing options...
niche Posted March 16, 2012 Share Posted March 16, 2012 per justsomeguy (JSG), please post the table's structure so you can get the help you need. Link to comment Share on other sites More sharing options...
TheCatapult Posted March 16, 2012 Author Share Posted March 16, 2012 (edited) Here is the form for putting the image code of current DJ. <form action="insert.php" method="post"> Web: <input type="text" name="jockey"><br><input type="Submit"></form> This is the insert.php file. <?$username="";$password="";$database=""; $jockey=$_POST['jockey']; mysql_connect("",$username,$password);@mysql_select_db($database) or die( "Unable to select database"); $query = "INSERT INTO diskjockey1 VALUES ('','$jockey')";mysql_query($query); mysql_close();?> This is what my table look like. Thanks and I hope for help! Edited March 16, 2012 by MisterCatapult Link to comment Share on other sites More sharing options...
justsomeguy Posted March 16, 2012 Share Posted March 16, 2012 What about the code that displays the current DJ? Link to comment Share on other sites More sharing options...
niche Posted March 16, 2012 Share Posted March 16, 2012 Please help me. I just want to have a page wherein I can select the image code of the current DJ on air. To do this you'll need to use WHERE in your sql. Have you used WHERE before? Link to comment Share on other sites More sharing options...
TheCatapult Posted March 16, 2012 Author Share Posted March 16, 2012 (edited) Thank! Here's the code. <?$username="username";$password="password";$database="your_database";mysql_connect(localhost,$username,$password);@mysql_select_db($database) or die( "Unable to select database");$query="SELECT * FROM contacts";$result=mysql_query($query);$num=mysql_numrows($result);mysql_close(); $i=0;while ($i < $num) { $jockey=mysql_result($result,$i,"jockey");echo "<b>$jockey";$i++;}?> niche, no. What is that? Edited March 16, 2012 by MisterCatapult Link to comment Share on other sites More sharing options...
justsomeguy Posted March 16, 2012 Share Posted March 16, 2012 So you've got your diskjockey1 table which holds IDs and jockeys, and the contacts table which you get all of the records from and display each one. How do the 2 tables relate to each other? Is there an ID in the contacts table that is the same as the one in the other table? Link to comment Share on other sites More sharing options...
TheCatapult Posted March 16, 2012 Author Share Posted March 16, 2012 Sorry! That supposed to be diskjockey1. Please help. Link to comment Share on other sites More sharing options...
justsomeguy Posted March 16, 2012 Share Posted March 16, 2012 OK, that table displays all of them. How does it know which one is playing? Is there only one record in the table? Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now