View Full Version : Odd mySql problems
djmagic23
07-12-2003, 01:49 AM
Hello,
I am experiancing some weird problems with mySql upadating with cirtain PHP scripts(some made by myself, some from other people). Some forms used to update the database just dont do anything at all(save for refresh the page when you press submit). I can update via command promt and some scripts (such as PHPBB or myPHPAdmin), but not others (such as vNews or SnipeGallery). Also, I can retreive information from the database(so I know I didn't mistype the databse name or login or what not) just I can't update or add.
here are the servers stats.
Apache 2.0.46
Coldfusion MX with Upgrade 3
PHP 4.3.2
MySql 4.0.13-nt
Welcome here.
I think we need more info. Can you post some of the PHP code that doesn't update the db ?
Or did you check that the MySQL-account that you use inside the PHP, has got updatepermissions on the tables ?
djmagic23
07-12-2003, 06:57 PM
the thing is, it doesn't give me any errors in either mySql or PHP. It just does not submit the form that updates the database with new information (check the attachment, it is just the standard vNews script, this is with my database name, username, and password removed but I DID input them correctly on my server). In the newsdesign.php and newscontent.php i just fill in the simple forms and push submit. according to the code it SHOULD add a "Changes have been saved" above the table. But in my case it just refreshs the page with the default dettings back in each form box. (see code)<?
if ($saved=="true")
{
print "<tr>";
print " <td valign=\"top\" colspan=\"2\"><b><i>";
print " <font face=\"Verdana, Arial, Helvetica, sans-serif\" size=\"2\" color=\"#990000\">";
print " Changes has been saved.</font></i></b>";
print " </td>";
print "</tr>";
// Store to DB
$Update = mysql_db_query($dbname, "UPDATE newsdesign SET
sAlignment='$sAlignment', sWidth='$sWidth', sBSize='$sBSize', sBColor=UCASE('$sBColor'),
hTitle='$hTitle', hBold='$hBold', hAlignment='$hAlignment', hBGcolor=UCASE('$hBGcolor'),
hFont='$hFont', hColor=UCASE('$hColor'), hSize='$hSize', dDate='$dDate', dTime='$dTime',
dAlignment='$dAlignment', dBold='$dBold', dFont='$dFont', dColor=UCASE('$dColor'),
dSize='$dSize', cAlignment='$cAlignment', cBGcolor=UCASE('$cBGcolor'), cBold=UCASE('$cBold'),
cFont='$cFont', cColor=UCASE('$cColor'), cSize='$cSize', cShowMax='$cShowMax'");
}
// Get values from DB
$result = mysql_db_query($dbname, "SELECT * FROM newsdesign");
$row = mysql_fetch_array($result);
$id = $row["id"];
$sAlignment = $row["sAlignment"];
$sWidth = $row["sWidth"];
$sBSize = $row["sBSize"];
$sBColor = $row["sBColor"];
$hTitle = $row["hTitle"];
$hBold = $row["hBold"];
$hAlignment = $row["hAlignment"];
$hBGcolor = $row["hBGcolor"];
$hFont = $row["hFont"];
$hColor = $row["hColor"];
$hSize = $row["hSize"];
$dDate = $row["dDate"];
$dTime = $row["dTime"];
$dAlignment = $row["dAlignment"];
$dBold = $row["dBold"];
$dFont = $row["dFont"];
$dColor = $row["dColor"];
$dSize = $row["dSize"];
$cAlignment = $row["cAlignment"];
$cBGcolor = $row["cBGcolor"];
$cBold = $row["cBold"];
$cFont = $row["cFont"];
$cColor = $row["cColor"];
$cSize = $row["cSize"];
$cShowMax = $row["cShowMax"];
?>
Since no errors are givin to me in either PHP or the mySql error log, I have no clue where the porblem might be and if it is just the script itself. But the same problem happens to me on a differant script (SnipeGallery) just in a differant way(I'll point out my snipeGallery problems in the next post just for clearity and the ability to put another attachment in).
djmagic23
07-12-2003, 06:57 PM
now in snipe gallery's case, there are no forms on the front admin page. i can see my test tables and what not, but i cannot delete or edit or add anything. Clicking any icons that lead me to such functions simple do not work. Only refreshing the page (similer to what happend on vNews). it does not give me the die('FATAL: cannot connect to mySQL server'); so I know it connected to the database, just none of the scripted actions now work. Again, I do not know what the problem is, if it is script side or mySql side or just me being an idiot about somthing.
djmagic23
07-12-2003, 07:05 PM
forgot the atachment.
about the first thing.
On top of the script, you've got
if ($saved=="true")
but i nowhere see a value set for this variable.
So the update will never be performed.
You can check this by putting this in front of it
echo "Value of saved = " . $saved ;
djmagic23
07-12-2003, 09:46 PM
I thought $saved would get changed from the hidden form field
<tr valign="middle">
<td colspan="2" bgcolor="#CCCCCC">
<div align="center"><font face="Verdana, Arial, Helvetica, sans-serif" size="2">
<input type="hidden" type="saved" value="true">
<input type="submit" name="Submit" value="Save settings">
<input type="reset" name="Reset" value="Reset">
</font></div>
</td>
</tr>
In older PHP versions, probably yes. But newer versions will have
register_globals as default set to 'off' now
So if you need the value for that variabel, you need to specify the collection. In your case, probably
$_POST['saved']
djmagic23
07-12-2003, 10:25 PM
Ah, i see. (the scripts that Im using were probably for an older PHP version) So where would i need to put $_POST['saved']? And with what syntax?
djmagic23
07-12-2003, 10:35 PM
Ok i figued out $_POST but now none of the form fields are updating. Im wondering if i now need to $_POST['var'] every <select> in the form.
djmagic23
07-12-2003, 10:39 PM
er not in select, in each variable declaration.
I don't quite follow you.
On the server you run the PHP on, you'll ptobably have register_globals set to off, cause there a huge security risk in havving globals on.
So when you refer to a variabel, that was not created in the script itself, then you need to specify the collection in which the variabel is. Check out
http://be.php.net/manual/en/language.variables.predefined.php
Buth when you dynamically insert values in a form, that you first stored in a variabel that was created in the script, then you can just refer to that like $varible
djmagic23
07-12-2003, 11:15 PM
ok, thank you for your help. I've gotton $saved to work (now that I've used $_POST) but the form updates the database with default values and not the values enterd in the form.will i need to use $_POST on the other variables so that they will relay to the database?
Yes.
Your query will look like
$Update = mysql_db_query($dbname, "UPDATE newsdesign SET
sAlignment='$POST_['sAlignment']', sWidth='$POST_['sWidth']', sBSize='$POST_['sBSize']',
and so on for all the other variables.
djmagic23
07-13-2003, 12:49 AM
All righty, thank you very much!
You're welcome.:thumbsup:
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.