GoFuckYourself.com - Adult Webmaster Forum

GoFuckYourself.com - Adult Webmaster Forum (https://gfy.com/index.php)
-   Fucking Around & Business Discussion (https://gfy.com/forumdisplay.php?f=26)
-   -   any PHP guys around? have a question (https://gfy.com/showthread.php?t=987456)

96ukssob 09-15-2010 12:48 PM

any PHP guys around? have a question
 
I'm trying to mess around with script to edit a single row in a table, but for some reason, it wont update.

Anyone help out? p-p-p-please :helpme

edit page
PHP Code:

<?php
mysql_connect
("localhost","username","password") or die("Error: ".mysqlerror());
mysql_select_db("db_name");
$sql "select * from `ring` where ID = 'user'";
$query mysql_query($sql);
while (
$row mysql_fetch_array($query)){
    
$id $row['ID'];
    
$value $row['value'];
    
$text $row['text'];
    
$image $row['image'];
}
mysql_free_result($query);
?>
<html>
<head>
<title>Edit User Info</title>
</head>
<body>
<form action="updateinfo.php" method="post">
ID:<br/>
<input type="text" value="<?php echo $id;?>" name="id" disabled/>
<br/>
Value:<br/>
<input type="text" value="<?php echo $value;?>" name="value"/>
<br/>
Text:<br/>
<input type="text" value="<?php echo $text;?>" name="text"/>
<br/>
Image:<br/>
<input type="text" value="<?php echo $image;?>" name="image"/>
</br>
<input type="submit" value="submit changes"/>
</form>
</body>
</html>

and here is the update info page

PHP Code:

<?php
mysql_connect
("localhost","username","password") or die("Error: ".mysqlerror());
mysql_select_db("db_name");
$id $row['ID'];
$value $row['value'];
$text $row['text'];
$image $row['image'];
$sql "UPDATE `ring` SET `value` = '$value',`text` = '$text',`image` = '$image' WHERE `ring`.`ID` = '$id' LIMIT 1";
mysql_query($sql) or die ("Error: ".mysql_error());
echo 
"Database updated. <a href='editinfo.php'>Return to edit info</a>";
?>

the single user that I am trying to edit is named "user" in the table

i'll have some paypal sent later this week if someone wants a few bucks, or let me know how i can help you out :thumbsup

woj 09-15-2010 12:56 PM

in that 2nd file, you need use $_POST instead of $row, but still I hope you are just playing around and aren't actually planning to use this on a live site, that code is full of holes...

96ukssob 09-15-2010 01:10 PM

Quote:

Originally Posted by woj (Post 17506047)
in that 2nd file, you need use $_POST instead of $row, but still I hope you are just playing around and aren't actually planning to use this on a live site, that code is full of holes...

its just something I am messing around with, but no wont be anything public.

i changed the $row to $_POST and still not storing in the DB. I changed the file permissions to 777 from 644... any other suggestions

PHP Code:

<?php
mysql_connect
("localhost","username","password") or die("Error: ".mysqlerror());
mysql_select_db("db_name");
$id $_POST['ID'];
$value $_POST['value'];
$text $_POST['text'];
$image $_POST['image'];
$sql "UPDATE `ring` SET `value` = '$value',`text` = '$text',`image` = '$image' WHERE `ring`.`ID` = '$id' LIMIT 1";
mysql_query($sql) or die ("Error: ".mysql_error());
echo 
"Database updated. <a href='editinfo.php'>Return to edit info</a>";
?>


EDepth 09-15-2010 01:14 PM

id is lowercase in the form, uppercase in your code?

grumpy 09-15-2010 01:20 PM

add
echo $sql;

and see if the line is correct or post it here

Jakez 09-15-2010 01:21 PM

When something isn't working and I can't for the life of me figure out why I usually just start "dieing" stuff out, try:
die($sql)

Then you can see exactly what it's telling mysql and copy/paste it into phpmyadmins SQL query box. Haven't used mysql_error() in a while but phpmyadmin will give you some good info about the query if it fails or not.

96ukssob 09-15-2010 01:22 PM

Quote:

Originally Posted by EDepth (Post 17506114)
id is lowercase in the form, uppercase in your code?

i changed it from ID to id... still wont update in the db :(

davethedope 09-15-2010 01:25 PM

it's probably not connecting to "localhost" use the server name.

96ukssob 09-15-2010 01:25 PM

Quote:

Originally Posted by grumpy (Post 17506147)
add
echo $sql;

and see if the line is correct or post it here

Quote:

Originally Posted by Jakez (Post 17506151)
When something isn't working and I can't for the life of me figure out why I usually just start "dieing" stuff out, try:
die($sql)

Then you can see exactly what it's telling mysql and copy/paste it into phpmyadmins SQL query box. Haven't used mysql_error() in a while but phpmyadmin will give you some good info about the query if it fails or not.

thanks guys :thumbsup

here is the output...
Code:

UPDATE `ring` SET `value` = '75',`text` = 'blah blah',`image` = 'image' WHERE `ring`.`id` = '' LIMIT 1

EDepth 09-15-2010 01:25 PM

is ID uppercase in your db table as well or lower?

EDepth 09-15-2010 01:26 PM

eh nevermind, looks like your not setting the $id variable for some reason. Most likely lowercase/uppercase in your $_POST or form vars.

96ukssob 09-15-2010 01:27 PM

AHHH! figured it out! i'm a knuckle head :winkwink:

had to change

PHP Code:

$sql "UPDATE `ring` SET `value` = '$value',`text` = '$text',`image` = '$image' WHERE `ring`.`id` = '$id' LIMIT 1"

to

PHP Code:

$sql "UPDATE `ring` SET `value` = '$value',`text` = '$text',`image` = '$image' WHERE `ring`.`id` = 'user' LIMIT 1"

:thumbsup

thanks for the help

grumpy 09-15-2010 01:30 PM

a little echo can save the day


All times are GMT -7. The time now is 01:32 PM.

Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
©2000-, AI Media Network Inc123