Page 1 of 1
the list box doesnt store a complete phrase in the MySQL DB
Posted: Sat Feb 02, 2008 7:04 pm
by josh27
Hello to everydoby, nice forum. Well i have a list box that get the values from a MySQL table....
<?php
$link=mysql_connect("localhost","USER","PASWORD");
mysql_select_db("DATABS",$link);
echo"<select name=teachers id=teachers>";
$sql="SELECT name FROM teachers";
$result=mysql_query($sql);
$i=0;
while ($row=mysql_fetch_array($result))
{
echo "<option value=".$row[$i].">".$row[$i]."</option>\n";
}
echo "</select>";
?>
ok, this show my the name and the last name of the teacher, like this, "jhon hutchison" but when press submit and see in the phpMyAdmin the table teacher in the name colum only appear the name "jhon" and dont store the last name "hutchison"... why?.
Re: the list box doesnt store a complete phrase in the MySQL DB
Posted: Sat Feb 02, 2008 7:22 pm
by bdlang
What type of column is `name`?
Re: the list box doesnt store a complete phrase in the MySQL DB
Posted: Sat Feb 02, 2008 8:45 pm
by califdon
josh27 wrote:Hello to everydoby, nice forum. Well i have a list box that get the values from a MySQL table....
<?php
$link=mysql_connect("localhost","USER","PASWORD");
mysql_select_db("DATABS",$link);
echo"<select name=teachers id=teachers>";
$sql="SELECT name FROM teachers";
$result=mysql_query($sql);
$i=0;
while ($row=mysql_fetch_array($result))
{
echo "<option value=".$row[$i].">".$row[$i]."</option>\n";
}
echo "</select>";
?>
ok, this show my the name and the last name of the teacher, like this, "jhon hutchison" but when press submit and see in the phpMyAdmin the table teacher in the name colum only appear the name "jhon" and dont store the last name "hutchison"... why?.
You initialize $i=0, but where do you increment it?? You could use a for loop or a foreach loop, but if you use a while loop, you have to increment $i or it will remain equal to zero.
As for your question, are sure that the field `name` really does have more than one word stored in it?
Re: the list box doesnt store a complete phrase in the MySQL DB
Posted: Sat Feb 02, 2008 9:06 pm
by josh27
yes im so sure that i have "jhon hutchison" and show me this complete name but when i press submit button it send only "jhon"... this is the complete page...
Code: Select all
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Agregar Profesonres Modulo</title>
</head>
<script type="text/javascript">
function checkmateria(form) {
Ctrl = form.materia;
if (Ctrl.value == "") {
validatePrompt(Ctrl, "ingresar materia");
return (false);
} else
return (true);
}
function checkprofesor(form) {
Ctrl = form.profesor;
if (Ctrl.value == "") {
validatePrompt(Ctrl, "ingresar docente");
return (false);
} else
return (true);
}
function checkano(form) {
Ctrl = form.ano;
if (Ctrl.value == "--") {
validatePrompt(Ctrl, "ingresar año");
return (false);
} else
return (true);
}
function checksecc(form) {
Ctrl = form.secc;
if (Ctrl.value == "") {
validatePrompt(Ctrl, "ingresar seccion");
return (false);
} else
return (true);
}
function checkForm(form) {
if (!checkmateria(form)) return;
if (!checkprofesor(form)) return;
if (!checkano(form)) return;
if (!checksecc(form)) return;
//alert ("All entries verified OK!\n(Assume this form is submitted!)");
//document.getElementById("loader").style.display='block';
document.form1.submit(); // un-comment to submit form
return;
}
function validatePrompt(Ctrl, PromptStr) {
alert (PromptStr);
Ctrl.focus();
return;
}
function loadDoc() {
// initial focus; use if needed
document.testform.realname.focus ();
return;
}
</script>
<style type="text/css">
#main {
border-width:1px;
border:solid;
border-color:#CCCCCC
}
.style3 {font-family: Arial, Helvetica, sans-serif; font-size: 12px; }
.style4 {
font-family: Arial, Helvetica, sans-serif;
font-size: 12px;
font-weight: bold;
color: #FFFFFF;
}
</style>
<body>
<form id="form1" name="form1" method="post" action="add_materias_process.php" enctype="multipart/form-data">
<table width="550" border="0" align="center" cellpadding="0" cellspacing="1" id="main">
<tr>
<td align="center" bgcolor="#006699" class="style4">Agregar Materias </td>
</tr>
<tr>
<td>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="3%" height="21"></td>
<td width="20%" bgcolor="#E0E0E0" class="style3">Materia</td>
<td width="2%" bgcolor="#E0E0E0">:</td>
<td bgcolor="#E0E0E0">
<input name="materia" type="text" id="materia" style="border:solid; border-width:1px; font-size:12px;" size="35"/> </td>
</tr>
<tr>
<td> </td>
<td class="style3"><span class="style3">Docente</span></td>
<td>:</td>
<td><?php
$link=mysql_connect("localhost","user","pass");
mysql_select_db("database",$link);
echo"<select name=profesor id=profesor>";
$sql="SELECT nombre FROM profesores";
$result=mysql_query($sql);
$i=0;
while ($row=mysql_fetch_array($result))
{
echo "<option value=".$row[$i].">".$row[$i]."</option>\n";
// [b]IT SHOW ME THE COMPLETE NAME, JHON HUTCHISON.[/b]
}
echo "</select>";
?></td>
</tr>
<tr>
<td> </td>
<td bgcolor="#E0E0E0" class="style3">Año</td>
<td bgcolor="#E0E0E0">:</td>
<td bgcolor="#E0E0E0"><select name="ano" size="1" id="ano">
<option value="--" selected="selected">--</option>
<option value="primero">primero</option>
<option value="segundo">segundo</option>
<option value="tercero">tercero</option>
<option value="cuarto">cuarto</option>
<option value="quinto">quinto</option>
<option value="sexto">sexto</option>
</select></td>
</tr>
<tr>
<td bgcolor="#FFFFFF"> </td>
<td bgcolor="#FFFFFF" class="style3">Secc.</td>
<td bgcolor="#FFFFFF">:</td>
<td bgcolor="#FFFFFF"><select name="secc" size="1" id="secc">
<option value="--" selected="selected">--</option>
<option value="unica">unica</option>
<option value="A">A</option>
<option value="B">B</option>
<option value="C">C</option>
</select></td>
</tr>
<tr>
<td> </td>
<td bgcolor="#E0E0E0" class="style3"> </td>
<td bgcolor="#E0E0E0"> </td>
<td bgcolor="#E0E0E0">
<label>
<input name="Button" type="button" id="Submit" value="Ingresar" onclick="checkForm(this.form)" />
</label> </td>
</tr>
</table></td>
</tr>
<tr>
<td> </td>
</tr>
</table>
</form>
</body>
</html>
Re: the list box doesnt store a complete phrase in the MySQL DB
Posted: Sat Feb 02, 2008 9:48 pm
by bdlang
PLEASE limit your code to
only the relevant PHP or SQL. In addition, be sure to use the PHP code taqs when posting to make it easier to read.
You still haven't shown us how your `name` or `nombre` column is defined.
I completely agree with
CalifDon, you never increment the
$i variable (which doesn't really need a place in the while() loop anyway, as you can simply use the associative index).
josh27 wrote:yes im so sure that i have "jhon hutchison" and show me this complete name but when i press submit button it send only "jhon"... this is the complete page...
Ok, so when you hit "submit", the value sent is truncated, but what does the HTML source from this PHP output show?
Re: the list box doesnt store a complete phrase in the MySQL DB
Posted: Sat Feb 02, 2008 10:05 pm
by califdon
Oh! So the full name shows correctly in the HTML form, but when you submit the form to another script, it only stores the first name in the database?? I did not understand that from your first description. If that is the case, you must show us the script that stores the data in the database, not what you have shown us so far. That would be "add_materias_process.php". That is what stores the data in the table. If you post that code, perhaps we can show you what is wrong. If you do, please follow the request of bdlang about using the Code tags to make it more readable, and just show us the part where it receives the data in the $_POST variables and the SQL INSERT statement that stores it in the table.
Re: the list box doesnt store a complete phrase in the MySQL DB
Posted: Sat Feb 02, 2008 11:17 pm
by John Cartwright
Code: Select all
echo "<option value=".$row[$i].">".$row[$i]."</option>\n";
should be
Code: Select all
echo '<option value="'.$row[$i].'">'.$row[$i].'</option>\n";
considering if any of the values had a space it would be truncated until the space
Re: the list box doesnt store a complete phrase in the MySQL DB
Posted: Sun Feb 03, 2008 7:32 am
by josh27
hey i use...
Code: Select all
echo '<option value="'.$row[$i].'">'.$row[$i].'</option>\n';
and now send the complete phrase to the "add_materias_process.php" and store in the data base complete name.
"Jhon Hutchison"...
thanks so much!!!
