Jump to content

[SOLVED] MySQL won't update


timmah1

Recommended Posts

I'm trying to change the values of the field "default" in my database, but it won't update.

Here is the code
[code]
<a href=myPhotosD.php?default=yes&file=$myrow[file]>Make Default Picture</a>[/code]

and here is the script that should update the DB
[code]
<?php
session_start();
if(!session_is_registered(username)){
header("location:login.html");
}
/***** database connection start *****/
// MySQL Settings
      $MySqlHostname = "localhost";
      $MySqlUsername = "xx";
      $MySqlPassword = "xx";
      $MySqlDatabase = "xx";

      /* make connection to database */
      /* If no connection made, display error Message */
         
      $dblink=MYSQL_CONNECT($MySqlHostname, $MySqlUsername, $MySqlPassword) OR DIE("Unable to connect to database");     

      /* Select the database name to be used or else print error message if unsuccessful*/
      @mysql_select_db("$MySqlDatabase") or die( "Unable to select database");
/***** database connection end ******/

$query="update photos set default='$default' WHERE file='$file'";
$result = MYSQL_QUERY($query);
?>
[/code]

any ideas?
thanks
Link to comment
Share on other sites

here's the code where it's defined
[code]
echo "<table width=100% border=0 align=center>";

//set 3 to 4 of you want 4 columns. Set it to 5 if you want 5, etc
$numcols = 3; // how many columns to display
$numcolsprinted = 0; // no of columns so far

// get the results to be displayed
$query = "SELECT * FROM photos WHERE username = '$username'";
$mysql_result = mysql_query($query);


// get each row
while($myrow = mysql_fetch_assoc($mysql_result))
{

//get data - eg,
$file = $myrow['file'];
$default = $myrow['default'];
$username = $myrow['username'];
$comments = $myrow['comments'];

if ($numcolsprinted == $numcols) {
print "</tr>\n<tr>\n";
$numcolsprinted = 0;
}

// output row from database
echo "<td align=center valign=top><img src=\"/$username/$file\" width=\"100\" border=\"1\"><br>
Default <b>$myrow[default]</b><br>
<a href=myPhotosD.php?default=yes&file=$myrow[file]&username=$myrow[username]>Make Default Picture</a><br>
<a href=share.php?default=no&file=$myrow[file]>Undefault Picture</a></td>\n";

// bump up row counter
$numcolsprinted++;

} // end while loop

$colstobalance = $numcols - $numcolsprinted;
for ($i=1; $i<=$colstobalance; $i++) {

}
print "<TD></TD></table>\n";
[/code]
Link to comment
Share on other sites

Try

$query="UPDATE `photos` SET `default` = '{$default}' WHERE `file` = '{$file}'";
$result = mysql_query($query) or die(mysql_error());

I doubt it'll work, but its worth a try... Anyways tell me what it says the error is if it doesnt work...

And ummm if file and default are being pulled from the DB, whats the point in updating them to the same values?
Link to comment
Share on other sites

I have a code that displays pictures, which is this one.
It also gives you the choice of making a certain picture your default, and you should be able to change it
[code]
echo "<table width=100% border=0 align=center>";

//set 3 to 4 of you want 4 columns. Set it to 5 if you want 5, etc
$numcols = 3; // how many columns to display
$numcolsprinted = 0; // no of columns so far

// get the results to be displayed
$query = "SELECT * FROM photos WHERE username = '$username'";
$mysql_result = mysql_query($query);


// get each row
while($myrow = mysql_fetch_assoc($mysql_result))
{

//get data - eg,
$file = $myrow['file'];
$default = $myrow['default'];
$username = $myrow['username'];
$comments = $myrow['comments'];

if ($numcolsprinted == $numcols) {
print "</tr>\n<tr>\n";
$numcolsprinted = 0;
}

// output row from database
echo "<td align=center valign=top><img src=\"/$username/$file\" width=\"100\" border=\"1\"><br>
Default <b>$myrow[default]</b><br>
<a href=myPhotosD.php?default=yes&file=$myrow[file]>Make Default Picture</a><br>
<a href=myPhotosD.php?default=no&file=$myrow[file]>Undefault Picture</a></td>\n";

// bump up row counter
$numcolsprinted++;

} // end while loop

$colstobalance = $numcols - $numcolsprinted;
for ($i=1; $i<=$colstobalance; $i++) {

}
print "<TD></TD></table>\n";[/code]

Then here is the script which is suppose to update the file into the database
[code]
session_start();
if(!session_is_registered(username)){
header("location:login.html");
}
/***** database connection start *****/
// MySQL Settings
      $MySqlHostname = "localhost";
      $MySqlUsername = "xx";
      $MySqlPassword = "xx";
      $MySqlDatabase = "xx;

      /* make connection to database */
      /* If no connection made, display error Message */
         
      $dblink=MYSQL_CONNECT($MySqlHostname, $MySqlUsername, $MySqlPassword) OR DIE("Unable to connect to database");     

      /* Select the database name to be used or else print error message if unsuccessful*/
      @mysql_select_db("$MySqlDatabase") or die( "Unable to select database");
/***** database connection end ******/


$query="update photos set default='$default' WHERE file='$file'";
$result = MYSQL_QUERY($query);
[/code]
Link to comment
Share on other sites

$default and $file are not defined in your second script. They are contained within the $_GET array. Use...

[code=php:0]
$query="update photos set default='{$_GET['default']}' WHERE file='{$_GET['file']}'";
[/code]

Whatever tutorial or book it is your reading as well out of date.


Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.