larclem Posted May 3, 2010 Share Posted May 3, 2010 Hello, I have a script that grabs data from a website and enters it into mysql. It grabs almost like a raw txt file. Here is an example of my code and then I'll explain what I want to do. <form action="" method="GET"> <small>Please enter a username:</small> <br> <input type="text" name="user" /> <br> <input type="submit" value="Search" name="submit" /> <br> </form> <?php function showInfo() { $user = $_GET['user']; //then connect as user //change user and password to your mySQL name and password mysql_connect("localhost","username","password"); //select which database you want to edit mysql_select_db("table"); $file = @file_get_contents('http://getstat.mysite.com/index_lite.ws?player=' . $user); $explode = explode("\n", $file); $implode = implode(",", $explode); $stats = explode(",", $implode); echo '<b>' . $user . '</b>' . '<br>'; echo 'Rank: ' . $stats[0] . '<br>'; echo 'Total Level: ' . $stats[1] . '<br>'; } There are various other information that I am grabbing, but just wanted to list a low down on what I am doing. I have another part that adds this info to mysql once you search for a certain user. What I would like to do since I have about 200 users or more that I need to update, is have a query where I can do the example above but update if the user values if they exist in the database. I have tried several methods. I think I may be doing it wrong. $sql = "UPDATE stats SET total='$stats[1]', overall='$stats[0]' where username = '$user' "; $result = mysql_query($sql); Quote Link to comment https://forums.phpfreaks.com/topic/200605-php-update-mysql/ Share on other sites More sharing options...
Muddy_Funster Posted May 3, 2010 Share Posted May 3, 2010 for this to work: $sql = "UPDATE stats SET total='$stats[1]', overall='$stats[0]' where username = '$user' you will need to connect the variables to the statement using "." eg. $sql = "UPDATE stats SET total='.$stats[1].', overall='.$stats[0].' where username = \''.$user'\''; I also quoted your $user variable as it looks as though it is a sting. if you can run the above query using the following: mysql_query($query) or die (mysql_error(); and let us know what, if any, errors come back it would help a lot. Quote Link to comment https://forums.phpfreaks.com/topic/200605-php-update-mysql/#findComment-1052695 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.