 |
Account Login
|
 |
 |
Latest Articles
|
 |
 |
IRC Channel
|
 |
 |
Associates
|
 |
 |
Associates
|
 |
|
 |
|
 |
|
 |
05-07-2009, 12:41 AM
|
#1 (permalink)
|
|
The Acquainted
Join Date: May 2007
Location: Your G/F's Closet
Posts: 114
Thanks: 7
|
UPDATE MySQL data via web forms?
So i am working on a CMS for a certain genre of websites, not much detail is needed but I am having some issues. I am trying to make it for that they can update the website details from a php page and for some reason it wont update the database..
Form/PHP:
PHP Code:
<?php
if (isset($_POST['submit'])) {
// Define Variables
$websitename = $_POST['websitename'];
$tagline = $_POST['tagline'];
$websiteurl = $_POST['websiteurl'];
$contactemail = $_POST['contactemail'];
// Attempt To Update
$update = mysql_query"UPDATE settings SET `sitename` = '$websitename' ") or die(mysql_error());
if(mysql_num_rows($update) > 0
{
echo 'SUCCESS';
}
else
{
echo 'FAILZOR';
}
} else {
?>
<form action="" method="POST" id="settings" name="settings ">
Website Name: <br />
<label class="mediumInput">
<input name="websitename" id="websitename" type="text" size="75" />
</label>
<br />
<small>This will show up in the tab bar in your browser and all over the website.</small>
<p>Tagline (Description): <br />
<label class="textareasmall">
<textarea name="tagline" id="tagline" rows="2" cols="5"></textarea>
</label>
<br />
<small>This will show up on search engines under the name and will give a basic description of your website.</small></p>
<p>Website URL: <br />
<label class="mediumInput">
<input type="text" name="websiteurl" id="websiteurl" size="75"/>
</label>
<br />
<small>This is the URL to where you have this installed, It is recommend you do not change unless you know what you are doing.</small></p>
<p>Contact Email: <br />
<label class="mediumInput">
<input name="contactemail" id="contactemail" type="text" size="75" />
</label>
<br />
<small>This is where emails will be sent to when contact form is used, as well as when emails are sent out.</small></p>
<p>
<input name="submit" id="submit" type="image" src="../images/bt_submit.gif" />
</p>
</form>
<?php
}
?>
I have updated the entire file here:
http://pastie.org/470648
PHP for Form starts on line: 170
Im not sure why its not updating, i know all my variables are right. I don't receive any errors at all, I hit submit and it just reloads the page and removes all entered text on the input
__________________
Real Programmers always confuse Christmas and Halloween because Oct31 == Dec25 - Andrew Rutherford
|
|
|
05-07-2009, 12:50 AM
|
#2 (permalink)
|
|
The Gregarious
Join Date: Feb 2009
Location: New York
Posts: 646
Thanks: 64
|
Your query is missing a (...
$update = mysql_query"UPDATE settings SET `sitename` = '$websitename' ") or die(mysql_error());
$update = mysql_query("UPDATE settings SET `sitename` = '$websitename' ") or die(mysql_error());
|
|
|
|
05-07-2009, 12:52 AM
|
#3 (permalink)
|
|
The Acquainted
Join Date: May 2007
Location: Your G/F's Closet
Posts: 114
Thanks: 7
|
even with that it doesn't work, i had it before but was trying new things. I added it back and tried still didnt work.
__________________
Real Programmers always confuse Christmas and Halloween because Oct31 == Dec25 - Andrew Rutherford
|
|
|
05-07-2009, 12:56 AM
|
#4 (permalink)
|
|
Wizard
Join Date: Sep 2007
Posts: 1,211
Thanks: 17
|
You are not telling the database where to update, put a where clause at the end. Instead of modifying every row, mysql just doesn't do it (to do every row, do WHERE 1=1)
|
|
|
|
05-07-2009, 12:57 AM
|
#5 (permalink)
|
|
The Gregarious
Join Date: Feb 2009
Location: New York
Posts: 646
Thanks: 64
|
Quote:
Originally Posted by Randy
even with that it doesn't work, i had it before but was trying new things. I added it back and tried still didnt work.
|
Are you using IE or FF?
|
|
|
|
05-07-2009, 12:58 AM
|
#6 (permalink)
|
|
The Gregarious
Join Date: Feb 2009
Location: New York
Posts: 646
Thanks: 64
|
Quote:
Originally Posted by Village Idiot
You are not telling the database where to update, put a where clause at the end. Instead of modifying every row, mysql just doesn't do it (to do every row, do WHERE 1=1)
|
Good catch, that would be horrible to have all site names with the same name! Assuming that column is not unique....
|
|
|
|
05-07-2009, 01:00 AM
|
#7 (permalink)
|
|
The Acquainted
Join Date: May 2007
Location: Your G/F's Closet
Posts: 114
Thanks: 7
|
column is 100% unique so, but I did that:
PHP Code:
$update = mysql_query("UPDATE settings SET `sitename` = '$websitename' WHERE `build` = '1.0a'") or die(mysql_error());
and still nothing, i used build because its the "build" version of the script.
I am using FF3 I believe, not sure on exact version number as it is a work computer.
__________________
Real Programmers always confuse Christmas and Halloween because Oct31 == Dec25 - Andrew Rutherford
|
|
|
05-07-2009, 01:03 AM
|
#8 (permalink)
|
|
The Gregarious
Join Date: Feb 2009
Location: New York
Posts: 646
Thanks: 64
|
Quote:
Originally Posted by Randy
column is 100% unique so, but I did that:
PHP Code:
$update = mysql_query("UPDATE settings SET `sitename` = '$websitename' WHERE `build` = '1.0a'") or die(mysql_error());
and still nothing, i used build because its the "build" version of the script.
I am using FF3 I believe, not sure on exact version number as it is a work computer.
|
Try this...
$update = mysql_query("UPDATE settings SET `sitename` = '".$websitename."' WHERE `build` = '1.0a'") or die(mysql_error());
|
|
|
|
05-07-2009, 01:05 AM
|
#9 (permalink)
|
|
Wizard
Join Date: Sep 2007
Posts: 1,211
Thanks: 17
|
Another thing I noticed is that UPDATE does not return any rows, so your script will never show success. You are also missing a closing bracket on your if statement. Are you actually checking the values in the database or relying off of the script to say yes or no?
|
|
|
|
05-07-2009, 01:07 AM
|
#10 (permalink)
|
|
The Acquainted
Join Date: May 2007
Location: Your G/F's Closet
Posts: 114
Thanks: 7
|
Did not work :( all I can think of is that perhaps its being blocked because i am running some lines at the top of the page to retrieve the data as its required for the general purpose of the website such as getting the title to display and other items.
Code At Top:
PHP Code:
$settingsquery = mysql_query("SELECT * FROM settings") or die(mysql_error());
$setingsresult = mysql_fetch_array( $settingsquery );
$sitename = $setingsresult['sitename'];
$siteurl = $setingsresult['siteurl'];
$build = $setingsresult['build'];
that works just find just not this update issue.
__________________
Real Programmers always confuse Christmas and Halloween because Oct31 == Dec25 - Andrew Rutherford
|
|
|
05-07-2009, 01:08 AM
|
#11 (permalink)
|
|
Wizard
Join Date: Sep 2007
Posts: 1,211
Thanks: 17
|
That shouldn't block it.
Can you access your database directly? Try running the query on phpmyadmin or whatever you have in your control panel.
|
|
|
|
05-07-2009, 01:11 AM
|
#12 (permalink)
|
|
The Gregarious
Join Date: Feb 2009
Location: New York
Posts: 646
Thanks: 64
|
Just for kicks, take out your image button and try using a regular form button. I've ran into issues like this before with image buttons...
<input name="submit" id="submit" type="image" src="../images/bt_submit.gif" />
Try:
<input name="submit" id="submit" type="submit" />
|
|
|
|
05-07-2009, 01:11 AM
|
#13 (permalink)
|
|
The Acquainted
Join Date: May 2007
Location: Your G/F's Closet
Posts: 114
Thanks: 7
|
It works if i run in it PHPMyAdmin just fine,
Im running this on XAMPP on my PC
Quick Note: I am heading out of my office now to go home and work on this some more, please give me about 30mins to an hour to expect a reply from me again,
Thanks for helping me with this, i have been trying to fix this all day and have gotten nowhere..
__________________
Real Programmers always confuse Christmas and Halloween because Oct31 == Dec25 - Andrew Rutherford
|
|
|
05-07-2009, 01:12 AM
|
#14 (permalink)
|
|
The Acquainted
Join Date: May 2007
Location: Your G/F's Closet
Posts: 114
Thanks: 7
|
Quick Note On Allworknoplay's idea:
worked just getting this error:
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\xampp\htdocs\exotic\admin\settings.php on line 180
__________________
Real Programmers always confuse Christmas and Halloween because Oct31 == Dec25 - Andrew Rutherford
|
|
|
05-07-2009, 01:13 AM
|
#15 (permalink)
|
|
Wizard
Join Date: Sep 2007
Posts: 1,211
Thanks: 17
|
Quote:
Originally Posted by Randy
Thanks for helping me with this, i have been trying to fix this all day and have gotten nowhere..
|
I hope this is an issue regarding a project for work if that is the case 
|
|
|
|
05-07-2009, 01:14 AM
|
#16 (permalink)
|
|
The Acquainted
Join Date: May 2007
Location: Your G/F's Closet
Posts: 114
Thanks: 7
|
no its not but i work as a server administrator i just sit here and make sure servers are working.
__________________
Real Programmers always confuse Christmas and Halloween because Oct31 == Dec25 - Andrew Rutherford
|
|
|
05-07-2009, 01:19 AM
|
#17 (permalink)
|
|
The Gregarious
Join Date: Feb 2009
Location: New York
Posts: 646
Thanks: 64
|
Quote:
Originally Posted by Randy
Quick Note On Allworknoplay's idea:
worked just getting this error:
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\xampp\htdocs\exotic\admin\settings.php on line 180
|
Give us your latest code because that is missing the ) too...
if(mysql_num_rows($update) > 0
if(mysql_num_rows($update) > 0 )
|
|
|
|
05-07-2009, 01:49 AM
|
#18 (permalink)
|
|
The Acquainted
Join Date: May 2007
Location: Your G/F's Closet
Posts: 114
Thanks: 7
|
New Code:
PHP Code:
<?php
if (isset($_POST['submit'])) {
// Define Variables
$websitename = $_POST['websitename'];
$tagline = $_POST['tagline'];
$websiteurl = $_POST['websiteurl'];
$contactemail = $_POST['contactemail'];
// Attempt To Update
$update = mysql_query("UPDATE settings SET `sitename` = '".$websitename."' WHERE `build` = '1.0a'") or die(mysql_error());
if(mysql_num_rows($update) > 0);
} else {
?>
<form action="" method="POST" id="settings" name="settings ">
Website Name: <br />
<label class="mediumInput">
<input name="websitename" id="websitename" type="text" size="75" />
</label>
<br />
<small>This will show up in the tab bar in your browser and all over the website.</small>
<p>Tagline (Description): <br />
<label class="textareasmall">
<textarea name="tagline" id="tagline" rows="2" cols="5"></textarea>
</label>
<br />
<small>This will show up on search engines under the name and will give a basic description of your website.</small></p>
<p>Website URL: <br />
<label class="mediumInput">
<input type="text" name="websiteurl" id="websiteurl" size="75"/>
</label>
<br />
<small>This is the URL to where you have this installed, It is recommend you do not change unless you know what you are doing.</small></p>
<p>Contact Email: <br />
<label class="mediumInput">
<input name="contactemail" id="contactemail" type="text" size="75" />
</label>
<br />
<small>This is where emails will be sent to when contact form is used, as well as when emails are sent out.</small></p>
<p>
<input name="submit" id="submit" type="submit" />
</p>
</form>
<?php
}
?>
__________________
Real Programmers always confuse Christmas and Halloween because Oct31 == Dec25 - Andrew Rutherford
|
|
|
05-07-2009, 01:52 AM
|
#19 (permalink)
|
|
Wizard
Join Date: Sep 2007
Posts: 1,211
Thanks: 17
|
The UPDATE clause does not return any rows, counting the rows it returns will always be zero.
|
|
|
|
05-07-2009, 01:58 AM
|
#20 (permalink)
|
|
The Gregarious
Join Date: Feb 2009
Location: New York
Posts: 646
Thanks: 64
|
Quote:
Originally Posted by Village Idiot
The UPDATE clause does not return any rows, counting the rows it returns will always be zero.
|
Hmm.....can he do this?
PHP Code:
$update = mysql_query("UPDATE settings SET `sitename` = '".$websitename."' WHERE `build` = '1.0a'") or die(mysql_error());
if($update) {
echo "Success";
}
|
|
|
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|