[CS-FSLUG] another sql qustions
David McGlone
d.mcglone at att.net
Fri Dec 26 17:53:09 CST 2008
On Friday 26 December 2008 6:13:54 pm Frank Bax wrote:
> David McGlone wrote:
> > I can't seem to figure out how to write an UPDATE query for this form.
> > I've tried several different ways but nothing gets updated in the db.
> > Here is the code I have
<snip>
> $UpdateQuery = "UPDATE subheaderText SET
> subheaderText='".$_POST['subheaderText']."',"
> headerText='".$_POST['headerText']."'"
> WHERE pageID='".$_POST['pageID']."'";
>
> I sure hope I got all these quotes right! You might consider adding
> echo $UpdateQuery;
> to your script to see if the string you've created looks like valid sql
> before calling mysql_query().
>
> You should try to find log files for both mysql and apache. I often
> have terminal windows open that run 'tail -f' on these files so that I
> can see error messages as they are logged. These often provide very
> useful clues when you make a typo.
Thank you frank, Sorry, I should have posted more.
You mention this script being different from my first script, the reason is
after you gave me advice on that script, I played with it for hours, even
accidentally deleted the database table. Although that happened, I learned a
good deal on how to retrieve data from the database just by studying your
example.
Then I started another script (this one) with a new empty DB and started
trying to figure out how to put things in that database through forms and
such.
with the code I posted earlier, I only posted part of the code, so I will post
all of the relevant code this time. (sorry about that, I thought my sql
statements were what was giving me the problem)
finally, after I posted the first messaged, I took a cat nap because I was
mentally exhausted. LOL and then I came back and made some changes, and I
noticed in my previous UPDATE statement I was not naming the table, so I
changed that here, and gave it all another attempt. Anyway, here is the code
in it's entirety. After dinner I will go over your reply of the last message
and study it better. I really appreciate the advice. learning mySQL is proving
to be exhausting for me. :-)
$query = "SELECT * FROM subheaderText WHERE subheaderTextID=1";
$result = @mysql_query($query);
echo "<form name='subheader' action='$_SERVER[PHP_SELF]' method='POST'>";
while ($row = mysql_fetch_array($result)){
echo "<OPTION VALUE='subheaderText'>$row[subheaderText]<br>";
echo "<input type=text name='subheaderText' size='30'
value='$row[subheaderText]'>";
echo "<input type=text name='pageID' size='10' value='$row[pageID]'>";
echo "<textarea name='headerText' cols='50' rows='15'
/>$row[headerText]</textarea>";
}
$updateQuery= "UPDATE workshop.subheaderText SET subheaderText =
$subheaderText,
headerText = $headerText, pageID = $pageID WHERE subheaderText.subheaderTextID
=1 LIMIT 1";
$result2= mysql_query($updateQuery);
--
David M.
http://www.dmcentral.net
More information about the Christiansource
mailing list