Board index   FAQ   Search  
Register  Login
Board index php forum :: Database mySQL & php coding

Query Problem

Codes here !

Moderators: macek, egami, gesf

Query Problem

Postby gacoksa » Thu Aug 16, 2012 1:18 pm

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

Mysql table:
Code: Select all
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:
Code: Select all
<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:
insert.php
Code: Select all
<?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.
        }
?>
gacoksa
New php-forum User
New php-forum User
 
Posts: 2
Joined: Thu Aug 16, 2012 12:14 pm

Re: Query Problem

Postby freshnet » Mon Aug 20, 2012 4:06 am

If you want help, you'll probably need to provide some details on what the problem is, and what you're looking to do.
User avatar
freshnet
php-forum Active User
php-forum Active User
 
Posts: 278
Joined: Tue Feb 22, 2011 8:19 am
Location: Canada


Return to mySQL & php coding

Who is online

Users browsing this forum: Google [Bot] and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.