×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

PHP editing value doesn't fully shows the original value

PHP editing value doesn't fully shows the original value

PHP editing value doesn't fully shows the original value

(OP)
Hi everyone,
The following is a PHP code to edit a line in a MySQL table.
Lots of things do not work in this code. To start with is the following warning message I get when start running it:
"Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in C:\xampp\htdocs\magar\xxx.php on line 16".
Second is: I do not manage to delete the table when start running. Why is that ?! Evrey time I run it an additional line emerges!
Third: Clicking "Edit", the existing value of: "Name" shows up at the input editing box. Trouble is: instead of showing: "aaa aaa aaa"
only "aaa" shows up. The rest of the string, apart from the the segment which ends at first space, is not shown ! Why?!
I wish someone could help me with that complication!
Thanks in advance!

CODE

<?php 
	$errors = "";
	$name=''; 
	$db = mysqli_connect('localhost', 'root', 'root4qpines', 'magar');
	IF(!$db)
		DIE('' .MYSQLI_CONNECT_ERROR());
	
	mysqli_query($db, "DROP TABLE IF EXISTS 'xxx';");
	mysqli_query($db, "CREATE TABLE xxx(name VARCHAR(128))");
	mysqli_query($db, "INSERT INTO xxx(name) VALUES('aaa aaa aaa')");

	if (isset($_GET['edit_task']))
	{
		$name = $_GET['edit_task'];
		$edid=mysqli_query($db, "SELECT * FROM xxx WHERE name = $name");
		$row=mysqli_fetch_array($edid);
		$errors = $name;
		echo $errors;
	}
	$stations = mysqli_query($db, "SELECT * FROM xxx");
?>
<!DOCTYPE html>
<html>
<head>
	<link href="https://fonts.googleapis.com/css?family=Amatic+SC|Assistant|David+Libre|Heebo|Jua|Varela+Round" rel="stylesheet">
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
	<style>
	.add_btn
{
	/*height: 39px;*/
	background: #FFF8DC;
	color: #6B8E23;
	border: 2px solid #6B8E23;
	border-radius: 5px;
	/*padding: 5px 20px;*/
}
.btn_td
{
	/*border-left: 1px solid #cbcbcb;	*/
	border-bottom: 1px solid #FFFFFF;
}
	</style>
	
</head>
<body>
	<table>
		<thead>
			<tr>
				
				<th class="name_th" maxlength="50">Name</th>
				<th class="add_th"></th>
				<th class="edit_th"></th>
			</tr>
			<tr>
				<form method="POST" action="xxx.php">
					<td><input type="text" name="name" class="name_input" value=<?php echo htmlspecialchars($name);?>></td>
					<td class="btn_td"><button type="submit" class="add_btn" name="submit">Edit</button></td>
				</form>
			</tr>
			
		</thead>
		<tbody>
			<?php
				while ($row = mysqli_fetch_array($stations))
				{
					echo "<tr>";
					echo "<td class='name_td'>".$row['name']."</td>";
					
					echo "<td class='edit'>
							<a href='xxx.php?edit_task=".$row['name']."'>
								<img src='edit.gif' alt='Smiley face' height='20px' width='20px'>
							</a>
							<span class='tooltiptext'>Edit</span>
						</td>
						</tr>";
				}
			?>								
		</tbody>
	</table>
</body>
</html> 

RE: PHP editing value doesn't fully shows the original value

And 'line 16' would be??

Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.

Never mind this jesus character, stars had to die for me to live.

RE: PHP editing value doesn't fully shows the original value

Wrap strings in quotes and ticks, where appropriate.

CODE

$edid=mysqli_query($db, "SELECT * FROM `xxx` WHERE `name` = '$name'"); 

Why are you dropping and creating a table with each run of this script? Do this elsewhere, such as a MySQL interface like SQLyog, HeidiSQL, or MySQL Workbench. This will also present better error reporting while you debug.

And... did we post real usernames and passwords in a public forum? Change them on your system.

CODE

$db = mysqli_connect('localhost', 'root', '_________', '_____');
IF(!$db)
DIE('' .MYSQLI_CONNECT_ERROR());
mysqli_query($db, "DROP TABLE IF EXISTS 'xxx';");
mysqli_query($db, "CREATE TABLE xxx(name VARCHAR(128))");
mysqli_query($db, "INSERT INTO xxx(name) VALUES('aaa aaa aaa')"); 

RE: PHP editing value doesn't fully shows the original value

Going to take a wild guess and assume this is line 16:

CODE

$row=mysqli_fetch_array($edid); 

If so then that means that the previous line:

CODE

$edid=mysqli_query($db, "SELECT * FROM xxx WHERE name = $name"); 

Is not actually returning a result set. It's likely returning a false value. a.k.a a boolean. Which line 16 then attempts to use to retrieve results.

The first thing to do, is to actually find out what is happening with your query.

Try asking mysql for an error:

CODE

$edid=mysqli_query($db, "SELECT * FROM xxx WHERE name = $name") or die(mysql_error($db)); 

It's important to try to understand where the issues are coming from, and not just expect packaged answers and solutions.

Read and understand the error you are seeing first. If its saying the function expects a mysqli_result but boolean given its telling you the variable you are passing to it is not what its expecting. i.e its not a mysqli_result. It's telling you its a boolean, i.e true or false. Which means your $edid variable is true or false, and not a result. That means that the query is having an issue and not returning a result and instead true or false. Very likely false if something went wrong with the query.

You need to read what its telling you. Work out an issue at a time, and only when you know that part is actually working, move onto the next issue. sometimes solving one issue, will fix others further down if they are trying to use variables or data from the section further up that was having an issue.







----------------------------------
Phil AKA Vacunita
----------------------------------
OS-ception: Running Linux on a Virtual Machine in Windows which itself is running in a Virtual Machine on Mac OSx.

Web & Tech

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close