 |
Account Login
|
 |
 |
Latest Articles
|
 |
 |
IRC Channel
|
 |
 |
Associates
|
 |
 |
Associates
|
 |
|
 |
|
 |
|
 |
10-17-2008, 05:30 PM
|
#21 (permalink)
|
|
Super Moderator
Join Date: Sep 2007
Location: Near you.
Posts: 791
Thanks: 241
|
This is how i am doing it but i get
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\wamp\www\t\index.php on line 22
Warning: Invalid argument supplied for foreach() in C:\wamp\www\t\index.php on line 23
PHP Code:
<?php error_reporting(E_ALL ^ E_NOTICE); include "config.php";
if(isset($_POST['submit'])) {
$url=$_POST['url']; if(strlen($url)<1) { print "You did not enter a URL."; } else { $bringdb = "SELECT * FROM upload"; $results = mysql_fetch_array($bringdb); foreach($results as $result) { if($result == $url) { die ('no!'); } } } if (preg_match('~^http://(?:[a-z]{2,3}\.)?youtube\.com/watch\?v=.+$~i', $url)) { $sql="INSERT INTO `upload` (`link`) VALUES('$url')"; mysql_query($sql) or die(mysql_error()); print "Link added!"; } else { print "Link is invalid"; } }
else { print "<form action='index.php' method='post'>"; print "URL(include http://):<br>"; print "<input type='text' name='url' size='20'><br>"; print "<input type='submit' name='submit' value='submit'></form>"; } ?>
|
|
|
|
10-17-2008, 06:31 PM
|
#22 (permalink)
|
|
The Addict
Join Date: Aug 2008
Posts: 336
Thanks: 8
|
mysql_fetch_array() needs a query handle as a parameter not a string. something like
$bringdb = mysql_query("SELECT * FROM upload");
while($result = mysql_fetch_assoc($bringdb)){
if($result['url'] == $url)
die ('no!');
}
Last edited by tony : 10-17-2008 at 06:34 PM.
Reason: submitted before making changes
|
|
|
|
|
The Following User Says Thank You to tony For This Useful Post:
|
|
10-17-2008, 07:14 PM
|
#23 (permalink)
|
|
Super Moderator
Join Date: Sep 2007
Location: Near you.
Posts: 791
Thanks: 241
|
ty you tony, but that got errors to..
|
|
|
|
10-17-2008, 08:51 PM
|
#24 (permalink)
|
|
The Addict
Join Date: Aug 2008
Posts: 336
Thanks: 8
|
I forgot to test my script. I tested now and yeah I get an error with the mysql_fetch_array() and mysql_fetch_assoc() not getting a MySQL handle. So I guess the problem is with mysql_query(), I can't seem to find it though. not much help here.
|
|
|
|
10-17-2008, 10:46 PM
|
#25 (permalink)
|
|
Super Moderator
Join Date: Sep 2007
Location: Near you.
Posts: 791
Thanks: 241
|
i am getting t_else but cant find :S
|
|
|
|
10-17-2008, 10:48 PM
|
#26 (permalink)
|
|
La Vida es Sueño
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
|
This is how to from inside SQLYog. Simply right click on the desire table, and select "Manage Indexes".

__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
|
|
|
|
The Following User Says Thank You to Wildhoney For This Useful Post:
|
|
10-17-2008, 11:32 PM
|
#27 (permalink)
|
|
Super Moderator
Join Date: Sep 2007
Location: Near you.
Posts: 791
Thanks: 241
|
i get this
Parse error: syntax error, unexpected T_ELSE in C:\wamp\www\t\index.php on line 39
and when i fix the bracket for the if thing it gives me same error just on line 63 :S
PHP Code:
<?php error_reporting(E_ALL ^ E_NOTICE); include "config.php";
if(isset($_POST['submit'])) {
$url=$_POST['url']; if(strlen($url)<1) { print "You did not enter a URL."; }
}
else
{
$videoid = 'ML5T1Lm7oO8'; $query = mysql_query("SELECT `id` FROM `upload` WHERE `id` = '{$videoid}' LIMIT 1") OR die(mysql_error());
if (mysql_fetch_array($query)) { print "error"; }
}
else
{
if (preg_match('~^http://(?:[a-z]{2,3}\.)?youtube\.com/watch\?v=.+$~i', $url)) { $sql = "INSERT INTO `upload` (`link`) VALUES('$url')"; mysql_query($sql) or die(mysql_error()); print "Link added!"; }
else { print "Link is invalid"; }
} else
{ print "<form action='index.php' method='post'>"; print "URL(include http://):<br>"; print "<input type='text' name='url' size='20'><br>"; print "<input type='submit' name='submit' value='submit'></form>"; }
include "watch.php";
?>
Why t_else error?
PS: thank you wildhoney i will look into that..
PS2: ID is primary in my db should it be the link ? or ?..
|
|
|
|
10-17-2008, 11:36 PM
|
#28 (permalink)
|
|
La Vida es Sueño
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
|
You should use an editor that points syntax errors out for, such as Zend Studio. By placing all that code into Zend Studio, I can immediately see you have 2 else statements in 1 if statement. Like this:
php Code:
if (true) { } else { } else { }
And that's not allowed.
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
|
|
|
|
The Following User Says Thank You to Wildhoney For This Useful Post:
|
|
10-17-2008, 11:42 PM
|
#29 (permalink)
|
|
Super Moderator
Join Date: Sep 2007
Location: Near you.
Posts: 791
Thanks: 241
|
i use komodo, and it tells u but i deleted and tried and etc.. it wont release the error :P
damn errors :(
This is how i feel right now :P
-.(Fatal error: Maximum brain power is exceeded in C:\brain\).-
-----
|
|
|
|
10-18-2008, 12:19 AM
|
#30 (permalink)
|
|
Super Moderator
Join Date: Sep 2007
Location: Near you.
Posts: 791
Thanks: 241
|
PHP Code:
<?php
error_reporting(E_ALL ^ E_NOTICE);
include "config.php";
if(isset($_POST['submit']))
{
$url = $_POST['url'];
if(strlen($url)<1)
{
print "You did not enter a URL.";
}
else
{
if(preg_match('~^http://[a-z]{2,3}\.youtube\.com/\?v=[\w-]+(?:&feature=related)?$~i', $url, $id))
{
echo $id[1]; // This is the ID.
$sql ="INSERT into upload (link) values('$id')";
mysql_query($url) or die(mysql_error());
print "Link added!";
}
else
{
print "Link is invalid or the link is already in are system!";
}
}
}
else
{
print "<form action='index.php' method='post'>";
print "URL(include http://):<br>";
print "<input type='text' name='url' size='20'><br>";
print "<input type='submit' name='submit' value='submit'></form>";
}
include "watch.php";
?>
|
|
|
|
10-18-2008, 03:05 PM
|
#31 (permalink)
|
|
The Prestige
Join Date: Oct 2007
Location: Manchester, UK
Posts: 854
Thanks: 32
|
Quote:
|
Only if the link column has a unique index on it.
|
Yea sorry I had forgotten that.
Anyway you can quickly add a unique to a column with a simple SQL statement:
sql Code:
ALTER TABLE `upload` ADD UNIQUE (`link`)
Your script works now?
__________________
mysql> SELECT * FROM `users` WHERE `users`.`clue` > 0;
Empty set (0.00 sec)
|
|
|
|
10-18-2008, 03:36 PM
|
#32 (permalink)
|
|
Super Moderator
Join Date: Sep 2007
Location: Near you.
Posts: 791
Thanks: 241
|
i am not going with that just yet.
this is how the script is looking right now.
it wont take in i think it's something with the preg_match maybe
the two vars, don't know,
any ideas would be great.
Thank you!
PHP Code:
<?php
error_reporting(E_ALL ^ E_NOTICE);
include "config.php";
if(isset($_POST['submit'])) {
$url = $_POST['url'];
if(strlen($url)<1) {
print "You did not enter a URL.";
}
else
{
if(preg_match('~^http://(?:[a-z]{2,3}\.)?youtube\.com/\?v=([\w-]+)~i', $url, $id)) {
echo $id[1]; // This is the ID.
$sql ="INSERT into upload (link) values(". (int) $id[1].")";
mysql_query($sql) or die(mysql_error());
print "Link added!";
}
else
{
print "Link is invalid or the link is already in are system!";
}
}
}
else
{
print "<form action='index.php' method='post'>";
print "URL(include http://):<br>";
print "<input type='text' name='url' size='20'><br>";
print "<input type='submit' name='submit' value='submit'></form>";
}
include "watch.php";
?>
|
|
|
|
10-18-2008, 03:36 PM
|
#33 (permalink)
|
|
The Prestige
Join Date: Oct 2007
Location: Manchester, UK
Posts: 854
Thanks: 32
|
Method of preventing duplicates using IGNORE:
IGNORE will basically stop MySQL returning the error on duplicate entries, therefore you can separate general SQL errors (i.e. syntax errors etc) from duplicate entry errors.
PHP Code:
$sql = 'INSERT IGNORE INTO `upload` (`link`) VALUES (' . $id . ')';
mysql_query($sql) or die(mysql_error());
if(!mysql_affected_rows()) { echo 'Link already exists'; } else { echo 'Your link was added to the database'; }
You need a UNIQUE on the `link` column.
__________________
mysql> SELECT * FROM `users` WHERE `users`.`clue` > 0;
Empty set (0.00 sec)
|
|
|
|
|
The Following User Says Thank You to sketchMedia For This Useful Post:
|
|
10-18-2008, 04:51 PM
|
#34 (permalink)
|
|
Super Moderator
Join Date: Sep 2007
Location: Near you.
Posts: 791
Thanks: 241
|
Thank you in advance!
I tried that,
sketchMedia what you posted and made the link spot in db unique but when i try to submit something it only prints out echo 'Your link was added to the database';
but noting happens :/
This is how it looks now ?
any ideas,
and thank you everyone for the help!
i learn so much from you, and i will never forget the
kindness that i get from talkphp, specially, wildhoney
and sketchMedia, and tony! great people!
and of course my friend tanax! :D
PHP Code:
<?php error_reporting(E_ALL ^ E_NOTICE); include "config.php"; if(isset($_POST['submit'])) { $url = $_POST['url']; if(strlen($url)<1) { print "You did not enter a URL."; } else { if(preg_match('~^http://(?:[a-z]{2,3}\.)?youtube\.com/\?v=([\w-]+)~i', $url)) { $sql = "INSERT IGNORE INTO `upload` (`link`) VALUES('$url')";
mysql_query($sql) or die(mysql_error());
if(!mysql_affected_rows()) {
echo 'Link already exists'; } } else { echo 'Your link was added to the database'; } } }
else { print "<form action='index.php' method='post'>"; print "URL(include http://):<br>"; print "<input type='text' name='url' size='20'><br>"; print "<input type='submit' name='submit' value='submit'></form>"; }
?>
Thank you in advance!
btw, willdhoney i bought ZendStudio ;)
but is there anyways to make the debug function to check for
common newbie mistakes ;)
|
|
|
|
10-18-2008, 04:59 PM
|
#35 (permalink)
|
|
The Prestige
Join Date: Oct 2007
Location: Manchester, UK
Posts: 854
Thanks: 32
|
PHP Code:
error_reporting(E_ALL ^ E_NOTICE); include "config.php"; if(isset($_POST['submit'])) {
$url = $_POST['url'];
if(strlen($url)<1) { print "You did not enter a URL."; } else { if(preg_match('~^http://(?:[a-z]{2,3}\.)?youtube\.com/\?v=([\w-]+)~i', $url)) {
$sql = "INSERT IGNORE INTO `upload` (`link`) VALUES('$url')";
mysql_query($sql) or die(mysql_error());
if(!mysql_affected_rows()) { echo 'Link already exists'; } else { echo 'Your link was added to the database'; } } else { echo 'Your link was invalid or malformed'; } } } else { print "<form action='index.php' method='post'>"; print "URL(include http://):<br>"; print "<input type='text' name='url' size='20'><br>"; print "<input type='submit' name='submit' value='submit'></form>"; }
Try that and see what it outputs.
__________________
mysql> SELECT * FROM `users` WHERE `users`.`clue` > 0;
Empty set (0.00 sec)
|
|
|
|
|
The Following User Says Thank You to sketchMedia For This Useful Post:
|
|
10-18-2008, 05:35 PM
|
#36 (permalink)
|
|
Super Moderator
Join Date: Sep 2007
Location: Near you.
Posts: 791
Thanks: 241
|
Your link was invalid or malformed
|
|
|
|
10-18-2008, 05:37 PM
|
#37 (permalink)
|
|
The Prestige
Join Date: Oct 2007
Location: Manchester, UK
Posts: 854
Thanks: 32
|
k, now we know that its failing at the regex because preg_match is returing 0.
What its the string you are using to test?
__________________
mysql> SELECT * FROM `users` WHERE `users`.`clue` > 0;
Empty set (0.00 sec)
|
|
|
|
10-18-2008, 05:40 PM
|
#38 (permalink)
|
|
Super Moderator
Join Date: Sep 2007
Location: Near you.
Posts: 791
Thanks: 241
|
|
|
|
|
10-18-2008, 06:24 PM
|
#39 (permalink)
|
|
Super Moderator
Join Date: Sep 2007
Location: Near you.
Posts: 791
Thanks: 241
|
was it, that you meant or?
|
|
|
|
10-18-2008, 06:35 PM
|
#40 (permalink)
|
|
The Prestige
Join Date: Oct 2007
Location: Manchester, UK
Posts: 854
Thanks: 32
|
Quote:
Originally Posted by codefreek
was it, that you meant or?
|
Yea, the regex isn't matching it.
__________________
mysql> SELECT * FROM `users` WHERE `users`.`clue` > 0;
Empty set (0.00 sec)
|
|
|
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|