开发者

error using mysql escape string

开发者 https://www.devze.com 2022-12-21 16:18 出处:网络
What\'s wrong with my code, Im just a beginner. The error said it was an undefined index. A record is added to mysql but its just 0\'s. What\' s the proper way of doing this

What's wrong with my code, Im just a beginner. The error said it was an undefined index. A record is added to mysql but its just 0's. What' s the proper way of doing this

$con = mysql_connect("localhost","root","");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("Hospital", $con);


$hospnum = mysql_real_escape_string($_POST['HOSPNUM']);
$rnum =  mysql_real_escape_string($_POST['ROOMNUM']);
$adate = mysql_real_escape_string($_POST['ADATE']);

$adtime = mysql_real_escape_string($_POST['ADTIME']);
$lname = mysql_real_escape_string($_POST['LASTNAME']);
$fname = mysql_real_escape_string($_POST['FIRSTNAME']);
$mname = mysql_real_escape_string($_POST['MIDNAME']);

$cs = mysql_real_escape_string($_POST['CSTAT']);
$age = mysql_real_escape_string($_POST['AGE']);
$ad = mysql_real_escape_string($_POST['ADDRESS']);
$bday = mysql_real_escape_string($_POST['BDAY']);

$telnum = mysql_real_escape_string($_POST['TELNUM']);
$sex = mysql_real_escape_string($_POST['SEX']);
$stats1 = mysql_real_escape_string($_POST['STAT']);
$stats2 = mysql_real_escape_string($_POST['STAT2']);
$stats3 = mysql_real_escape_string($_POST['STAT3']);
$stats4 = mysql_real_escape_string($_POST['STAT4']);
$stats5 = mysql_real_escape_string($_POST['STAT5']);
$stats6 = mysql_real_escape_string($_POST['STAT6']);
$stats7 = mysql_real_escape_string($_POST['STAT7']);
$stats8 = mysql_real_escape_string($_POST['STAT8']);
$nurse = mysql_real_escape_string($_POST['NURSE']);




      $sqlque="INSERT INTO t2 (HOSPNUM, ROOMNUM, ADATE, ADTIME, LASTNAME, FIRSTNAME, MIDNAME, CSTAT, AGE, BDAY, ADDRESS, TELNUM, SEX, STAT, STAT2, STAT3, STAT4, STAT5, STAT6, STAT7, STAT8, NURSE)
      VALUES ('$hospnum', '$rnum' , '$adate' , '$adtime', '$lname',  '$fname', '$mname', '$cs', '$age', '$bday', '$ad', '$telnum', '$sex','$stats1', '$stats2', '$stats3', '$stats4', '$stats5', '$stats6', '$stats7', '$stats8', '$nurse')"; 




if (!mysql_query($sqlque,$con))
  {
  die('Error: ' . mysql_error());
  }
echo "<script>alert('Record successfully added in Table In-patient!')</script>";


mysql_close($con)


?>

Here's the html form:

<html>
<head>
<script language="javascript" src="cal2.js">
/*
Xin's Popup calendar script-  Xin Yang (http://www.yxscripts.com/)
Script featured on/available at http://www.dynamicdrive.com/
This notice must stay intact for use
*/
</script>
<script language="javascript" src="cal_conf2.js"></script>
</head>
<body onLoad="show_clock()">
<style>
input { font-size: 16px;}
</style>
<?php include('header.php'); ?>
<div id="main_content">

</div>
<?php include('footer.php'); ?>
</head>
<table width="900" border="0" align="left" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<form name="form1" method="post" action="aisaction.php">
<td>
<table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
<tr>
<td colspan="16" style="background:#9ACD32; color:white; border:white 1px solid; text-align: center"><strong><fo开发者_开发百科nt size="3">Add In-Patient</strong></td>
</tr>
<tr>

<td width="54"><font size="3">Hospital #</td>
<td width="3">:</td>
<td width="168"><input name="hnum" type="text" id="hospnum" maxlength="4"></td>

<td width="41"><font size="3">Room #</td>
<td width="3">:</td>
<td width="168"><input name="rnum" type="text" id="rnum" maxlength="4"></td>

<td width="67"><font size="3">Date</td>
<td width="3">:</td>
<td width="168"><input name="adate" type="text" id="adate" maxlength="15">







<td width="67"><font size="3">Time</td>
<td width="3">:</td>
<td width="168"><input name="adtime" type="text" id="adtime" maxlength="15">

</td>




</tr>
<tr>
<td><font size="3">Last Name</td>
<td>:</td>
<td><input name="lname" type="text" id="lname" maxlength="15"></td>
<td><font size="3">First Name</td>
<td>:</td>
<td><input name="fname" type="text" id="fname" maxlength="15"></td>
<td><font size="3">Middle Name</td>
<td>:</td>
<td><input name="mname" type="text" id="mname" maxlength="15"></td>
</tr>


<tr>
<td><font size="3">Civil Status</td>
<td>:</td>
<td>
    <select name="cs" id="cs">
        <option>Single</option>
        <option>Married</option>
        <option>Widowed</option>

    </select></td></td>
<td><font size="3">Age</td>
<td>:</td>
<td><input name="age" type="text" id="age" maxlength="3"></td>
<td><font size="3">Birthday</td>
<td>:</td>
<td><input name="bday" type="text" id="bday" maxlength="12">

</td>

</tr>

<tr>
<td><font size="3">Address</td>
<td>:</td>
<td><input name="ad" type="text" id="ad" maxlength="25"></td>
<td><font size="3">Telephone #</td>
<td>:</td>
<td><input name="telnum" type="text" id="telnum" maxlength="11"></td>

<td width="23"><font size="3">Sex</td>
<td width="3">:</td>
<td width="174"><input name="sex" type="text" id="sex" maxlength="1"></td>
</tr>

<tr>
<td><font size="3">Pls. Check</td>
<td>:</td>

<input type='hidden' name="stats1" value="0">
<td><input name="stats1" type="checkbox" id="SSS" value="SSS">SSS</td>
<td><font size="3"></td>
<td>:</td>
<input type='hidden' name="stats2" value="0">
<td><input name="stats2" type="checkbox" id="nonmed" value="NonMedicare">Non Medicare</td>

<td><font size="3"></td>
<td>:</td>
<input type='hidden' name="stats3" value="0">
<td><input name="stats3" type="checkbox" id="sh" value="stockholder">Stockholder</td>
</tr>


<tr>
<td><font size="3"></td>
<td></td>
<input type='hidden' name="stats4" value="0">
<td><input name="stats4" type="checkbox" id="gsis" value="GSIS">GSIS</td>
<td><font size="3"></td>
<td></td>
<input type='hidden' name="stats5" value="0">
<td><input name="stats5" type="checkbox" id="senior" value="seniorcitizen">Senior-Citizen</td>


<tr>
<td><font size="3"></td>
<td></td>
<input type='hidden' name="stats6" value="0">
<td><input name="stats6" type="checkbox" id="dep" value="dependent">Dependent</td>
<td><font size="3"></td>
<td></td>
<input type='hidden' name="stats7" value="0">
<td><input name="stats7" type="checkbox" id="emp" value="employee">Employee</td>
<td><font size="3"></td>
<td></td>
<input type='hidden' name="stats8" value="0">
<td><input name="stats8" type="text" id="" value="" maxlength="15">Others</td>

</tr>

<tr>
<td><font size="3">Admitting/Attending Nurse</td>
<td>:</td>
<td><input name="nurse" type="text" id="nurse" maxlength="15"></td>

</tr>






<tr>

<td>&nbsp;</td>
<td>&nbsp;</td>
<td><input type="submit" name="Submit" value="Add"> <input type="reset" name="Reset" value="Reset"></td></td>

</form>



</tr>
</table>
</td>
</form>
</tr>
</table>
<table>
<tr><td>

</tr>
</table>


</html>

Here's the error:

Notice: Undefined index: HOSPNUM in C:\wamp\www\backup\kamikorosutengenmyo510\aisaction.php on line 15

Notice: Undefined index: ROOMNUM in C:\wamp\www\backup\kamikorosutengenmyo510\aisaction.php on line 16

Notice: Undefined index: ADATE in C:\wamp\www\backup\kamikorosutengenmyo510\aisaction.php on line 17

Notice: Undefined index: ADTIME in C:\wamp\www\backup\kamikorosutengenmyo510\aisaction.php on line 19


I would say, that form names and then $_POST variables have to have same case - they are case sensitive.

And you are having lowercase names in form and checking uppercase variables in $_POST

As c0mrade pointed out, do

var_dump($_POST);

and it will tell you what variables are really going to your script.

0

精彩评论

暂无评论...
验证码 换一张
取 消