Jump to content

Recommended Posts

Hi Guys

 

I was wondering if you could help me with a problem I am having.I`m trying to create a PHP file that enters information into 3 separate fields into a table row  when the user enters information into a HTML form.

 

at the moment I have created this

 

 

  <html>
<head>
<title>update database</title>
</head>
<body>
<form method="post" action="update.php">

Please state the category of problem that has occurred<br/>
<input type="text" name="category" size="70"/></br>

Please give a desription of the problem</br>
<input type="text" name="problem" size="70"/></br>

Please give a solution to the problem<br/>
<input type="text" name="solution" size="70"/></br>

<input type="submit" value="Submit the problem and solution"/>
</form>
</body>
</html>

<?php
$category = $_POST['category'];

mysql_connect ("localhost", "root","password")  or die (mysql_error());
mysql_select_db ("heskdb");

$query="insert into hesk_std_replies (category) values ('$category')";
mysql_query($query) or die ('error updating database');
echo"database updated with:".$category;



$solution = $_POST['solution'];
mysql_connect ("localhost", "root","password")  or die (mysql_error());
mysql_select_db ("heskdb");

$query="insert into hesk_std_replies (solution) values ('$solution')";
mysql_query($query) or die ('error updating database');

echo"database updated with:".$solution;


$problem = $_POST['problem'];
mysql_connect ("localhost", "root","password")  or die (mysql_error());
mysql_select_db ("heskdb");

$query="insert into hesk_std_replies (problem) values ('$problem')";
mysql_query($query) or die ('error updating database');

echo"database updated with:".$problem;
?>

 

 

The problem with this is thatit enters the inormation into 3 incremental rows where I want it to be entered into the same row.

 

I have created this file which I thaught would work but it is giving me errors.

 

 

 

gdds

<?php
$category = $_POST['category'];
$problem = $_POST['problem'];
$solution = $_POST['solution'];

mysql_connect ("localhost", "root","password")  or die (mysql_error());
mysql_select_db ("heskdb");
                    
$query="insert into hesk_std_replies(category,problem,solution)  values ('.$category.''.$problem.''.$solution.')";
mysql_query($query) or die ('error updating database');
echo"database updated with:".$category ,$problem,$solution;


?>

Any help would be much appreciated

Your second solution is almost good. You've left concatenation operators in your query (also know as 'dots'):

 

$query="insert into hesk_std_replies(category,problem,solution)  values ('.$category.''.$problem.''.$solution.')";

 

it should be

 

$query="insert into hesk_std_replies(category,problem,solution)  values ('$category','$problem','$solution')";

The last echo statement will fail as well

 

<?php

$category = mysql_real_escape_string($_POST['category']);
$problem  = mysql_real_escape_string($_POST['problem']);
$solution = mysql_real_escape_string($_POST['solution']);

mysql_connect ("localhost", "root","password")  or die (mysql_error());
mysql_select_db ("heskdb");
                    
$query="INSERT INTO `hesk_std_replies` (`category`, `problem`, `solution`)
          values ('{$category}', '{$problem}', '{$solution}')";

mysql_query($query) or die ('error updating database');

echo "Database updated with: {$category}, {$problem}, {$solution}";

?>

Your second solution is almost good. You've left concatenation operators in your query (also know as 'dots'):

 

$query="insert into hesk_std_replies(category,problem,solution)  values ('.$category.''.$problem.''.$solution.')";

 

it should be

 

$query="insert into hesk_std_replies(category,problem,solution)  values ('$category','$problem','$solution')";

 

Thanks for the reply but I am still having the same error IE error updating database

It would look ugly, but there's no reason why it would fail.

 

You're right. I've never seen any documentation that the comma works concatenate text the same as a period. Although it only seems to work within an echo and not for an assignment.

Use

die(mysql_error()." $query")

to display something meaningful

Thanks ,the error is

 

Column count doesn't match value count at row 1 insert into hesk_std_replies(category,problem,solution) values ('hardware''Broken Mouse''Connection')

 

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.