Hi All, help me please!.
How to create Query for my project problem.

Mysql table:

CREATE TABLE `outbox` (
`id` INT( 11 ) NOT NULL ,
`phone_number` VARCHAR( 20 ) NOT NULL ,
`text` VARCHAR( 160 ) NOT NULL ,
PRIMARY KEY ( `id` )
) ENGINE = MYISAM ;


CREATE TABLE `contacts` (
  `id` int(11) NOT NULL auto_increment,
  `name` varchar(25) NOT NULL,
  `phone` varchar(20) NOT NULL,
  `group_name` varchar(20) NOT NULL,
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=7 ;

INSERT INTO `contacts` VALUES (1, 'jala', '+60111', 'friends');
INSERT INTO `contacts` VALUES (2, 'jali', '+60222', 'friends');
INSERT INTO `contacts` VALUES (3, 'jalu', '+60333', 'friends');
INSERT INTO `contacts` VALUES (4, 'kada', '+60444', 'members');
INSERT INTO `contacts` VALUES (5, 'kadi', '+60555', 'members');
INSERT INTO `contacts` VALUES (6, 'kadu', '+60666', 'members');

Form:

<html>
<body>
<h1>Form Send SMS Message</h1>

<form method="post" action="insert.php">
<table>
  <tr><td>Send To</td><td>:</td><td>
       <select name="group">
       <option selected>Select Phone Group</option>
         <option value="members">Members Group</option>
         <option value="friends">Friends Group</option>
       </select>
       </td><tr>   
  </tr>
  <tr><td>Message</td><td>:</td><td><textarea name="message" rows="10" cols="20"></textarea></td></tr>  
</table>
<input type="submit" name="submit" value="submit">
</form>
</body>
</html>

proses Form:

<?php
include ("koneksi.php");
$con = mysql_connect($servername,$username ,$password);
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("smsd");

        $group=$_POST['group'];
        $message=$_POST['message'];

    $qr_contacts = "SELECT phone FROM contacts WHERE group_name = $group";
    $rs_contacts = mysql_query($qr_contacts);
    while($data = mysql_fetch_array($rs_contacts))
        {
        $id= $data['id'];
        $phone= $data['phone'];

        // I Want insert to outbox tabel (phone_number, text) VALUES ('$phone','$message')
        // How to Create Query? 
        // Thank you.
        }

?>

Recommended Answers

All 4 Replies

Member Avatar for LastMitch

@gacoekchip.pokher

Just this:

$query = mysql_query ("INSERT INTO outbox (phone_number, text) VALUES ('$phone','$message')") or die (mysql_error());

Can you also Click Solved from the previous thread if the answer I provided solved your question.

@LastMitch:

if $group =="friends";
$phone = '+60111', '+60222', '+60333';

How to insert to outbox table for one click?.

EDIT:

$qr_contacts = "SELECT phone FROM contacts WHERE group_name = '$group'";
Member Avatar for LastMitch

@gacoekchip.pokher

I'm not gonna write out the whole code! I'm just gonna should you how to begin it.

This is the first few lines:

if ($_POST['$group'] == "friends"){
    $phone = $_POST['post'];
    $tquery = "SELECT phone FROM contacts WHERE group_name = '$group'";
    //Start here to finish the code
    }

If you have any more question just post it here.

Can you also Click Solved from the previous thread if the answer I provided solved your question. The reason why so other members need to find that answer, they can look at your thread. On your bottom left corner there's button called "Mark Question Solved".

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.