futumuch
-
Posts
5 -
Joined
-
Last visited
Posts posted by futumuch
-
-
I think i am connecting ok, i also get this on my screen just before the error message.
first link = aaacnew link = aaacsuccess! were in!
This is from my echo statements. I declared the $dbc variable as global in the main body.
If you need any other info let me know. Many thanks.
-
Hi all,
i am trying to insert some data into a table via a php function as below
function save_link($new_link)
{
echo 'new link = '.$new_link; #just to make sure the code gets to here
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
else
{
echo 'success! were in!';
}
$query = "INSERT INTO college_values
(link_code, year_2011, year_2012, year_2013, year_2014)
VALUES
('AAAB',0,0,0,0)";
$retval = mysql_query($query, $dbc);
if(! $retval )
{
die('Could not enter data: ' . mysql_error());
}
return $result;
}
but i get the following message -
Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in....
I have tried many different combinations of $query but the one above does work if I paste it into the query section of PHPMyAdmin.I can substitute the query for a SELECT and it works fine. I just cant see why the INSERT doest work.Many thanks.
-
Thank you Antonio,
it works now!
Dave
-
hi,
I am try to learn PHP and MySQL with the help of Larry's excellent book. Most of the time, I find the book easy to follow and I can find the answer I need, however I have now hit a wall!
I want to count the amount of rows in a table that meet a certain criteria and then use this number in a PHP while loop.
My query is -
$SQL_count = SELECT COUNT(*) FROM college_notes WHERE link_code = 'CHES'
and I used this
$result_count = mysqli_query($dbc, $SQL_count);
My problem is that the variable $result_count doesnt seem to be usable. If I use echo to dump it on the screen, i get this -
Catchable fatal error: Object of class mysqli_result could not be converted to string in/home/www
I have also tried using AS to get an alias and $result_count['alais'] but got a message stating that the variable wasnt an array.
Thanks in advance for any help!
Dave
Can'T Insert Via Php
in PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide (4th Edition)
Posted
Thanks guys for your help, in trying to solve a problem with my syntax, I copied and pasted some code from a website that had mysql_query instead of mysqli_query. While i solved the original problem, I couldnt see the problem in the pasted code. A valuable lesson learned!
Many thanks.