Jump to content


Photo

Re: MySQL update syntax problem


  • Please log in to reply
9 replies to this topic

#1 roboseal

roboseal
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 10 September 2006 - 12:55 PM

I am so very confused about what you need help with.


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:


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


#2 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 10 September 2006 - 01:03 PM

Other than the fact that your string isn't quoted (the description column), you should be fine.
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

#3 roboseal

roboseal
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 10 September 2006 - 03:42 PM

Ouch bad mistake..... :-\ however I still can´t get it to work.

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;


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?

#4 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 10 September 2006 - 09:12 PM

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]' ");
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

#5 roboseal

roboseal
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 18 October 2006 - 01:16 AM

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:

<?
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>
<? } ?>

And this is the code that updates/modifies it:

<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>
<? } ?>


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 :) 



#6 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 19 October 2006 - 04:07 PM

I am so very confused about what you need help with.
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

#7 roboseal

roboseal
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 20 October 2006 - 02:24 AM

I am so very confused about what you need help with.


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:


<?
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;
?>



          <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>
<? } ?>


#8 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 20 October 2006 - 04:08 PM

So it's not pre-populating, or you want to append whatever was entered into this textarea into the db value regardless?
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

#9 roboseal

roboseal
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 20 October 2006 - 05:43 PM

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.

#10 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 22 October 2006 - 08:08 PM

And I assume you've verified elsewhere that there is such data in the record?  I don't see any record retrieval!
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users