PHP - Unread Message Function
Hey, im trying to create a little function that displays how many unread messages a user has
this is my function Code: [Select] function unread() { $sql_pm_r = mysql_query("SELECT COUNT(*) FROM messages WHERE reciever=" . $user . " AND recieved='0'"); $num_rows = mysql_num_rows($sql_pm_r); $sql_pm_check = mysql_query("SELECT id FROM messages WHERE reciever=" . $user . " AND recieved='0' LIMIT 1"); $num_new_pm = mysql_num_rows($sql_pm_check); if ($num_new_pm > 0) { $pms = '<a href="inbox.php" >('.$num_rows.')</a>'; } else { $pms = '<a href="inbox.php" >(0)</a>'; } echo $pms; }and i'm calling it on the index page as normal like Code: [Select] unread(); However not matter how many unread messages i have, i always get (0), this is how my sql table looks id reciever sender subject message recieved Similar TutorialsHello World ! i got this script of PM system on my website where 2 or 3 users can send PM to each other it work ok but it <?php header : PM (unread count) $msgs_count = GetUnreadMessagesCount($session_user["id"]); and got this in the Index header : PM <span>( <?=$msgs_count;?> )</span> /* Hello World ! i got a website where 2 or 3 users can create and send PM everything work good but have this bug . */ Example message thread#id1 Sender: A send the message to B & C ok now B & C got PM (1) B make reply to this PM and C the same now the bug is userA will have PM(2) like he have 2unread messages but is different reply in the same message so need to count only (1) by Thread not reply ok if A read it and send new reply now B & C will have PM (3) i hope someone can help me with this code thank you ! this is message_tbl for database <?php $tbl_messages_fields = array( "id" => "INTEGER PRIMARY KEY AUTO_INCREMENT", "threadId" => "INT(11)", "type" => "VARCHAR(4)", "heldById" => "INT", "fromId" => "INT", "toId" => "VARCHAR(32)", "isRead" => "INT(1) $d0", "isStarred" => "INT(1) $d0", "isDeleted" => "INT(1) $d0", "subject" => "VARCHAR(150)", "message" => "VARCHAR(10000)", "timestamp" => "INT(12)"); SetupTable('tbl_messages', $tbl_messages_fields); function UpdateMessageField($conditions, $field, $value){ global $dbPrep; $add = array(); foreach($conditions as $key=>$val){ $add[] = "`$key`=:$key"; } $add = implode(" AND ", $add); $sql = "UPDATE `tbl_messages` SET $field=:$field WHERE $add"; $query = $dbPrep->prepare($sql); $data = array_merge($conditions, array("$field"=>$value)); $query->execute($data); } function GetMessagesQuery($data = array(), $complexConditions = "", $extra = ""){ $dbPrep = GetDatabaseConnection(); $sql = "SELECT * FROM `tbl_messages` "; $add = " "; foreach($data as $key=>$value){ $add.= "AND `$key`=:$key "; } $add = ($add != " ") ? "WHERE" . substr($add, 4, strlen($add)) : $add; $sql.= $add." ".$complexConditions." ".$extra; $query = $dbPrep->prepare($sql); $query->execute($data); return GetRows($query); } function GetThreadQuery($conditions = array(), $complexConditions = "", $extra = ""){ global $dbPrep; $add = array(); foreach($conditions as $key=>$val){ $add[] = "`$key`=:$key"; } $add = implode(" AND ", $add); $sql = "SELECT a.*, b.username AS fromUsername, b.type AS fromType FROM `tbl_messages` AS a "; $sql .= "INNER JOIN `tbl_users` AS b ON a.fromId=b.id "; $sql .= "WHERE $add ORDER BY timestamp ASC"; #echo $sql; $query = $dbPrep->prepare($sql); $query->execute($conditions); return GetRows($query); } $p_NewMessage = $dbPrep->prepare("INSERT INTO `tbl_messages` (type, threadId, heldById, fromId, toId, subject, message, timestamp) VALUES (:type, :threadId, :heldById, :fromId, :toId, :subject, :message, :timestamp);"); $sql = "SELECT a.*, b.type as fromType FROM `tbl_messages` AS a "; $sql .= "INNER JOIN `tbl_users` AS b ON a.fromId=b.id "; $sql .= "WHERE threadId=:id AND heldById=:heldById AND isDeleted=0 ORDER BY timestamp ASC"; $p_GetSingleMessage = $dbPrep->prepare($sql); function UnDeleteThread($threadId, $heldById){ global $dbPrep; $p_UnDeleteThread = $dbPrep->prepare("UPDATE `tbl_messages` SET isDeleted=0,isRead=0 WHERE threadId=:threadId AND heldById=:heldById"); $p_UnDeleteThread->execute(array("threadId"=>$threadId, "heldById"=>$heldById)); } function GetRecipients($sessId, $fromId, $toId){ $allParties = $sessId . "," . $fromId . "," . $toId; $arr = array_unique(explode(",", $allParties)); if (($key = array_search($sessId, $arr)) !== false) { unset($arr[$key]); } return implode (",", $arr); } function GetRecipientName($id){ global $dbPrep; $sql = "SELECT username FROM `tbl_users` WHERE id=:id"; $query = $dbPrep->prepare($sql); $query->execute(array("id"=>$id)); $row = $query->fetch( PDO::FETCH_ASSOC ); return $row["username"]; } function GetRecipientNames($recipients){ $all = explode(",", $recipients); $val = array(); foreach ($all as $a){ $val[] = GetRecipientName($a); } return $val; } $p_GetUnreadMessagesCount = $dbPrep->prepare("SELECT COUNT(*) FROM `tbl_messages` WHERE isRead=0 AND heldById=:heldById AND type='recv'"); $unreadMsgsCount = -1; function GetUnreadMessagesCount($uid){ global $unreadMsgsCount; global $p_GetUnreadMessagesCount; if($unreadMsgsCount == -1){ $p_GetUnreadMessagesCount->execute(array("heldById"=>$uid)); $unreadMsgsCount = $p_GetUnreadMessagesCount->fetch( PDO::FETCH_ASSOC ); $unreadMsgsCount = $unreadMsgsCount["COUNT(*)"]; } return $unreadMsgsCount; } function GetNewThreadId(){ global $dbPrep; $threadId = 1; $p_GetLatestThreadId = $dbPrep->prepare("SELECT MAX(threadId) FROM `tbl_messages`"); $p_GetLatestThreadId->execute(); $latestThreadId = $p_GetLatestThreadId->fetch( PDO::FETCH_ASSOC ); if($latestThreadId){ $threadId = $latestThreadId["MAX(threadId)"]+1; } return $threadId; } ?> if(isset($_REQUEST["mark_read"])){ if(isset($_REQUEST["message_all_toggle"])) foreach($_REQUEST["message_all"] as $m) SetNotificationRead($m, $session_user["id"], 1); elseif(isset($_REQUEST["message"])) foreach($_REQUEST["message"] as $m) SetNotificationRead($m, $session_user["id"], 1); else foreach($_REQUEST["message_all"] as $m) SetNotificationRead($m, $session_user["id"], 1); } if(isset($_REQUEST["mark_unread"])){ if(isset($_REQUEST["message_all_toggle"])) foreach($_REQUEST["message_all"] as $m) SetNotificationRead($m, $session_user["id"], 0); elseif(isset($_REQUEST["message"])) foreach($_REQUEST["message"] as $m) SetNotificationRead($m, $session_user["id"], 0); else foreach($_REQUEST["message_all"] as $m) SetNotificationRead($m, $session_user["id"], 0); } if(isset($_REQUEST["delete"])){ if(isset($_REQUEST["message_all_toggle"])) foreach($_REQUEST["message_all"] as $m) RemoveNotificationById($m, $session_user["id"]); elseif(isset($_REQUEST["message"])) foreach($_REQUEST["message"] as $m) RemoveNotificationById($m, $session_user["id"]); } } else { if(isset($_REQUEST["delete"])){ if(is_numeric($_REQUEST["delete"])){ UpdateMessageField(array("threadId"=>$_REQUEST["delete"], "heldById"=>$session_user["id"]), "isStarred", 0); UpdateMessageField(array("threadId"=>$_REQUEST["delete"], "heldById"=>$session_user["id"]), "isDeleted", 1); UpdateMessageField(array("threadId"=>$_REQUEST["delete"], "heldById"=>$session_user["id"]), "isRead", 1); }elseif(isset($_REQUEST["message_all_toggle"])){ $messages = $_REQUEST["message_all"]; foreach($messages as $m){ UpdateMessageField(array("threadId"=>$m, "heldById"=>$session_user["id"]), "isStarred", 0); UpdateMessageField(array("threadId"=>$m, "heldById"=>$session_user["id"]), "isDeleted", 1); UpdateMessageField(array("threadId"=>$m, "heldById"=>$session_user["id"]), "isRead", 1); } }elseif(isset($_REQUEST["message"])){ $messages = $_REQUEST["message"]; foreach($messages as $m){ UpdateMessageField(array("threadId"=>$m, "heldById"=>$session_user["id"]), "isStarred", 0); UpdateMessageField(array("threadId"=>$m, "heldById"=>$session_user["id"]), "isDeleted", 1); UpdateMessageField(array("threadId"=>$m, "heldById"=>$session_user["id"]), "isRead", 1); } } } if(isset($_REQUEST["messagestar"])){ if(isset($_REQUEST["message_all_toggle"])){ $messages = $_REQUEST["message_all"]; foreach($messages as $m){ UpdateMessageField(array("threadId"=>$m, "heldById"=>$session_user["id"]), "isStarred", 1); } }elseif(isset($_REQUEST["message"])){ $messages = $_REQUEST["message"]; foreach($messages as $m){ UpdateMessageField(array("threadId"=>$m, "heldById"=>$session_user["id"]), "isStarred", 1); } } } if(isset($_REQUEST["deletestarred"])){ if(isset($_REQUEST["message_all_toggle"])){ $messages = $_REQUEST["message_all"]; foreach($messages as $m){ UpdateMessageField(array("threadId"=>$m, "heldById"=>$session_user["id"]), "isStarred", 0); } }elseif(isset($_REQUEST["message"])){ $messages = $_REQUEST["message"]; foreach($messages as $m){ UpdateMessageField(array("threadId"=>$m, "heldById"=>$session_user["id"]), "isStarred", 0); } } } if(isset($_REQUEST["mark_unread"])){ if(isset($_REQUEST["message_all_toggle"])){ $messages = $_REQUEST["message_all"]; foreach($messages as $m){ UpdateMessageField(array("threadId"=>$m, "heldById"=>$session_user["id"]), "isRead", 0); } }elseif(isset($_REQUEST["message"])){ $messages = $_REQUEST["message"]; foreach($messages as $m){ UpdateMessageField(array("threadId"=>$m, "heldById"=>$session_user["id"]), "isRead", 0); } } } if(isset($_REQUEST["mark_read"])){ if(isset($_REQUEST["message_all_toggle"])){ $messages = $_REQUEST["message_all"]; foreach($messages as $m){ UpdateMessageField(array("threadId"=>$m, "heldById"=>$session_user["id"]), "isRead", 1); } }elseif(isset($_REQUEST["message"])){ $messages = $_REQUEST["message"]; foreach($messages as $m){ UpdateMessageField(array("threadId"=>$m, "heldById"=>$session_user["id"]), "isRead", 1); } } } } $details = isset($_REQUEST["details"])?$_REQUEST["details"]:0; $session_user = GetUserById($session_user["id"]);
Hi everyone, Hi all, I am just starting out in the world of php and have got this far with a lot of googling. But I'm really stuck with this part now. I have a function that works perfectly for display on a page, eg <?php echo quickquote(); ?> function quickquote() { global $db; global $cart; $cart = $_SESSION['cart']; if ($cart) { $items = explode(',',$cart); $contents = array(); foreach ($items as $item) { $contents[$item] = (isset($contents[$item])) ? $contents[$item] + 1 : 1; } $quickquote[] = 'Quote Required:<br />'; foreach ($contents as $id=>$qty) { $sql = 'SELECT * FROM products WHERE id = '.$id; $result = $db->query($sql); $row = $result->fetch(); extract($row); $quickquote[] = ''.$qty.''; $quickquote[] = ' x '; $quickquote[] = '' . $model . ''; $quickquote[] = ' (' . $type . '- '; $quickquote[] = ''. $basin . '- '; $quickquote[] = ''. $top . ')'; $quickquote[] = '<br />'; } $quickquote[] = 'End of Quick Quote Request'; } else { $quickquote[] = 'The quote cart is empty.'; } return join('',$quickquote); } However, i am trying to include this in an email message: if(!$error) { $messages="From: $email <br>"; $messages.="Name: $name <br>"; $messages.="Email: $email <br>"; $messages.="Phone: $phone <br>"; $messages.="Message: $message <br>"; $messages.="Quick Quote Request: $quickquote <br>"; $mail = mail($to,$subject,$messages,$headers); The email also works perfectly with the exception that the data is not there from $quickquote. I've tried all sorts of variations and suggested solutions from the web but nothing I've tried has been successful so far. It's amazing that I've got this far so I don't want to give up on it, but I'm just completely stumped ... All information and help very much appreciated. Cheers K I'm trying to call a function inside an iFrame inside Wordpress, and I'm getting this error message: Code: [Select] Fatal error: Call to a member function get_results() on a non-object in What is this supposed to mean? By the way the function DOES work when it's NOT called inside the iFrame, but as soon as I call it inside the iFrame I get the error message. Why is that? Hi, I am using PHP mail() function to sent message. Following is the code, the message is received in email account, but as attachment, not displayed in the body section as normal message would. Please can you guys help, as why is this message going as attachment, but not being displayed in the body of email. Below is the url which gives preview as to what I mean. http://i56.tinypic.com/29fujxf.jpg Code: [Select] $to = $_POST['to']; $subject = ' web visior'; $customer = stripslashes($_POST['customer']); $email = stripslashes($_POST['email']); $contactinfo = stripslashes($_POST['contactinfo']); $body = stripslashes($_POST['enquiry']); $header = 'From:'.$email.'\r\n'; $header = 'Reply-To:'.$email.'\r\n'; $header = 'X-Mailer: PHP/' . phpversion(); $header = 'Content-type: text/html\r\n'; $message = '<html><body> <table> <tr><td>From:'.$customer.'</td></tr> <tr><td>Email:'.$email.'</td></tr> <tr><td>Contact No'.$contactinfo.'</td></tr> <tr><td style="center"><b>Message:</b></td></tr> <tr><td>'.$body.'</td></tr> </body></html>'; Regards, Abhishek Hello. My first topic here was about getting the amount of unread messages. I'm now working on showing the unread messages in the inbox. Let's say we have 2 users. User1 sends user2 a message with the title: this is a title. User2 read the message and replied. User1 now has to see: this is a title. This is the code in: class Pm {} public function get_unread_pm() { $stmt = $this->db->prepare(' SELECT pm.title, pm.sender_id, pm.timestamp, (SELECT COUNT(pm2.id) FROM pm as pm1, pm as pm2 WHERE pm1.parent_id=pm2.id) AS replies, u.username as sender FROM pm LEFT JOIN users AS u ON u.id=pm.sender_id WHERE pm.receiver_id=:user_id AND pm.unread=1 AND pm.parent_id=pm.id'); $stmt->bindParam('user_id', $_SESSION['userid']); $stmt->execute(); return $stmt->fetchAll(); } I now get the original message because of the pm.parent=pm.id, but I want to get the message where the parent_id of a reply is the same parent_id as where the parent_id is equal to it's id. I think a less complicated description is: How do I get the last reply instead of the original message?
parent_id: When I reply to a message, my id still counts up, the parent_id is the id of the original message. This is what my data-table looks like:
The content:
If I'm doing this stuff really inefficient, I would be happy to know how to make it better Fabian Edited September 19, 2019 by FabelHi, I am learning pdo php and mysql
I would like to know how to see whether a record has been read or not. I have a database messages with id, user_id, contact_id, login, msg, rrecord and msgtime.
The rrecord column has been set as 0 as default. When the client clicks the msg link, I would like it to update the rrecord to 1.
Thanks.
I cant get this to work and I found a host with imap-ssl here is my code though i've been messing around with it. It cant get the imap_open to work. Code: [Select] $mbox = imap_open ("{imap.gmail.com:993/imap/ssl/novalidate-cert/norsh}Inbox", "username", "password", OP_READONLY) or die("can't connect: " . imap_last_error()); $check = imap_mailboxmsginfo($mbox); echo $check->Unread; / Please please help. Thanks I am trying to run this but it wont work. I get the following error. Warning: imap_open() [function.imap-open]: Couldn't open stream {imap.gmail.com:993/imap/ssl/novalidate-cert/norsh}Inbox in /home/u984345410/public_html/default.php Here is a snipit of the code Code: [Select] function CountUnreadMails($login, $passwd) { $mbox = imap_open("{imap.gmail.com:993/imap/ssl/novalidate-cert/norsh}Inbox", $login, $passwd, OP_READONLY); $count = 0; if (!$mbox) { echo "Error"; } else { $headers = imap_headers($mbox); foreach ($headers as $mail) { $flags = substr($mail, 0, 4); $isunr = (strpos($flags, "U") !== false); if ($isunr) $count++; } } imap_close($mbox); return $count; } Im working on my own (basic) forum sofware how would I determine if the user has read or unread the topic? (like SMF has a specific icon when viewing the forum/topic list which represents theirs unread topics within this forum). Everything about the email is sending except the message text does anyone know what the issue could be? here is the block of code that sends the email Thanks in advance Code: [Select] $image = "http://www.visualrealityink.com/dev/clients/arzan/snell_form/images/email.png"; echo "got to process form"; $target_path = "upload/"; $path = $target_path = $target_path . basename( $_FILES['file']['name']); $boundary = '-----=' . md5( uniqid ( rand() ) ); $message .= "Content-Type: application/msword; name=\"my attachment\"\n"; $message .= "Content-Transfer-Encoding: base64\n"; $message .= "Content-Disposition: attachment; filename=\"$path\"\n\n"; echo $path; $fp = fopen($path, 'r'); do //we loop until there is no data left { $data = fread($fp, 8192); if (strlen($data) == 0) break; $content .= $data; } while (true); $content_encode = chunk_split(base64_encode($content)); $message .= $content_encode . "\n"; $message .= "--" . $boundary . "\n"; $message .= $image . "<br />" . $_POST['name'] . "submitted a resume on our website. Please review the applications and contact the candidate if their resume is a fit for any open opportunities with the company. <br><br> Thank you. <br><br> SEI Team"; $headers = "From: \"Me\"<me@example.com>\n"; $headers .= "MIME-Version: 1.0\n"; $headers .= "Content-Type: multipart/mixed; boundary=\"$boundary\""; mail('george@visualrealityink.com', 'Email with attachment from PHP', $headers, $message); I just had a question for you guys. I am building a forum script and I'm currently stumped on the "show unread posts since last visit" feature. Not sure as to how to code it. Should I be using a mysql database to keep track of them or use cookies some how? Thanks in advanced! Hey Guys, I have followed a tutorial and got a SMS text message script working. Although what i would like to do now is allow a registered user to add another user via a form. This form will contain the users mobile number, email, who its from, and a textarea for the message to send to them in the text message. *** It also stores it into a database. But dont worry about that. I have run into a problem, when i type in a mobile number and an email address and then press send. It doesnt seem to store the email address in the $vars echo (message). **It does echo in the email bit but i wont it to show in the message bit. ** Here is a screenshot. right ive setup my own messaging feature on my website but it still allowes me to message myself if tried <? }else{ if($to == username){ ?> the whole code so you can get a better understanding <?php session_start(); include_once "includes/db_connect.php"; include_once "includes/functions.php"; logincheck(); $username=$_SESSION['username']; $fetch=mysql_fetch_object(mysql_query("SELECT * FROM users WHERE username='$username'")); if ($fetch->texts < '1'){ echo "<font color=red>You don't have No Texts Left</font><br>"; }elseif($fetch->texts >= '1'){ ?> <body onLoad="goaway();"><? $towho=$_GET['fromper']; $oldmsg=$_GET['oldmsg']; $text=$_POST['text']; $subject=$_POST['subject']; $fsubject=$_GET['fsubject']; $info=mysql_fetch_object(mysql_query("SELECT rank FROM users WHERE username='$username'")); $goody = mysql_query("SELECT `inbox`, `date`, `from` FROM `messages` WHERE `id`='$rep'"); while($success = mysql_fetch_row($goody)){ $ini = $success[0]; $dateon = $success[1]; $fromper = $success[2]; } if(strip_tags($_POST['Send'])){ $text=strip_tags(addslashes($text)); $to = strip_tags(addslashes($_POST['to'])); $rep = $_GET['rep']; if((!$to)){ ?> <p class="style4">Please enter a username!</p> <span class="style4"> <? }else{ if(!$text){?> </span> <p class="style4">You cannot send a blank message!</p> <span class="style4"> <? }else{ if($to == username){ ?> </span> <p class="style4">You cannot send a message to yourself!</p> <span class="style4"> <? }else{ $sql_username_check = mysql_query("SELECT username FROM users WHERE username='$to'"); $username_check = mysql_num_rows($sql_username_check); if ($username_check == 0){ ?> </span> <p class="style4">Invalid Username!</p> <span class="style4"> <? }else{ $date = gmdate('Y-m-d H:i:s'); $sql = mysql_query("INSERT INTO `inbox` (`id`, `to`, `from`, `message`, `date`, `read`, `subject`) VALUES ('', '$to', '$username', '$text', '$date', '0', '$subject');") or die (mysql_error()); $sqll = mysql_query("UPDATE users SET texts = texts-1 WHERE username='$username'"); if(!$sql){ ?> </span> <p class="style4">There has been an error please contact an Admin !</p> <span class="style1"> <? }else{ echo "<table width=300 border=1 align=center cellpadding=0 cellspacing=0 bordercolor=#003300 class=thinline2> <tr> <td height=20 align=center bgcolor=#74CE59 scope=col><span class=style1>Your Message As Been Sent </span></td> </tr> </table>"; }}}}}} ?> I have this php code to load a word document : sample.docx
//define a variable define('wdPropertyTitle', 1);
//instantiate the object OK
// check Class //check the object
echo "<pre>";
?> Question: When I run the script, I get the following exception: PHP Fatal error: Uncaught com_exception: <b>Source:</b> Microsoft Word<br/><b>Description:</b> This command is not available because no document is open. in C:\phpFolder\php_codes\class_COM.php:75 Stack trace: #0 {main} thrown in C:\phpFolder\php_codes\class_COM.php on line 75 Do you have any solution to get this thing done?, please PS: I have : win 10, php 7.4.1, IIS 10 , php_com_dotnet is active in php.ini, Dcom Configured in windows snap-in Appreciated Mohamad Aflatooni Code: [Select] switch($_GET['action']){ case 'write_ok': $error=false; $msg=''; if($_POST['dateofbirth']=='' || !preg_match( "/^(19|20)\d\d[-\\./](0[1-9]|1[012])[-\\./](0[1-9]|[12][0-9]|3[01])$/",$_POST['dateofbirth'])){ $error=true; $msg.='Date of birth is required and in the correct format 00/00/0000\n'; } the message at the end appears if the error is true. I wanted to know how to not show an errors message if the error is false. Any help on this? Code: [Select] <?php include 'header.php'; ?> <form name="form1" method="post" action="insert_ac.php"> <table id="formcss" width="100%" border="0" cellspacing="1" cellpadding="3" align="center"> <tr> <td colspan="3"><strong>Insert Data Into mySQL Database </strong></td> </tr> <tr> <td width="71">Name</td> <td width="6">:</td> <td width="301"><input name="name" type="text" id="name"></td> </tr> <tr> <td>Company</td> <td>:</td> <td><input name="company" type="text" id="company"></td> </tr> <tr> <td>Phone</td> <td>:</td> <td><input name="phone" type="text" id="phone"></td> </tr> <tr> <td>Mobile</td> <td>:</td> <td><input name="mobile" type="text" id="mobile"></td> </tr> <tr> <td>Email</td> <td>:</td> <td><input name="email" type="text" id="email"></td> </tr> <tr> <td>Called</td> <td>:</td> <td><input type="checkbox" name="call" value="training" /> Training <input type="checkbox" name="call" value="business" /> Business <input type="checkbox" name="call" value="legal" /> Legal <input type="checkbox" name="call" value="other" /> Other</td> </tr> </tr> <tr> <td>Patched To</td> <td>:</td> <td> <select name="patch"> <option value="sperkins">S.Perkins</option> <option value="srayson">S.Rayson</option> <option value="strandafil">S.Trandafil</option> <option value="tmoore">T.Moore</option> <option value="lharding">L.Harding</option> <option value="vmitchell">V.Mitchell</option> <option value="achilvers">A.Chilvers</option> <option value="aedwards">A.Edwards</option> <option value="rfrost">R.Frost</option> <option value="ohoogenhout">O.Hoogenhout</option> <option value="pkeily">P.Keily</option> </select> </td> </tr> <tr> <td>Filled out by</td> <td>:</td> <td><input name="user" type="text" id="user"></td> </tr> <tr> <td colspan="3" align="center"><input type="submit" name="Submit" value="Submit"></td> </tr> </table> </form> <?php include 'footer.php'; ?> Code: [Select] <?php $host="Localhost"; // Host name $username="root"; // Mysql username $password=""; // Mysql password $db_name="test"; // Database name $tbl_name="members"; // Table name // Connect to server and select database. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); // Get values from form $name=$_POST['name']; $company=$_POST['company']; $phone=$_POST['phone']; $mobile=$_POST['mobile']; $email=$_POST['email']; $call=$_POST['call']; $patch=$_POST['patch']; $user=$_POST['user']; // Insert data into mysql $sql="INSERT INTO $tbl_name(name, company, phone, mobile, email, call, patch, user)VALUES('$name', '$company', '$phone' '$mobile', '$email', '$call', '$patch', '$user')"; $result=mysql_query($sql); // if successfully insert data into database, displays message "Successful". if($result){ echo "Successful"; echo "<BR>"; echo "<a href='insert.php'>Back to main page</a>"; } else { echo "ERROR 1"; //This is where the error is. Not sure why it's not working } // close connection mysql_close(); ?> Can anyone see what i've done wrong here? I swear my brain is going to explode if i look over this one more time. Just a simple form trying to submit to the database i am making a private messaging system like hotmails where the message list appears on the left. Then when you click on one of them the box on the right loads the email. The problem is i dont really know how to go about it. Anyone have any pointers? Can anyone help me with this delete confirm box. I have tried but somehow its not working. Can anyone help me with this? Thankz. html codes : echo "<td><a href=delete.php?id=" . $rows['id'] ." onclick=\"return confirm(Are you sure?);\">Delete</a></td>"; delete.php : <?php include "config.php"; ?> <?php $id=$_GET['id']; ?> <script type="text/javascript"> <!-- function confirmation() { var answer = confirm('Are you sure you want to delete?') if (answer){ $sql="DELETE FROM document WHERE id='$id'"; } else{ alert("Cancelled the delete!") } } </script> Hi2all! I have one question: A have this page: http://proximabih.com/elitesecurity/test_mapa.html Its on my native lang, but what is important that at the bottom of page is generated google maps static image of dynamic map. Now - how to send, or how to integrate this image to php $body of ph contact form. My idea is to have two pages-first is above link, another is php contact form, so if we have php contact form, on first page maby i need to create SUBMIT button which will by code automaticly put url with poicture in contact form body. I really don have any idea, any help is very appriciate ) |