nightkarnation Posted August 27, 2008 Share Posted August 27, 2008 Ok here's my doubt... Lets say i have the following code on php: if ($action == "writeMyChat") { $time = time(); $chat=$_POST['myChat']; mysql_connect("localhost", "root", "") or die(mysql_error()); mysql_select_db("learning") or die(mysql_error()); mysql_query("INSERT INTO `chat` (chat, messageTime) VALUES ('$chat', '$time')"); } The values are actually coming from Flash...sometimes some data is missed and not stored on mysql ... Is there a simple way to tell php or flash that "hey, it didnt save on mysql, loop again until it saves" Any ideas?? thanx for the help in advance, Cheers! Quote Link to comment https://forums.phpfreaks.com/topic/121494-stable-best-way-to-insert-into-mysql-from-php/ Share on other sites More sharing options...
Stooney Posted August 27, 2008 Share Posted August 27, 2008 After the insert query, run a query requesting the same information. If it's there you're fine, otherwise try again. $result=mysql_query("SELECT messageTime FROM `chat` WHERE `chat`='$chat' AND `messageTime`='$time'"); if(mysql_num_rows($result)==1){ //Good } else{ //Do it again } Quote Link to comment https://forums.phpfreaks.com/topic/121494-stable-best-way-to-insert-into-mysql-from-php/#findComment-626554 Share on other sites More sharing options...
nightkarnation Posted August 27, 2008 Author Share Posted August 27, 2008 Perfect !! Thanx Chris! Cheers bro, Quote Link to comment https://forums.phpfreaks.com/topic/121494-stable-best-way-to-insert-into-mysql-from-php/#findComment-626579 Share on other sites More sharing options...
True`Logic Posted August 27, 2008 Share Posted August 27, 2008 <?php //--mysql_connect stuff--// function newentry($id) { $sqls = "update TABLE set "; $sqle = " where id=$id"; mysql_query("insert into TABLE(id) values('$id')"); mysql_query($sqls."VARRIABLE=VALUE".$sqle); mysql_query($sqls."VARRIABLE=VALUE".$sqle); mysql_query($sqls."VARRIABLE=VALUE".$sqle); mysql_query($sqls."VARRIABLE=VALUE".$sqle); //--etc } ?> (on one of my php games the signup line was so long that mysql wouldn't handle it, so I had to resort to this method, it works though .. the reason for $sqls and $sqle is simply to save space\time when writing it) Quote Link to comment https://forums.phpfreaks.com/topic/121494-stable-best-way-to-insert-into-mysql-from-php/#findComment-626641 Share on other sites More sharing options...
Fadion Posted August 27, 2008 Share Posted August 27, 2008 Wouldn't it be better to check if the variables are empty or not? <?php if(!$chat && !$time){ //variables empty, dont insert them } else{ //run the insert query } ?> Quote Link to comment https://forums.phpfreaks.com/topic/121494-stable-best-way-to-insert-into-mysql-from-php/#findComment-626718 Share on other sites More sharing options...
Ken2k7 Posted August 27, 2008 Share Posted August 27, 2008 Wouldn't it be better to check if the variables are empty or not? <?php if(!$chat && !$time){ //variables empty, dont insert them } else{ //run the insert query } ?> I doubt $time will be empty or undefined. <?php //--mysql_connect stuff--// function newentry($id) { $sqls = "update TABLE set "; $sqle = " where id=$id"; mysql_query("insert into TABLE(id) values('$id')"); mysql_query($sqls."VARRIABLE=VALUE".$sqle); mysql_query($sqls."VARRIABLE=VALUE".$sqle); mysql_query($sqls."VARRIABLE=VALUE".$sqle); mysql_query($sqls."VARRIABLE=VALUE".$sqle); //--etc } ?> (on one of my php games the signup line was so long that mysql wouldn't handle it, so I had to resort to this method, it works though .. the reason for $sqls and $sqle is simply to save space\time when writing it) You misspelled "variable". Quote Link to comment https://forums.phpfreaks.com/topic/121494-stable-best-way-to-insert-into-mysql-from-php/#findComment-626722 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.