/    Sign up×
Community /Pin to ProfileBookmark

PHP script problem.

I’m not sure where the error in these scripts are. Edit.php seems to work fine.
The problem comes in at edit_form.php witch uses edit_data.php .

There is 1 table field i dont have listed and it stores IP addresses.

So can someone point out the error for me please.

edit.php

[code=php]
<html>
<body>
<table>
<tr>
<td align=”center”>EDIT DATA</td>
</tr>
<tr>
<td>
<table border=”1″>
<?
mysql_connect(“localhost”, “*****”, “******”) or die(mysql_error());
mysql_select_db(“*****”) or die(mysql_error());

$order = “SELECT id, eventname, host, time, date FROM event”;
$result = mysql_query($order);
echo (“<tr> <th>Event Name</th> <th>Host</th> <th>Time</th> <th>Date</th> <th>Edit</th></tr>”);
while ($row=mysql_fetch_array($result)){
echo (“<tr><td>$row[eventname]</td>”);
echo (“<td>$row[host]</td>”);
echo (“<td>$row[time]</td>”);
echo (“<td>$row[date]</td>”);
echo (“<td><a href=”edit_form.php?id=$row[id]”>Edit</a></td></tr>”);
}
?>
</table>
</td>
</tr>
</table>
</body>
</html>
[/code]

edit_form.php

[code=php]
<html>
<head>
<title>Form Edit Data</title>
</head>

<body>
<table border=1>
<tr>
<td align=center>Form Edit Employees Data</td>
</tr>
<tr>
<td>
<table>
<?
mysql_connect(“localhost”, “******”, “******”) or die(mysql_error());
mysql_select_db(“******”) or die(mysql_error());

$order = “SELECT id, eventname, host, time, date FROM event
where id=’$id'”;
$result = mysql_query($order);
$row = mysql_fetch_array($result);
?>
<form method=”post” action=”edit_data.php”>
<input type=”hidden” name=”id” value=”<? echo “$row[id]”?>”>
<tr>
<td>Event Name</td>
<td>
<input type=”text” name=”eventname”
size=”24″ value=”<? echo “$row[eventname]”?>”>
</td>
</tr>
<tr>
<td>Host</td>
<td>
<input type=”text” name=”host” size=”24″
value=”<? echo “$row[host]”?>”>
</td>
</tr>
<tr>
<td>Time</td>
<td>
<input type=”text” name=”time” size=”24″
value=”<? echo “$row[time]”?>”>
</td>
</tr>
<tr>
<td>Date</td>
<td>
<input type=”text” name=”date” size=”24″
value=”<? echo “$row[date]”?>”>
</td>
</tr>
<tr>
<td align=”right”>
<input type=”submit”
name=”submit value” value=”Edit”>
</td>
</tr>
</form>
</table>
</td>
</tr>
</table>
</body>
</html>
[/code]

Edit_data.php

[code=php]
<?
mysql_connect(“localhost”, “*****”, “******”) or die(mysql_error());
mysql_select_db(“******”) or die(mysql_error());
$order = “UPDATE event
SET eventname=’$eventname’,
host=’$host’,
time=’$time’,
date=’$date’
WHERE
id=’$id'”;
mysql_query($order);
header(“location:edit.php”);
?>[/code]

to post a comment
PHP

20 Comments(s)

Copy linkTweet thisAlerts:
@ibechaneAug 22.2008 — I noticed in your <?php echo "...." ?> pieces, you don't have a semicolon after the echo statement, i.e. <?php echo "...."[b];[/b]?>. Maybe that's it?
Copy linkTweet thisAlerts:
@CA-TaylorauthorAug 22.2008 — I added semicolans to the echos on edit_form.php The script still isnt functioning corectly
Copy linkTweet thisAlerts:
@Phill_PaffordAug 22.2008 — whats the error you get? also when you view the generate source, does it display correctly?
Copy linkTweet thisAlerts:
@CA-TaylorauthorAug 22.2008 — There is no error, thats why it confuses me. Its just not editing the row at all. My Delete also is not working correctly. I cant figure out my problem because its not giving me a error message.


Location: Here
Copy linkTweet thisAlerts:
@Phill_PaffordAug 22.2008 — I do notice one thing that might be the cause, in all of your array calls you call them like this

[code=php]
$row[eventname]
[/code]


try this

[code=php]
$row['eventname']
[/code]


I think you can only use the array variable without the quotes for numeric values like 0-9, not string values. they need to be in quotes.

[code=php]
$row[1]

// or

$row[$i]
[/code]
Copy linkTweet thisAlerts:
@CA-TaylorauthorAug 22.2008 — I tryed changing them like you said and it only gave me actual errors.
Copy linkTweet thisAlerts:
@Phill_PaffordAug 22.2008 — what errors?
Copy linkTweet thisAlerts:
@CA-TaylorauthorAug 22.2008 — Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING

Was the error I received.
Copy linkTweet thisAlerts:
@Phill_PaffordAug 22.2008 — Does it tell you what script the error is in? Line number?

Could you repost your code for review?
Copy linkTweet thisAlerts:
@CA-TaylorauthorAug 22.2008 — This is the edits you told me to make.

Edit.php (Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/coders/public_html/phptesting/edit.php on line 22)
[code=php]
<html>
<body>
<table>
<tr>
<td align="center">EDIT DATA</td>
</tr>
<tr>
<td>
<table border="1">
<?
mysql_connect("localhost", "coders_phptest", "051092") or die(mysql_error());
mysql_select_db("coders_phptest") or die(mysql_error());

$order = "SELECT id, eventname, host, time, date FROM event";
$result = mysql_query($order);
echo ("<tr> <th>Event Name</th> <th>Host</th> <th>Time</th> <th>Date</th> <th>Edit</th> <th>Delete</th></tr>");
while ($row=mysql_fetch_array($result)){
echo ("<tr><td>$row['eventname']</td>");
echo ("<td>$row['host']</td>");
echo ("<td>$row['time']</td>");
echo ("<td>$row['date']</td>");
echo ("<td><a href="edit_form.php?id=$row[id]">Edit</a></td>");
echo ("<td><a href="delete.php?id=$row[id]">Delete</a></td></tr>");
}
?>
</table>
</td>
</tr>
</table>
</body>
</html>
[/code]


edit_form.php (Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/coders/public_html/phptesting/edit_form.php on line 26)
[code=php]
<body>
<table border=1>
<tr>
<td align=center>Form Edit Employees Data</td>
</tr>
<tr>
<td>
<table>
<?
mysql_connect("localhost", "coders_phptest", "051092") or die(mysql_error());
mysql_select_db("coders_phptest") or die(mysql_error());

$order = "SELECT id, eventname, host, time, date FROM event
where id='$id'";
$result = mysql_query($order);
$row = mysql_fetch_array($result);
?>
<form method="post" action="edit_data.php">
<input type="hidden" name="id" value="<? echo "$row['id']"; ?>">
<tr>

<td>Event Name</td>
<td>
<input type="text" name="eventname"
size="24" value="<? echo "$row['eventname']"; ?>">
</td>
</tr>
<tr>
<td>Host</td>
<td>
<input type="text" name="host" size="24"
value="<? echo "$row['host']"; ?>">
</td>
</tr>
<tr>
<td>Time</td>
<td>
<input type="text" name="time" size="24"
value="<? echo "$row['time']"; ?>">
</td>
</tr>

<tr>
<td>Date</td>
<td>
<input type="text" name="date" size="24"
value="<? echo "$row['date']"; ?>">
</td>
</tr>
<tr>
<td align="right">
<input type="submit"
name="submit value" value="Edit">
</td>
</tr>
</form>
</table>
</td>
</tr>
</table>
</body>
</html>
[/code]


edit_data.php
[code=php]<?
mysql_connect("localhost", "coders_phptest", "051092") or die(mysql_error());
mysql_select_db("coders_phptest") or die(mysql_error());
$order = "UPDATE event
SET eventname='$eventname',
host='$host',
time='$time',
date='$date'
WHERE
id='$id'";
mysql_query($order);
header("location:edit.php");
?>
[/code]



My delete is also malfunctioning. It doesnt delete at all

delete.php
[code=php]<?

mysql_connect("localhost", "coders_phptest", "051092") or die(mysql_error());
mysql_select_db("coders_phptest") or die(mysql_error());

$order = "DELETE FROM event
WHERE id='$id'";
mysql_query($order);
header("location:edit.php");
?>
[/code]
Copy linkTweet thisAlerts:
@Declan1991Aug 22.2008 — You have two extra brackets, maybe that's it. mysql_connect("localhost", "coders_phptest", "051092") or die(mysql_error()[b][color=red])[/color][/b];
mysql_select_db("coders_phptest") or die(mysql_error()[B][COLOR="Red"])[/COLOR][/B];


Just one other point, echo shouldn't have brackets, it's not really a function. You are better off to use[code=php]
echo "string";
[/code]
than[code=php]echo("string");[/code]
Copy linkTweet thisAlerts:
@ibechaneAug 22.2008 — I don't want to sound pedantic, but please proofread your code carefully when you make changes.

<i>
</i> echo ("&lt;td&gt;&lt;a href="edit_form.php?id=$row[id]"&gt;Edit&lt;/a&gt;&lt;/td&gt;");
echo ("&lt;td&gt;&lt;a href="delete.php?id=$row[id]"&gt;Delete&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;");


You didn't add the apostrophes to the $row variables. Not surprisingly, this occurred on line 22.


Are you posting the entirety of the edit_form.php? Line numbers don't help if we're not counting from the beginning of the file.

Another thing - I'm assuming that you have other code somewhere because you never actually define $id, and you use it a few times in your code. Could that be a problem?

One last thing -- if you accidentally forgot to star out your login information, I suggest you change it.
Copy linkTweet thisAlerts:
@CA-TaylorauthorAug 22.2008 — Thats my whole code. and I added the thing to the cut out you posted.

the errors started when i added the ' ' into my code other then that the script didnt function. and on edit.php id is a variable for my db table field
Copy linkTweet thisAlerts:
@ibechaneAug 22.2008 — What I meant was where is $id defined? I don't see a place where you put:

[code=php]
$id = /*something*/;
[/code]


Is it part of a url query string (e.g. edit_form.php?id=MY_ID), because if so, you need to use $_GET["id"] instead of $id.
Copy linkTweet thisAlerts:
@CA-TaylorauthorAug 22.2008 — do i still need the ['whatever'] cause thats what screwed it up and gave it errors.

as for the get command i'm not sure how to use it.
Copy linkTweet thisAlerts:
@ibechaneAug 22.2008 — How does the script determine which id to use? That's what I don't understand.

If what you posted is really all there is to your code, $id is not defined anywhere, yet you use it in your query. You are asking mySQL "find me a data entry with an id equal to $id" except $id isn't defined anywhere. Where does the value for $id come from?
Copy linkTweet thisAlerts:
@CA-TaylorauthorAug 22.2008 — Well ID was selected from the DB on edit.php I figure it would work fine but i still dotn think undoing the edits that gave me the errors and identifying id will help a whole lot but i will try it
Copy linkTweet thisAlerts:
@ibechaneAug 22.2008 — There seems to be a communication problem.

Let me explain in an anecdote so it's clear.

Say you are a doctor and I am your secretary. I am in charge of handing you patient records, which you have stored in a cabinet. The patient records have information like name, address, phone number, etc.

If you want to get the full information on a person, you give me his/her name, and I search the cabinet for that name and give you his/her full record.

For example, you say "Hey, ibechane, please give me the record of the patient named 'Bob'." Then I search through and find the record and give it to you.

Simple, right? This is essentially what you are asking mySQL to do. However, in order for me, the secretary, to actually find a record, you have to give me a name to find.

If you go up to me and say "Hey, ibechane, please give me the record of the patient named" and then walk away, I will have no idea what the heck you are asking me.

Does that make sense? This is currently what you are doing in your php code. What I want to know is how you are deciding which id to choose. Is it id=001? Is it id=fred? Is it id=asdijfa? You are asking mySQL to get you a record with id=$id, but what is $id??
Copy linkTweet thisAlerts:
@CA-TaylorauthorAug 22.2008 — i know your asking me to Identify "id" but i dont know hwo to fully do that and make it work with my coding.
Copy linkTweet thisAlerts:
@ibechaneAug 22.2008 — Explain in words what you want the code to do and then we can give you ideas and tips on how to accomplish it.

As of right now, there's no quick fix to make your code work because there are logical steps missing. There's no way to give you an answer because the answer depends on what you want it to do.
×

Success!

Help @CA-Taylor spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...