1.I have a MySql DB called 'scheduled' and table called 'messagelist'.
The first field msgID is int(10). Rest all are varchar(20).

2.broadcasttext.php
<form name="frmText" method="post" action="addScheduled.php">

3.addScheduled.php

<?php
$host="localhost"; // Host name
$username="scheduledUudk8"; // Mysql username
$password="KeszRXqXo.)-"; // Mysql password
$db_name="scheduled"; // Database name
$tbl_name="messagelist"; // Table name
$i = 0;

// 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");

$result = mysql_query("SELECT * FROM messagelist");

while($row = mysql_fetch_array($result))
{
    $i = $i + 1;
}
// Get values from form
$txtText=$_POST['txtText'];
$sqlDate=$_POST['sqlDate'];
$sqlTime=$_POST['sqlTime'];
$chkDir=$_POST['chkDir'];

if($chkDir == "All")
{
    $reach = "64,000";
}

// Insert data into mysql
$sql="INSERT INTO $tbl_name(msgID,msg,msgDate,msgTime,msgDir,msgReach)VALUES('$i', '$txtText', '$sqlDate',' $sqlTime', '$chkDir', '$reach')";
$result=mysql_query($sql);

// if successfully insert data into database, displays message "Successful".
if($result){
echo "Successful";
echo "<BR>";
echo "<a href='index.php#!scheduled'>Back to main page</a>";
}

else {
echo "ERROR";
}
?>

<?php
// close connection
mysql_close();
?>

4.Output Table

No. Message Message Date Message Time Message Group Message Reach

id0

Every field remains blank.. one column is updated and no error message is shown. Please help.
Thankyou :)

Recommended Answers

All 4 Replies

Can you show your form?

Also have tried var_dump($_POST); to see if the varible is being populated?

My form:

<!DOCTYPE html>
<html lang="en">
    <head>
        <link rel="stylesheet" type="text/css" href="../css/datepicker.css" /> 
        <script type="text/javascript" src="../js/datepicker.js"></script>
        <script type="text/javascript" src="../js/timepicker.js"></script>

        <meta charset="utf-8" />
        <script type="text/javascript">
            var result_style = document.getElementById('dis').style;

            function display() {
                document.frmText.ipHours.hidden = false;
                document.frmText.ipMins.hidden = false;
                document.frmText.ipYear.hidden = false;
                document.frmText.ipMonth.hidden = false;
                document.frmText.ipDate.hidden = false;
                result_style.display = 'table-row';
                document.frmText.cmdSubmit.value = "Schedule";
            }
            function hide() {
                document.frmText.ipHours.hidden = true;
                document.frmText.ipMins.hidden = true;
                document.frmText.ipYear.hidden = true;
                document.frmText.ipMonth.hidden = true;
                document.frmText.ipDate.hidden = true;
                result_style.display = 'none';
                document.frmText.cmdSubmit.value = "Send";
            }

            function validate() {
                var hour = document.frmText.ipHours.value;
                var mins = document.frmText.ipMins.value;
                var year = document.frmText.ipYear.value;
                var month = document.frmText.ipMonth.value;
                var date = document.frmText.ipDate.value;
                var flg = false;

                if (year > 2013 || year < 2012) {
                    alert("Invalid year");
                    document.frmText.ipYear.focus();
                    flg = true;
                }
                if (month > 12 || month < 01) {
                    alert("Invalid month");
                    document.frmText.ipMonth.focus();
                    flg = true;
                }
                if (date > 31 || date < 1) {
                    alert("Invalid date");
                    document.frmText.ipDate.focus();
                    flg = true;
                }
                if (hour > 23 || hour < 00) {
                    alert("Invalid hour");
                    document.frmText.ipHour.focus();
                    flg = true;
                }
                if (mins > 59 || mins < 00) {
                    alert("Invalid minutes");
                    document.frmText.ipMins.focus();
                    flg = true;
                }
                if (!document.frmText.chkDir[0].checked && !document.frmText.chkDir[1].checked && !document.frmText.chkDir[2].checked && !document.frmText.chkDir[3].checked && !document.frmText.chkDir[4].checked && !document.frmText.chkDir[5].checked && !document.frmText.chkDir[6].checked && !document.frmText.chkDir[7].checked) {
                    alert("Invalid message group");
                    flg = true;
                }

                if (document.frmText.txtText.value == "") {
                    alert("Enter message to send");
                    document.frmText.txtText.focus();
                    flg = true;
                }
                if (flg == false) {
                    document.frmText.sqlDate.value = year + '-' + month + '-' + date;
                    document.frmText.sqlTime.value = hour + ':' + mins + ':00';
                    alert(document.frmText.sqlDate.value);
                    alert(document.frmText.sqlTime.value);
                    document.frmText.cmdSubmit.disabled = true;
                    document.frmText.submit();
                }
            }
        </script>
    </head>
    <body>
        <h3>Broadcast Text | <a href="index.php#!broadcast_image">Broadcast Image</a></h3><br><br>
        <form name="frmText" method="post" action="index.php#!add_Schedule">
            <table>
                <tr>
                    <td><textarea rows="4" cols="50" name="txtText"></textarea></td>
                </tr>
                <tr>
                    <td colspan="50" style="text-align:left"><input type="button" name="cmdSubmit" value="Send" onclick="return validate();"/></td>
                </tr>
            </table>
            <br>
            <table>
                <tr>
                    <td><input type="radio" name="chkDir">North</input></td>
                    <td><input type="radio" name="chkDir">East</input></td>
                    <td><input type="radio" name="chkDir">West</input></td>
                    <td><input type="radio" name="chkDir">South</input></td>
                </tr>
                <tr>
                    <td><input type="radio" name="chkDir">Sales</input></td>
                    <td><input type="radio" name="chkDir">Operations</input></td>
                    <td><input type="radio" name="chkDir">Managers</input></td>
                    <td><input type="radio" name="chkDir">All</input></td>
                </tr>
            </table>
            <br>
            <table>
                <tr>
                    <td><input type="radio" name="chkSend" checked onclick="hide()">Now</input></td>
                    <td><input type="radio" name="chkSend" onclick="display()">Schedule</input></td>
                </tr>
            </table>
            <table>
                <tr style="display: none" id="dis">
                    <td rowspan="2">
                        <input type="number" name="ipHours" hidden="true" maxlength="2" min="00" max="23" size="2" onkeyup="if(this.value.length>=2)document.frmText.ipMins.focus()"/>
                            <label for="ipHours">&nbsp; :&nbsp;</label>
                        <input type="number" name="ipMins" hidden="true" maxlength="2" min="00" max="59" size="2" onkeyup="if(this.value.length>=2)document.frmText.ipYear.focus()"/>
                            <label  for="ipMins">&nbsp; IST</label>
                        <br><br>

                        <input type="number" name="ipYear" hidden="true" maxlength="4" min="2012" max="2013" size="4" onkeyup="if(this.value.length>=4)document.frmText.ipMonth.focus()"/>
                            <label for="ipYear">&nbsp; /&nbsp;</label>
                        <input type="number" name="ipMonth" hidden="true" maxlength="2" min="01" max="12" size="2" onkeyup="if(this.value.length>=2)document.frmText.ipDate.focus()"/>
                            <label  for="ipMonth">&nbsp;/&nbsp;</label>
                        <input type="number" name="ipDate" hidden="true" maxlength="2" min="01" max="31" size="2" onkeyup="if(this.value.length>=2)document.frmText.cmdSubmit.focus()"/>
                            <label  for="ipDate">&nbsp;(YYYY/MM/DD)</label>
                    </td>
                </tr>
            </table>
            <input type="text" hidden="hidden" name="sqlDate"/>
            <input type="text" hidden="hidden" name="sqlTime"/>
        </form>
    </body>
</html>

I would personally add hidden textboxes to retrieve the values...

In your broadcasttext.php form, before submit, add the hidden text boxes...

<input type="hidden" name="myhiddenvaluehere" value="<?=$_POST['myhiddenvaluehere'];?>"/>

Once you have that, it's quite easy to retrieve the value from another form -
In addScheduled.php -

$myhiddenvaluehere = $_POST['myhiddenvaluehere'];

Once you have all the values stored, you can run your INSERT statement succesfully

you cannot use $result twice. try making one $results and the other $result

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.