PDA

View Full Version : updating MySQL record using PHP


loxinthe
January 2nd, 2008, 06:14
Ok I have this first file:

<?
$title=$_POST['title'];
$pic=$_POST['pic'];
$description=$_POST['description'];
$expire=$_POST['expire'];
$valid=$_POST['valid'];
mysql_connect(localhost,$uname,$pword) or die("It's gone");
@mysql_select_db($db) or die( "Unable to select database");


$query = "SELECT * FROM special WHERE title='$title',pic='$pic',description='$descriptio n',expire='$expire',valid='$valid'";




echo $pic;



?>

<form ENCTYPE="multipart/form-data" method="post" action="editdb.php">
<table bgcolor=#ffffcc align=center>
<tr>
<td colspan=2><strong>Fill out this form to edit this special on the web site</strong></td></tr>
<tr><td> Title:</td><td><input type="text" size=25 name="title" value="<?echo $title;?>"></td></tr>
<tr><td> Image:</td><td><input type="file" name="pic" value="<? echo $pic;?>"><input type="hidden" name="pico" value="<? echo $pic; ?>"></td></tr>
<tr><td>Description:</td><td><textarea height="30" name="description"><? echo $description; ?></textarea></td></tr>
<tr><td >Expiration:</td><td align=center>
<input type="text" size=25 name="expire" value="<?echo $expire;?>">

</td></tr>
<tr>
<td>
Valid with other offers?:</td>
<td>
<input type="radio" name="valid" value="yes" <? if ($valid=="yes"){echo "checked";} ?>> Yes<br>
<input type="radio" name="valid" value="no" <? if ($valid=="no"){echo "checked";} ?>> No
</td>
</tr>
<tr><td colspan=2 align=center><input type=submit name="send" value="Submit"></td></tr>
</table>
</form>

which should use this one to update:


<?
$uname="<<removed>>";
$pword="<<removed>>";
$db="<<removed>>";



if(strlen($_files['pic'])>0) {
$target = "specialsimages/";
$target = $target . basename(

$_FILES['pic']['name']) ;
echo "$target <br>";
$ok=1;
move_uploaded_file($_FILES['pic']['tmp_name'], $target)
$pic=$target;
}else{
$pic=$_POST['pico'];
}

$title=$_POST['title'] ;


$description=$_POST['description'];
$expire=$_POST['expire'];
$valid=$_POST['valid'];
mysql_connect(localhost,$uname,$pword) or die("It's gone");
@mysql_select_db($db) or die( "Unable to select database");


$query = "UPDATE special SET title = '$title', pic =

'$pic', description = '$description', expire = '$expire',

valid = '$valid'";

mysql_query($query);

mysql_close();


?>

All I get is: Parse error: syntax error, unexpected T_VARIABLE in /home/eyeaxcom/public_html/editdb.php on line 14

What is happening I can't figure it out.

the_pm
January 2nd, 2008, 06:33
Hello loxinthe, and welcome to IWDN :hi:

First of all, I'm probably not the most qualified person to give you an answer (PHP is not my strong suit), but I'll give this a look in a minute anyway - maybe I'll hit the right answer.

The main reason I'm responding quickly without an answer is because you posted the connection information to your database in your first post. This is a HUGE security risk to you and possibly your host! IWDN gets a lot of guest and search engine traffic, and if this info got out there, you could end up getting your site wiped out by a malicious reader. I removed the sensitive information from your post - it isn't needed in order to diagnose the problem.

Just a heads up for future posts :)

the_pm
January 2nd, 2008, 06:43
Hmm, it looks like some whitespace creeped into the page:

$target = $target . basename(

$_FILES['pic']['name']) ;

I don't know enough about PHP to know if it will make a difference, but I think these two lines were meant to be one line of text...

inimino
January 2nd, 2008, 07:15
All I get is: Parse error: syntax error, unexpected T_VARIABLE in /home/eyeaxcom/public_html/editdb.php on line 14

What is happening I can't figure it out.

What is happening is is a parse error on line 14 of the file editdb.php.

What you should do when you see such a message is open that file in your text editor and go to the indicated line. (If your text editor doesn't make it easy to find a particular line by number, get a better text editor.) Then look closely to find the syntax error.

In this case, the parse error on line 14 is actually caused by an error on line 13 where an important character is missing.

loxinthe
January 2nd, 2008, 08:09
lol

Thanks I found the missing ; I have been at this one site too long that I was getting burnt on debugging.

Thanks a ton

george22
December 8th, 2011, 12:54
Thanks I found the missing ; I have been at this one site too long that I was getting burnt on debugging. tips on dating (http://www.tipsondatings.com/)

NhocCuteGirl
December 8th, 2011, 23:57
Hello loxinthe, and welcome to IWDN images/smilies/paul_h_style/icon_hi.gif



First of all, I'm probably not the most qualified person to give you an answer (PHP is not my strong suit), but I'll give this a look in a minute anyway - maybe I'll hit the right answer.



The main reason I'm responding quickly without an answer is because you posted the connection information to your database in your first post. This is a HUGE security risk to you and possibly your host! IWDN gets a lot of guest and search engine traffic, and if this info got out there, you could end up getting your site wiped out by a malicious reader. I removed the sensitive information from your post - it isn't needed in order to diagnose the problem.



Just a heads up for future posts images/smilies/paul_h_style/icon_smile.gif
__________________

Download Software (http://soft444.com)