| | |
Help With Messages in Mysql Stop Overwriting
Please support our MySQL advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Jul 2006
Posts: 19
Reputation:
Solved Threads: 1
Ok, I'm not sure why it's creating a new row in the db. I thought maybe you had the id column set to auto-increment, but I think the query would actually fail if you did that. It might be something to check first anyway...
I tried to mimic what you are trying to do, and below is what I did. It seems to work ok for me.
I set up a test db / table with the following parameters:
(If you're not familiar with this syntax, it can be copied and saved as a text file, then imported into mysql. If you're using phpmyadmin, you would create the database called
I then drafted
[php]
<?php
//you'll need to modify this line
require '../db_control.php';
echo "<p>Enter some text and then click Insert...</p>";
?>
<hr />
<tt>
<form action="<?= $PHP_SELF ?>" method="post">
User ID: <input type="text" name="user_id"><br />
From: <input type="text" name="fm"><br />
Message: <textarea name="mg"></textarea><br />
<input type="submit" name="submit" value="Insert">
</form>
</tt>
<hr />
<?
if ($_POST['submit']=='Insert') {
$user_id=$_POST['user_id'];
$fm=$_POST['fm'];
$last_login=time();
//clean up the message text
$mg = htmlentities($_POST['mg'],ENT_QUOTES);
$query="INSERT INTO test_table (user_id,fm,mg,last_login) VALUES ('$user_id','$fm','$mg','$last_login')";
echo "This is the query string that would be performed on the db:<br /><code><b>".$query."</b></code>";
echo "<p>Now performing query...</p>";
mysql_select_db('_test');
$result=mysql_query($query);
if (!$result) {
"There was a problem with your query.";
}
else {
echo "<p>Query performed successfully.</p>";
echo "This is the last row that was entered in the db:<br />";
$query2="SELECT * FROM test_table ORDER BY id DESC LIMIT 1";
$result2=mysql_query($query2);
$row = mysql_fetch_assoc($result2);
echo "<pre>"; print_r($row); echo "</pre>";
}
}
?>
[/php]
I know this code is ugly, but it does the trick for now. I like to get things working first and then pretty up the code later.
The php code will allow you to enter some text, submit the form, and then it will show you the results. If you use the code, remember to change the database name, etc. if needed.
I tried to mimic what you are trying to do, and below is what I did. It seems to work ok for me.
I set up a test db / table with the following parameters:
MySQL Syntax (Toggle Plain Text)
-- -- Database: `_test` -- -- -------------------------------------------------------- -- -- Table structure for table `test_table` -- CREATE TABLE `test_table` ( `id` INT(8) UNSIGNED ZEROFILL NOT NULL AUTO_INCREMENT, `user_id` VARCHAR(30) NOT NULL DEFAULT '', `fm` VARCHAR(50) NOT NULL DEFAULT '', `mg` BLOB NOT NULL, `last_login` VARCHAR(50) NOT NULL DEFAULT '', PRIMARY KEY (`id`) ) ENGINE=INNODB DEFAULT CHARSET=latin1;
_test, click the SQL tab and then select the file to import.)I then drafted
test.php page with the following code:[php]
<?php
//you'll need to modify this line
require '../db_control.php';
echo "<p>Enter some text and then click Insert...</p>";
?>
<hr />
<tt>
<form action="<?= $PHP_SELF ?>" method="post">
User ID: <input type="text" name="user_id"><br />
From: <input type="text" name="fm"><br />
Message: <textarea name="mg"></textarea><br />
<input type="submit" name="submit" value="Insert">
</form>
</tt>
<hr />
<?
if ($_POST['submit']=='Insert') {
$user_id=$_POST['user_id'];
$fm=$_POST['fm'];
$last_login=time();
//clean up the message text
$mg = htmlentities($_POST['mg'],ENT_QUOTES);
$query="INSERT INTO test_table (user_id,fm,mg,last_login) VALUES ('$user_id','$fm','$mg','$last_login')";
echo "This is the query string that would be performed on the db:<br /><code><b>".$query."</b></code>";
echo "<p>Now performing query...</p>";
mysql_select_db('_test');
$result=mysql_query($query);
if (!$result) {
"There was a problem with your query.";
}
else {
echo "<p>Query performed successfully.</p>";
echo "This is the last row that was entered in the db:<br />";
$query2="SELECT * FROM test_table ORDER BY id DESC LIMIT 1";
$result2=mysql_query($query2);
$row = mysql_fetch_assoc($result2);
echo "<pre>"; print_r($row); echo "</pre>";
}
}
?>
[/php]
I know this code is ugly, but it does the trick for now. I like to get things working first and then pretty up the code later.
The php code will allow you to enter some text, submit the form, and then it will show you the results. If you use the code, remember to change the database name, etc. if needed.
•
•
Join Date: Mar 2006
Posts: 52
Reputation:
Solved Threads: 0
That is really kind of you! Good heavens I am truly pleasantly suprised, Thanks so much!
I did the test_table , brought up the code as test.php and I see it all.
On the Test_table mysql said I had an error with :
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
What is that? I took it out the table is showing with everything else.
You know what I want to ask you is this, Is their a php code that repeats the INSERT INTO the same Id : The ID stays the same of course ID 2 is John for example:
But I need all fm's and mg'g to repeat and store log in Johns Id#2 , is this possible do you know. Cause that is what the idea is right i want all john's messages to log under his ID in the mysql database...
Now I filled out the form but I don't see nothing in the test table what do I do?....
Is it something to do with I needing to add Id's or is it because of this line: ENGINE=InnoDB DEFAULT CHARSET=latin1;
I'm confussed I'm going to look it over...
Thanks again really, puddin
I did the test_table , brought up the code as test.php and I see it all.
On the Test_table mysql said I had an error with :
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
What is that? I took it out the table is showing with everything else.
You know what I want to ask you is this, Is their a php code that repeats the INSERT INTO the same Id : The ID stays the same of course ID 2 is John for example:
But I need all fm's and mg'g to repeat and store log in Johns Id#2 , is this possible do you know. Cause that is what the idea is right i want all john's messages to log under his ID in the mysql database...
Now I filled out the form but I don't see nothing in the test table what do I do?....
Is it something to do with I needing to add Id's or is it because of this line: ENGINE=InnoDB DEFAULT CHARSET=latin1;
I'm confussed I'm going to look it over...
Thanks again really, puddin
Last edited by puddin; Jul 7th, 2006 at 3:39 pm.
•
•
Join Date: Mar 2006
Posts: 52
Reputation:
Solved Threads: 0
I want to show you this is what I have now:
HERE IT IS GETTING WHO THE MESSAGE IS FROM THE SENDER
<?php
include 'db.php';
// get the variables from home page
$password = $_SESSION['password'];
$email_address = $_SESSION['email_address'];
$sql_check = mysql_query("SELECT fm FROM myd WHERE id='2'");
$fm = mysql_fetch_array($sql_check, MYSQL_BOTH); //MYSQL_BOTH;
$sql_check_num = mysql_num_rows($sql_check);
if($sql_check_num == 0){
echo ("");
} else {
echo ("");
}
?>
</p>
HERE IT IS PRINTING AND SHOWING THE SENDER THE MESSAGE IS FROM THEM
<p class="fm">
<?echo ucfirst($fm['fm']);?>
</p>
HERE IT IS GETTING THE MESSAGE THE SENDER IS SENDING
<?php
include 'db.php';
// get the variables from home page
$password = $_SESSION['password'];
$email_address = $_SESSION['email_address'];
$sql_check = mysql_query("SELECT mg FROM myd WHERE id='2'");
$mg = mysql_fetch_array($sql_check, MYSQL_BOTH); //MYSQL_BOTH;
$sql_check_num = mysql_num_rows($sql_check);
if($sql_check_num == 0){
echo ("");
} else {
echo ("");
}
?>
HERE IT IS PRINTING THE MESSAGE FOR THE SENDER TO VIEW
<p class="mb">
<u><?echo ucfirst($mg['mg']);?></u>
NOW AS YOU SEE ABOVE THIS MESSAGE IS BEING SENT TO MEMBER ID='2'
THE SENDER GETS TO VIEW THE COMPLETE WHO IT IS FROM AND MESSAGE, THEY LIKE IT ALL IS GOOD, THAN I HAVE A BUTTON THAT THEY CLICK TO CONFIRM AND IT GOES.
MY PROBLEM IS THE ID'S RECIEVING THEIR MESSAGES BECAUSE I AM USING UPDATE ONLY CAN RECIEVE ONE MESSAGE , UPDATE DOES NOT KEEP ALL THE MESSAGES BEING SENT , UPDATE OVERWRITES THE LAST MESSAGE, HOW DO I SCRIPT IT THAT ALL THE MESSAGES ARE KEPT IN MYSQL AND I CAN RELEASE THEM ON THE ID'S MESSAGE PAGE BY SELECTING FM' AND MG' SEVERAL TIMES AND ALL THE MESSAGES WILL SHOW. HOW DO I GET THE MYSQL DATABASE TO NOT OVERWRITE!
THIS IS THE MOST DIFFICULT PART I HAVE COME ACROSS.... IS IT SOMETHING.. HOW DO THEY DO THIS!
HERE IT IS GETTING WHO THE MESSAGE IS FROM THE SENDER
<?php
include 'db.php';
// get the variables from home page
$password = $_SESSION['password'];
$email_address = $_SESSION['email_address'];
$sql_check = mysql_query("SELECT fm FROM myd WHERE id='2'");
$fm = mysql_fetch_array($sql_check, MYSQL_BOTH); //MYSQL_BOTH;
$sql_check_num = mysql_num_rows($sql_check);
if($sql_check_num == 0){
echo ("");
} else {
echo ("");
}
?>
</p>
HERE IT IS PRINTING AND SHOWING THE SENDER THE MESSAGE IS FROM THEM
<p class="fm">
<?echo ucfirst($fm['fm']);?>
</p>
HERE IT IS GETTING THE MESSAGE THE SENDER IS SENDING
<?php
include 'db.php';
// get the variables from home page
$password = $_SESSION['password'];
$email_address = $_SESSION['email_address'];
$sql_check = mysql_query("SELECT mg FROM myd WHERE id='2'");
$mg = mysql_fetch_array($sql_check, MYSQL_BOTH); //MYSQL_BOTH;
$sql_check_num = mysql_num_rows($sql_check);
if($sql_check_num == 0){
echo ("");
} else {
echo ("");
}
?>
HERE IT IS PRINTING THE MESSAGE FOR THE SENDER TO VIEW
<p class="mb">
<u><?echo ucfirst($mg['mg']);?></u>
NOW AS YOU SEE ABOVE THIS MESSAGE IS BEING SENT TO MEMBER ID='2'
THE SENDER GETS TO VIEW THE COMPLETE WHO IT IS FROM AND MESSAGE, THEY LIKE IT ALL IS GOOD, THAN I HAVE A BUTTON THAT THEY CLICK TO CONFIRM AND IT GOES.
MY PROBLEM IS THE ID'S RECIEVING THEIR MESSAGES BECAUSE I AM USING UPDATE ONLY CAN RECIEVE ONE MESSAGE , UPDATE DOES NOT KEEP ALL THE MESSAGES BEING SENT , UPDATE OVERWRITES THE LAST MESSAGE, HOW DO I SCRIPT IT THAT ALL THE MESSAGES ARE KEPT IN MYSQL AND I CAN RELEASE THEM ON THE ID'S MESSAGE PAGE BY SELECTING FM' AND MG' SEVERAL TIMES AND ALL THE MESSAGES WILL SHOW. HOW DO I GET THE MYSQL DATABASE TO NOT OVERWRITE!
THIS IS THE MOST DIFFICULT PART I HAVE COME ACROSS.... IS IT SOMETHING.. HOW DO THEY DO THIS!
•
•
Join Date: Jul 2006
Posts: 19
Reputation:
Solved Threads: 1
The text after the closing paranthese in the mysql table definition shouldn't matter. It definitely isn't impacting the id thing.
If the table wasn't created successfully, remove the text
If the table wasn't created successfully, remove the text
ENGINE=InnoDB DEFAULT CHARSET=latin1 from the mysql definition and try importing it again. Once the table is properly created, pressing Insert on the HTML form should insert a row into the table. ![]() |
Similar Threads
Other Threads in the MySQL Forum
- Previous Thread: Need authoritative source on safety of resetting ft_min_word_len
- Next Thread: Desperate again
| Thread Tools | Search this Thread |
agplv3 alfresco amazon api artisticlicense aws bizspark breathalyzer camparingtocolumns changingprices cmg communityjournalism contentmanagement contractors copyright count court crm data database design developer development distinct drupal dui ec2 email enter enterprise eudora facebook form foss gartner gnu government gpl greenit groklaw groupware hiring hyperic images innerjoins insert ip joebrockmeier join journalism keyword keywords kickfire laptop law legal license licensing linux maintenance managing mariadb metron micromanage microsoft microsoftexchange mindtouch montywidenius mozilla music mysql mysqlcolumnupdating mysqldatetimeordermax() mysqlindex mysqlinternalqueries mysqlquery mysqlsearch news open-xchange opendatabasealliance opensource oracle php priceupdating query referencedesign reorderingcolumns resultset saas select sharepoint simpledb sourcecode spotify sql sugarcrm syntax techsupport thunderbird transparency





