0

I want that mysql data will be in one row but it doesn't, in my case data echoes in a right down side :(

http://lashatt.comoj.com/php+mysql.php

[IMG]http://lashatt.comoj.com/mysqlproblem.JPG[/IMG]

<?php
$user="a7247794_a724779";
$password="";
$database="a7247794_testdb";
mysql_connect("mysql5.000webhost.com",$user,$password);
@mysql_select_db($database) or die( "Unable to select database");
if (isset($_POST['saxeli']))
echo "saxeli {$_POST['saxeli']}";
$a = $_POST['saxeli'];
$query = "INSERT INTO contacts1(saxeli) VALUES ('$a')";
mysql_query($query) or die("Query failed: " . mysql_error());
mysql_close();
?>
<?php
$user="a7247794_a724779";
$password="";
$database="a7247794_testdb";
mysql_connect("mysql5.000webhost.com",$user,$password);
@mysql_select_db($database) or die( "Unable to select database");
if (isset($_POST['saxeli1']))
echo "saxeli {$_POST['saxeli1']}";
$b = $_POST['saxeli1'];
$query = "INSERT INTO contacts1(saxeli1) VALUES ('$b')";
mysql_query($query) or die("Query failed: " . mysql_error());
mysql_close();
?>
<form method="post">
<input name="saxeli" type="text" />
<br>
<input name="saxeli1" type="text" />
<br>
<input type="submit" name="Submit" value="დაპოსტვა" >
</form>

<html><head><title>MySQL Table Viewer</title></head><body>
<?php
$db_host = 'mysql5.000webhost.com';
$db_user = 'a7247794_a724779';
$db_pwd = '';

$database = 'a7247794_testdb';
$table = 'contacts1';

if (!mysql_connect($db_host, $db_user, $db_pwd))
   die("Can't connect to database");

if (!mysql_select_db($database))
   die("Can't select database");

// sending query
$result = mysql_query("SELECT * FROM {$table}");
if (!$result) {
   die("Query to show fields from table failed");
}

$fields_num = mysql_num_fields($result);


echo "<table border='1'><tr>";
// printing table headers
for($i=0; $i<$fields_num; $i++)
{
   $field = mysql_fetch_field($result);
   echo "<td>{$field->name}</td>";
}
echo "</tr>\n";
// printing table rows
while($row = mysql_fetch_row($result))
{
   echo "<tr>";

   // $row is array... foreach( .. ) puts every element
   // of $row to $cell variable
   foreach($row as $cell)
       echo "<td>$cell</td>";

   echo "</tr>\n";
}
mysql_free_result($result);
?>
</body></html>

Edited by Nick Evan: Added tags, moved thread from C -&gt; PHP

4
Contributors
5
Replies
6
Views
6 Years
Discussion Span
Last Post by aixlu
0

I don't see a problem with the logic. It may be a data problem. If you only have one field in each record or if your fields contain 'return' / line skip characters than that might give you the result your are getting.

0

Query failed: Column count doesn't match value count at row 1

Is the message on the page from the link you posted.

Also your table tags may be weirdly placed. You have a certain number of columns in your table. You have an open table tag BUT no close table tag.

0

i want to create a simple vote poll with check box and PHP. And i want it to send me email as vote result without any help of MySQL. i'm just a beginner, so please someone help me..!! post a favourable reply v soon :)

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.