943,853 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 627
  • PHP RSS
Sep 21st, 2008
0

@ crazy problems in sending and getting data to/from database

Expand Post »
PHP Syntax (Toggle Plain Text)
  1. ... mysql_select_db(".... database name....", $con);
  2. $sql="UPDATE INTO Picks (Day, Month, Number, Competition, Sport, Country, .....
  3.  

Working:

PHP Syntax (Toggle Plain Text)
  1. ... mysql_select_db(".... database name....", $con);
  2. $sql="INSERT INTO Picks (Day, Month, Number, Competition, Sport, Country, .....
  3.  

----------------

2. I can't make work the output of the database data, anything I try I got this message when trying to view my page:

"Parse error: syntax error, unexpected T_STRING, expecting ']' in /home/... my username..../public_html/test/view1.php on line 83"

Now this is a total nonsense, because like you can see below, line 83 is in an area which is totally identical with the same areas (lines) from the previous output zones (these are the output form of 5 sports-picks, everything is totally identical in the 5 areas, just the names of the "rows" are different as you can see...).

And if the code is validated in those 2 lines what in the world is with this line?
I tried to make some crazy changes, but nothing works, and anyways everything looks 1000% correct!
I have no data what could break the PHP code, any other character in the database which is not a letter are the " : ", "+ " or " - " characters.

<?php
$con = mysql_connect("localhost","...my username...","my pasword");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("...database name...., $con);

$result = mysql_query("SELECT * FROM Picks");

while($row = mysql_fetch_array($result))
  {

echo $row['Day'] . ", 
" . $row['Month'] . "
" . $row['Number']; echo "</h7></b>***</font></div><br>"; 

echo " <table align='center' border='1' bordercolor='#c0c0c0' cellpadding='0' cellspacing='0' width='528' bgcolor='#ffffff'><tr><td>
<table align='center' border='0' cellpadding='0' cellspacing='0' width='96%' bgcolor='#ffffff'>
<tr><td><div class='descr'><p align='center'><br><h8>"; 

echo $row['Competition'] . "  " . $row['Sport'] . " " . $row['Country'] . " " . $row['Time']; echo "</h8><br><h7>";
echo $row['Team1'] . " " .  $row['vs'] . " " .  $row['Team2']; echo "<br>";
echo $row['Type']; echo "</h7>&nbsp;<b>"; echo $row['Pick'] . " " . $row['Spread'] . " " . $row['Odds'] . " " . $row['Units']; 
echo "</b></font><br><br>";

echo "<h8>"; 
echo $row['Competition1'] . "  " . $row['Sport1'] . " " . $row['Country1'] . " " . $row['Time1']; echo "</h8><br><h7>";
echo $row['Team3'] . " " .  $row['vs1'] . " " .  $row['Team4']; echo "<br>";
echo $row['Type1']; echo "</h7>&nbsp;<b>"; echo $row['Pick1'] . " " . $row['Spread1'] . " " . $row['Odds1'] . " " . $row['Units1']; 
echo "</b></font><br><br>";

echo "<h8>"; 
echo $row['Competition2'] . "  " . $row['Sport2'] . " " . $row['Country2'] . " " . $row['Time2]; echo "</h8><br><h7>";
echo $row['Team5'] . " " .  $row['vs2'] . " " .  $row['Team6']; echo "<br>";
echo $row['Type2']; echo "</h7>&nbsp;<b>"; echo $row['Pick2'] . " " . $row['Spread2'] . " " . $row['Odds2'] . " " . $row['Units2']; 
echo "</b></font><br><br>";

echo "<h8>"; 
echo $row['Competition3'] . "  " . $row['Sport3'] . " " . $row['Country3'] . " " . $row['Time3]; echo "</h8><br><h7>";
echo $row['Team7'] . " " .  $row['vs3'] . " " .  $row['Team8']; echo "<br>";
echo $row['Type3']; echo "</h7>&nbsp;<b>"; echo $row['Pick3'] . " " . $row['Spread3'] . " " . $row['Odds3'] . " " . $row['Units3']; 
echo "</b></font><br><br>";

echo "<h8>";
echo $row['Competition4'] . "  " . $row['Sport4'] . " " . $row['Country4'] . " " . $row['Time4']; echo "</h8><br><h7>";
echo $row['Team9'] . " " .  $row['vs4'] . " " .  $row['Team10']; echo "<br>";
echo $row['Type4']; echo "</h7>&nbsp;<b>"; echo $row['Pick4'] . " " . $row['Spread4'] . " " . $row['Odds4'] . " " . $row['Units4']; 
echo "</b></font><br><br>";

}
  mysql_close($con);
?>

Line 84 is in red bold, and the other 2 identical lines are in green bold.
I'm totally out of ideas how to solve these 2 problems....
Last edited by cscgal; Sep 22nd, 2008 at 12:54 pm. Reason: Fixed code tags
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
MadMaxy is offline Offline
2 posts
since Aug 2008
Sep 21st, 2008
0

Re: @ crazy problems in sending and getting data to/from database

1. Lookup the update statement on the internet, the syntax for it is not correct, you can't simply replace INSERT with UPDATE, you need to completely re-write it, basics below:
php Syntax (Toggle Plain Text)
  1. mysql_query("UPDATE table_name SET row_name = value, rowname = value WHERE row_name = 'value'");

2. Are there any unescaped quotes within the values in the database as these may through such errors
For example, if you had 'value' in Team5 row in the database, it would make the code echo $row['Team5'] ..... into echo $row[''value'']...... which results in value being seen as code.
If you have any ' or " in the values in the db, you can escape them by changing them to \' or \"
Last edited by Will Gresham; Sep 21st, 2008 at 8:03 pm.
Reputation Points: 96
Solved Threads: 124
Master Poster
Will Gresham is offline Offline
728 posts
since May 2008
Sep 21st, 2008
0

Re: @ crazy problems in sending and getting data to/from database

Click to Expand / Collapse  Quote originally posted by xan ...
1. Lookup the update statement on the internet, the syntax for it is not correct, you can't simply replace INSERT with UPDATE, you need to completely re-write it, basics below:
php Syntax (Toggle Plain Text)
  1. mysql_query("UPDATE table_name SET row_name = value, rowname = value WHERE row_name = 'value'");

2. Are there any unescaped quotes within the values in the database as these may through such errors
For example, if you had 'value' in Team5 row in the database, it would make the code echo $row['Team5'] ..... into echo $row[''value'']...... which results in value being seen as code.
If you have any ' or " in the values in the db, you can escape them by changing them to \' or \"
Thanks for the info on the use of "UPDATE". I'm new to PHP, I was thinking that we need only to change"INSERT".

As about question 2, that's seems more problematic... No, I don't have any quotes in the database.
Last edited by MadMaxy; Sep 21st, 2008 at 8:11 pm.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
MadMaxy is offline Offline
2 posts
since Aug 2008
Sep 21st, 2008
0

Re: @ crazy problems in sending and getting data to/from database

look at the code below where you highlighted line 83, you have
php Syntax (Toggle Plain Text)
  1. echo $row['Competition2'] . " " . $row['Sport2'] . " " . $row['Country2'] . " " . $row['Time2]; echo "</h8><br><h7>";
  2.  
you are missing a ' from $row['Time2] this is also missing in the ones following this as well.
Reputation Points: 96
Solved Threads: 124
Master Poster
Will Gresham is offline Offline
728 posts
since May 2008
Sep 22nd, 2008
1

Re: @ crazy problems in sending and getting data to/from database

I think you forgot to insert single qoute for variables time2 and time3 you try to execute after removing this errors.
Reputation Points: 16
Solved Threads: 2
Light Poster
srilakshmitr7 is offline Offline
32 posts
since Aug 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: fwrite and fclose Error
Next Thread in PHP Forum Timeline: string manipulation





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC