Jump to content

Archived

This topic is now archived and is closed to further replies.

roboseal

Re: MySQL update syntax problem

Recommended Posts

[quote author=fenway link=topic=107534.msg454474#msg454474 date=1161274044]
I am so very confused about what you need help with.
[/quote]

hehe ok, i will try to explain in a simpler way.

When i use update the data using the "event_add.4php" i want the textfield to be populated with the data already in the database.

But it doesn´t fetch that data, the textfield is blank, but i want it to populate the field with  <? echo '$_POST[anmalda]; ?>

so if I add for example: "Robert" in the textfiled and press update, the next time i want to update the textield is alrady populated with "Robert" and i can add for example "Mark", and the nextime the texfield is populated with "robert", "Mark" ....and so on.

Am I making any sense?  :D

the query looks like this:

[code]

<?
IF(isset($_POST['submit'])){
require_once("includes/config.php");
$db_connection = mysql_connect %[/code]

Share this post


Link to post
Share on other sites
Other than the fact that your string isn't quoted (the description column), you should be fine.

Share this post


Link to post
Share on other sites
Ouch bad mistake..... :-\ however I still can´t get it to work.

[quote]mysql_query("INSERT INTO $db_table ( `event_id` , `event_day` , `event_month` , `event_year` , `event_time` , `event_title` , `event_desc` ) VALUES ('', '$_POST[day]', '$_POST[month]', '$_POST[year]', '$_POST[hour]:$_POST[minute]', '$_POST[event_title]', '$_POST[description]')");
$_POST['month'] = $_POST['month'] + 1;[/quote]

How would it look if you translate the above to update instead of insert? i think i have som trouble with all ( ' " ?
or is it even possible? maybe i have to rewrite everything?

Share this post


Link to post
Share on other sites
mysql_query("UPDATE $db_table SET `event_day` = '$_POST[day]', `event_month`= '$_POST[month]', `event_year` =  '$_POST[year]', `event_time` = $_POST[hour]:$_POST[minute]' , `event_title` = '$_POST[event_title]' , `event_desc` = '$_POST[description]' ");

Share this post


Link to post
Share on other sites
Been away for a while...however i managed to get it to update now...thanks  :D

Now to my next problem....

I want the data that already exists to show in the textfield when i update....more or less "adding" more information instead of just update the data, and i seem to have some problems declaring the variables (i think).


This is the event that gets the data and shows it:

[code]<?
require_once("includes/config.php");
$db_connection = mysql_connect ($DBHost, $DBUser, $DBPass) OR die (mysql_error()); 
$db_select = mysql_select_db ($DBName) or die (mysql_error());
$db_table = $TBL_PR . "events";

$query = "SELECT * FROM $db_table WHERE event_id='$_GET[id]' LIMIT 1";
$query_result = mysql_query ($query);
while ($info = mysql_fetch_array($query_result)){
    $date = date ("l, jS F Y", mktime(0,0,0,$info['event_month'],$info['event_day'],$info['event_year']));
    $time_array = split(":", $info['event_time']);
    $time = date ("H:i:s", mktime($time_array['0'],$time_array['1'],0,$info['event_month'],$info['event_day'],$info['event_year']));
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Easy Calendar Event: <? echo $info['event_title']; ?></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="images/cal.css" rel="stylesheet" type="text/css">
<style type="text/css">
<!--
body {
background-color: #666666;
}
-->
</style></head>

<body>
<table width="480" height="180" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td height="100">
<table width="480" border="0" cellpadding="0" cellspacing="0">
        <tr>
          <td><span class="eventwhen"><u><? echo $date . " at " . $time; ?></u></span><br>
            <br> <br> </td>
        </tr>
        <tr>
          <td><span class="event">Instans</span></td>
        </tr>
        <tr>
          <td><span class="eventdetail"><? echo $info['event_title']; ?></span><br>
            <br></td>
        </tr>
        <tr>
          <td><span class="event">Beskrivning</span></td>
        </tr>
        <tr>
          <td><span class="eventdetail"><? echo $info['event_desc']; ?></span><br></td>
        </tr>
        <tr>
          <td><span class="event">Anmälda</span></td>
        </tr>
<tr>
          <td><span class="eventdetail"><? echo $info['event_anmalda']; ?></span><br></td>
        </tr>
      </table></td>
  </tr>

  <tr>
    <td align="center" valign="bottom"><a href="event_delete.php?<? echo "day=$info[event_day]&month=$info[event_month]&year=$info[event_year]&id=$info[event_id]"; ?>">Delete</a></td>&nbsp;
<tr>
</tr>   
<td align="center" valign="bottom"><a href="event_add4.php?<? echo "day=$info[event_day]&month=$info[event_month]&year=$info[event_year]&id=$info[event_id]"; ?>">Anmäl</a></td>

  </tr>

</table>
</body>
</html>
<? } ?>[/code]

And this is the code that updates/modifies it:

[code]<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="images/cal.css" rel="stylesheet" type="text/css">
<style type="text/css">
<!--
body {
background-color: #666666;
}
-->
</style>

</head>
<

<body>
<form name="form1" method="post" action="">
  <table width="480" border="0" cellspacing="0" cellpadding="0">
    <tr>
      <td width="200" height="40" valign="top"><span class="addevent">Event Date</span><br>
        <span class="addeventextrainfo">(MM/DD/YY)</span></td>
      <td height="40" valign="top"> <select  name="month" id="month">
          <option value="1" <? IF($_GET['month'] == "1"){ echo "selected"; } ?>>01</option>
          <option value="2" <? IF($_GET['month'] == "2"){ echo "selected"; } ?>>02</option>
          <option value="3" <? IF($_GET['month'] == "3"){ echo "selected"; } ?>>03</option>
          <option value="4" <? IF($_GET['month'] == "4"){ echo "selected"; } ?>>04</option>
          <option value="5" <? IF($_GET['month'] == "5"){ echo "selected"; } ?>>05</option>
          <option value="6" <? IF($_GET['month'] == "6"){ echo "selected"; } ?>>06</option>
          <option value="7" <? IF($_GET['month'] == "7"){ echo "selected"; } ?>>07</option>
          <option value="8" <? IF($_GET['month'] == "8"){ echo "selected"; } ?>>08</option>
          <option value="9" <? IF($_GET['month'] == "9"){ echo "selected"; } ?>>09</option>
          <option value="10" <? IF($_GET['month'] == "10"){ echo "selected"; } ?>>10</option>
          <option value="11" <? IF($_GET['month'] == "11"){ echo "selected"; } ?>>11</option>
          <option value="12" <? IF($_GET['month'] == "12"){ echo "selected"; } ?>>12</option>
        </select> <select name="day" id="day">
          <option value="1" <? IF($_GET['day'] == "1"){ echo "selected"; } ?>>01</option>
          <option value="2" <? IF($_GET['day'] == "2"){ echo "selected"; } ?>>02</option>
          <option value="3" <? IF($_GET['day'] == "3"){ echo "selected"; } ?>>03</option>
          <option value="4" <? IF($_GET['day'] == "4"){ echo "selected"; } ?>>04</option>
          <option value="5" <? IF($_GET['day'] == "5"){ echo "selected"; } ?>>05</option>
          <option value="6" <? IF($_GET['day'] == "6"){ echo "selected"; } ?>>06</option>
          <option value="7" <? IF($_GET['day'] == "7"){ echo "selected"; } ?>>07</option>
          <option value="8" <? IF($_GET['day'] == "8"){ echo "selected"; } ?>>08</option>
          <option value="9" <? IF($_GET['day'] == "9"){ echo "selected"; } ?>>09</option>
          <option value="10" <? IF($_GET['day'] == "10"){ echo "selected"; } ?>>10</option>
          <option value="11" <? IF($_GET['day'] == "11"){ echo "selected"; } ?>>11</option>
          <option value="12" <? IF($_GET['day'] == "12"){ echo "selected"; } ?>>12</option>
          <option value="13" <? IF($_GET['day'] == "13"){ echo "selected"; } ?>>13</option>
          <option value="14" <? IF($_GET['day'] == "14"){ echo "selected"; } ?>>14</option>
          <option value="15" <? IF($_GET['day'] == "15"){ echo "selected"; } ?>>15</option>
          <option value="16" <? IF($_GET['day'] == "16"){ echo "selected"; } ?>>16</option>
          <option value="17" <? IF($_GET['day'] == "17"){ echo "selected"; } ?>>17</option>
          <option value="18" <? IF($_GET['day'] == "18"){ echo "selected"; } ?>>18</option>
          <option value="19" <? IF($_GET['day'] == "19"){ echo "selected"; } ?>>19</option>
          <option value="20" <? IF($_GET['day'] == "20"){ echo "selected"; } ?>>20</option>
          <option value="21" <? IF($_GET['day'] == "21"){ echo "selected"; } ?>>21</option>
          <option value="22" <? IF($_GET['day'] == "22"){ echo "selected"; } ?>>22</option>
          <option value="23" <? IF($_GET['day'] == "23"){ echo "selected"; } ?>>23</option>
          <option value="24" <? IF($_GET['day'] == "24"){ echo "selected"; } ?>>24</option>
          <option value="25" <? IF($_GET['day'] == "25"){ echo "selected"; } ?>>25</option>
          <option value="26" <? IF($_GET['day'] == "26"){ echo "selected"; } ?>>26</option>
          <option value="27" <? IF($_GET['day'] == "27"){ echo "selected"; } ?>>27</option>
          <option value="28" <? IF($_GET['day'] == "28"){ echo "selected"; } ?>>28</option>
          <option value="29" <? IF($_GET['day'] == "29"){ echo "selected"; } ?>>29</option>
          <option value="30" <? IF($_GET['day'] == "30"){ echo "selected"; } ?>>30</option>
          <option value="31" <? IF($_GET['day'] == "31"){ echo "selected"; } ?>>31</option>
        </select> <select name="year" id="year">
          <option value="2003" <? IF($_GET['year'] == "2003"){ echo "selected"; } ?>>2003</option>
          <option value="2004" <? IF($_GET['year'] == "2004"){ echo "selected"; } ?>>2004</option>
          <option value="2005" <? IF($_GET['year'] == "2005"){ echo "selected"; } ?>>2005</option>
          <option value="2006" <? IF($_GET['year'] == "2006"){ echo "selected"; } ?>>2006</option>
          <option value="2007" <? IF($_GET['year'] == "2007"){ echo "selected"; } ?>>2007</option>
        </select> </td>
    </tr>  
    <tr>



          <td><span class="event">Beskrivning</span></td>
        </tr>
        <tr>
          <td><span class="eventdetail"><? echo $_get['title']; ?></span><br></td>
        </tr>
        <tr>
<tr>
     <td width="200" height="40" valign="top"><span class="addevent">Anmäl</span></td>
      <td height="40" valign="top"> <textarea name="anmalda" cols="24" id="anmalda" ><? echo $_GET['id']; ?></textarea>
      </td>
    </tr>
    <tr>
      <td width="200">&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td><input name="submit" type="submit" id="submit" value="Uppdatera"></td>
    </tr>
  </table>
</form>
</body>
</html>
<? } ?>[/code]


At the textarea (near the bottom you can see that i added <? echo $_GET['id']; ?></textarea> that´s just to see that it´s possible to get that data to show in the textfield, but i want it to show <? echo $info['event_anmalda']; ?>  (as it does in the "event" code) ie the existing data already stored for that field so i can add more data, but i don´t seem to be able to pass/state that variable?

And how do i put line breaks so the data in that field shows on separate lines?

line1
line2
..and so on

Because if i can get this to work i´m hoping i can store the field  'event_anmalda' as a separate table to link to a 'id' so for example when i click the link "anmal" on a specific day, i can then add data that the "event.php" will pick from the table 'event_anmalda' .......but we can leave that for now ,i guess i will try for a couple of days before asking, though a point in the right direction is always appriciated  ;)


A quick summary what i´m trying to achieve is that you click a day in the calendar you add a event to happen on that day, then you have a link to "sign up" to that event.....maybe you know better or easier ways to do this, and if so i´d really really appriciate all the help i can get.

thx for now, looking forward to some serious coding a couple of nights if i just can get passed som obstacles on the way :) 

Share this post


Link to post
Share on other sites
I am so very confused about what you need help with.

Share this post


Link to post
Share on other sites
[quote author=fenway link=topic=107534.msg454474#msg454474 date=1161274044]
I am so very confused about what you need help with.
[/quote]

hehe ok, i will try to explain in a simpler way.

When i use update the data using the "event_add.4php" i want the textfield to be populated with the data already in the database.

But it doesn´t fetch that data, the textfield is blank, but i want it to populate the field with  <? echo '$_POST[anmalda]; ?>

so if I add for example: "Robert" in the textfiled and press update, the next time i want to update the textield is alrady populated with "Robert" and i can add for example "Mark", and the nextime the texfield is populated with "robert", "Mark" ....and so on.

Am I making any sense?  :D

The query looks like this:

[code]

<?
IF(isset($_POST['submit'])){
require_once("includes/config.php");
$db_connection = mysql_connect ($DBHost, $DBUser, $DBPass) OR die (mysql_error()); 
$db_select = mysql_select_db ($DBName) or die (mysql_error());
$db_table = $TBL_PR . "events";


mysql_query ("UPDATE $db_table SET  `event_anmalda` = '$_POST[anmalda]' WHERE event_id='$_GET[id]'")
or die("<b>A fatal MySQL error occured</b>.\n<br />Query: " . $query . "<br />\nError: (" . mysql_errno() . ") " . mysql_error());


$_POST['month'] = $_POST['month'] + 1;
?>


[/code]

          <td><span class="event">Beskrivning</span></td>
        </tr>
        <tr>
          <td><span class="eventdetail"><? echo $_get['title']; ?></span><br></td>
        </tr>
        <tr>
<tr>
    <td width="200" height="40" valign="top"><span class="addevent">Anmäl</span></td>
      <td height="40" valign="top"> <textarea name="anmalda" cols="24" id="anmalda" ><? echo '$_POST[anmalda]; ?></textarea>
      </td>
    </tr>
    <tr>
      <td width="200">&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td><input name="submit" type="submit" id="submit" value="Uppdatera"></td>
    </tr>
  </table>
</form>
</body>
</html>
<? } ?>

Share this post


Link to post
Share on other sites
So it's not pre-populating, or you want to append whatever was entered into this textarea into the db value regardless?

Share this post


Link to post
Share on other sites
It´s not pre-populating, i´s just empty even if I have the <textarea name="anmalda" cols="24" id="anmalda" ><? echo '$_POST[anmalda]; ?></textarea>

Was hoping the textarea would be filled with the data already in the DB.

Share this post


Link to post
Share on other sites
And I assume you've verified elsewhere that there is such data in the record?  I don't see any record retrieval!

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.